怀疑Sql Server - 如何生成动态查询 [英] Doubt on Sql Server -How to generate Dynamic query

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

问题描述

我听说我们可以使用XML生成动态查询我们可以这样做,如果我们能做到这一点我们怎么做才能让我知道



谢谢你提前,

Vinay

I heard that we can generate a dyanamic query using XML can we do that if we can do that how can we do that plz let me know

Thanks in Advance,
Vinay

推荐答案

您可以尝试以下查询,其中包含表名和列名称Dynamaically



You can try the Following Query Which takes the Table name and Columns name Dynamaically

DECLARE @sqlCommand varchar(1000)
DECLARE @columnList varchar(75)
DECLARE @table varchar(75)
SET @columnList = 'ExceptionTime,ExceptionMessage'
SET @table = 'ExceptionLog'
SET @sqlCommand = 'SELECT ' + @columnList + ' FROM ' + @table
print(@sqlCommand)
EXEC (@sqlCommand)


您好,



查看以下链接...



执行Dyna SQL Server中的mic SQL命令 [ ^ ]

动态SQL(动态结构化查询语言) ) [ ^ ]



并签入Codeproject文章



问候,

GVPrabu
Hi,

Check the following links...

Execute Dynamic SQL commands in SQL Server[^]
dynamic SQL (Dynamic Structured Query Language)[^]

and check in "Codeproject" Articles

Regards,
GVPrabu


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

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