I want To make a sql Query Dynamic mean On if else Condition i want to Add different columns into the select statement like that
If(QuestionID==1)
Select some thing
Else IF(questionID=2)
Select some thing differnt
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Danish HabibPosted Dec 27, 2014, 1:17 AM
Joginder BangerPosted Dec 27, 2014, 1:12 AM
Make the store Procedure like this type.
create procedure Procedure_name
(
@firstParameters varchar(max),
@secondParamerts varchar(max)
)
as
begin
if(@firstParameters=='condition one')
begin
--do stuff here
end
else
if(@secondparamerts=='condition two')
begin
--do stuff here
end
end
end
Khargesh RajputPosted Dec 27, 2014, 1:08 AM
Select * from table where QuestionID=1
Else IF(questionID=2)
Select * from table where QuestionID=2