开发者

Is there an alternative to dynamic stored procedures?

开发者 https://www.devze.com 2023-03-16 04:06 出处:网络
I hate 开发者_Python百科buikding these for a variety of reasons; debugging, lack of execution plan, permissions issues, etc. Is there a viable alternative to building huge dynamic sql statements in a

I hate 开发者_Python百科buikding these for a variety of reasons; debugging, lack of execution plan, permissions issues, etc. Is there a viable alternative to building huge dynamic sql statements in a stored proc and then executing it?


I sometimes avoid dynamic SQL by deleting rows from a temp table that I don't want. But I'm not saying that this is best for performance - I work in a data warehouse more often than not where performance is second to other factors, like avoiding dynamic SQL.

Here is an example, for a report that calls for TOP x records, I choose the max, say 200, and simply delete the rest. (I.e., 200 is the maximum the report will ever need. I hope.) So there will be, if the parameter's name is @Range:

SELECT TOP 200 
...

DELETE FROM #MyTemp where Counter > @Range
0

精彩评论

暂无评论...
验证码 换一张
取 消