当前位置: 代码迷 >> Sql Server >> 关于CharIndex函数在拼接SQL时的写法,
  详细解决方案

关于CharIndex函数在拼接SQL时的写法,

热度:12   发布时间:2016-04-27 11:39:38.0
关于CharIndex函数在拼接SQL时的写法,在线等~~~
SQL code
Declare @Sql varchar(1000)Declare @TestTxt varchar(100)='张三'Set @Sql = 'SELECT TOP 10  * FROM T_productDetails   WHERE  '+CharIndex(@TestTxt,'Title')+'>0'Exec (@Sql)


上面这段代码报转换错误,原因就是不太清楚CharIndex这个函数在拼接的时候应该怎么写?
求高手解答,在线等~~

------解决方案--------------------
SQL code
Declare @Sql varchar(1000)Declare @TestTxt varchar(100)set @TestTxt=N'张三'Set @Sql = 'SELECT TOP 10  * FROM T_productDetails  WHERE  CharIndex([email protected]+''',[Title])>0'Exec (@Sql)