可以用动态TSQL查询吗?
我有很长的选择查询,我需要根据一些参数进行过滤,我试图通过使用部分动态 TSQL 来避免在单个存储过程中使用不同的存储过程或 if 语句...
我将避免长选择,例如 @c 和 @d 是过滤器参数
select a
from b
where c=@c
or d=@d
,只能同时过滤一个过滤器,但也可以禁用两个过滤器。每个 0 意味着参数被禁用,因此我可以使用其中的 where 语句创建 nvarchar...
我如何集成到此处的动态查询中,以便可以将“where”添加到正常查询中。我无法将所有查询添加为大 nvarchar,因为其中有太多需要更改的内容(即何时、子查询、联接)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样:
当您不使用过滤器时,将参数设置为
NULL
并且条件应该被短路。How about something like:
When you're not using the filter, set the parameter to
NULL
and the condition should be short-circuited.有点晚了但是
A little late but