如何创建动态Tsql查询 [英] how to create dynamic Tsql queries

查看:83
本文介绍了如何创建动态Tsql查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种在存储过程中动态创建Tsql查询的方法.
我知道有关通过varchar变量创建查询并使用
执行查询的信息 sp_executesql

执行
但是,如果查询变得复杂,似乎很难调试.我的建议是,如果可以的话,请尽量避免使用动态SQL.它说它们比非动态脚本要慢得多.


Is there a way to dynamically create Tsql query in stored procedure.
i know about creating a query ia a varchar variable and execute it using
sp_executesql
or
EXECUTE
but it seems to be hard to debug if query gets complicated

解决方案

You practically do the same way in stored procedures if you are to create dynamic TSQL scripts. My advice is, as much as possible, try to avoid dynamic SQL if you can do it without one. Its said they''re a lot slower than non-dynamic scripts.


这篇关于如何创建动态Tsql查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆