How to get multiple result set on conditional basis and also retrieve the column name
I want to get the name as Col1, Col2, Col3, Col4 etc. as per the result set.
I have a store procedure which looks like
CREATE SP Test
(@Id INT)
AS
BEGIN
IF(@Id ==1)
BEGIN
SELECT Col1, Col2 from Table1
END
IF(@Id ==2)
BEGIN
SELECT Col1, Col2, Col3 from Table1
END
ELSE
BEGIN
SELECT Col4, Col3 from Table1
END
END