字符串连接为sql2008中的where条件 [英] string concatenate as where condition in sql2008

查看:81
本文介绍了字符串连接为sql2008中的where条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想知道是否可以在sql2008中将字符串连接为where条件,该字符串还必须包括我正在使用where条件的表的列名.我尝试过,但是没有成功!有谁知道我该怎么做?

感谢和问候

Hi All,

I wanted to know if it is possible to concatenate a string as where condition in sql2008, the string must also include the column name(s) of the table for which i am using the where condition. I tried it but was not successful! does anyone know how i can do this?

Thanks and Regards

推荐答案

您可以这样使用吗? -
Can you use like this? -
declare @Fil as varchar(100) set @Fil= '* from yourTable' ;
declare @qury as varchar(200) set @qury='Select ' + @Fil
exec (@qury)


有些不错有关动态where 条款的信息,请参见在静态SQL中实现动态WHERE条款 [
Some good info on dynamic where clauses at Implementing Dynamic WHERE-Clause in Static SQL[^].


如果您提供包含查询的一段代码,将会很有帮助.
It would be helpful if you provide a piece of code containing the query.


这篇关于字符串连接为sql2008中的where条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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