Is it possible with dynamic TSQL query ?

Posted by eugeneK on Stack Overflow See other posts from Stack Overflow or by eugeneK
Published on 2010-06-03T09:11:25Z Indexed on 2010/06/03 9:14 UTC
Read the original article Hit count: 177

Filed under:
|
|

I have very long select query which i need to filter based on some params, i'm trying to avoid having different stored procedures or if statements inside of single stored procedure by using partly dynamic TSQL...

I will avoid long select just for example sake

select a
from b
where c=@c
or d=@d

@c and @d are filter params, only one can filter at the same time but also both filters could be disabled. 0 for each of these means param is disables so i can create nvarchar with where statement in it...

How do i integrate in here dynamic query so 'where' can be added to normal query. I cannot add all the query as big nvarchar because there is too many things in it which will require changes ( ie. when's, subqueries, joins)

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about sql-server