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


Bikesh SrivastavaRank #108 · 20.3K reputationPosted Aug 2, 2016, 6:03 AM EDT
Anil Kumar MurmuRank #1,652 · 930 reputationPosted Aug 2, 2016, 6:11 AM EDT
Yes, Bikesh
Depending on input parameter, we will have separate result sets. If input parameter is 1 then columnsreturned would be col1 and col2
Vinay SinghRank #604 · 4K reputationPosted Aug 2, 2016, 9:11 AM EDT