Adding Dyanmic In() Conditions in Sql Server -


facing problem generating sql server query in following query dynamic conditions added check whether value null or not

select  *     tblemployees    employeename =  case                              when @employeename not null                                  @employeename                              else employeename                          end  

but need add in () conditions , parameter in in () null or blank ,if parameter /string passed in condition blank donot want add condition in query.

so how can achieve this.a helping hand useful me.

thanks , regards, d.mahesh

depending on value of parameter (blank of not), can create sql string accordingly.

declare @sqlcommand varchar(1000) if(isnull(@yourparameter,'')='')     @sqlcommand = 'your query goes here' else     @sqlcommand = 'your query goes here' 

and then, run using dynamic query execution

exec (@sqlcommand) 

if not dynamic query then,

select .... .... case when isnull(@yourparameter,'')='' '' else employeename end in (isnull(@yourparameter,'')) 

see if works...


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -