当前位置:编程学习 > C#/ASP.NET >>

求一sql语句

有一变量strname=session("xm")
有一表为tabA,其中一字段为lct
求tabA中字段lct包含strname的记录
strsql="?"
请问?号处该如何写 --------------------编程问答-------------------- select lct from tabA where lct like '%strname%' --------------------编程问答-------------------- string.Format("select * from tabA where lct='{0}',strname); --------------------编程问答-------------------- sql="Select * From tabA Where lct='"+ strname +"'" --------------------编程问答--------------------
string strsql= string.format(" select * from tabA where lct like '%{0}%'",strname);
--------------------编程问答-------------------- string strsql = "Select * From tabA Where CHARINDEX('"+ strname +"',lct)>0"; --------------------编程问答--------------------
引用 1 楼 lin11211408 的回复:
select lct from tabA where lct like '%strname%'

不对,直接把strname当字符串了 --------------------编程问答--------------------

string.format(" select * from tabA where CHARINDEX('{0}',lct)>0",strname);
string.format(" select * from tabA where lct like '%{0}%'",strname);
--------------------编程问答-------------------- string strname=session("xm").toString();
string strsql= string.format(" select * from tabA where lct like '%{0}%'",strname); --------------------编程问答-------------------- string.format("select * from tabA where ict like '%{0}%'",strname); --------------------编程问答--------------------
引用 4 楼 yhj464079080 的回复:
SQL code?1string strsql= string.format(" select * from tabA where lct like '%{0}%'",strname);

+1 --------------------编程问答-------------------- string sql=" select * from tabA where CHARINDEX('"+strname+"',lct)>0";
charindex的用法请参考http://www.cnblogs.com/lkvm114/archive/2011/03/06/1972261.html --------------------编程问答-------------------- 如上 回帖 --------------------编程问答--------------------
引用 8 楼 yhj464079080 的回复:
string strname=session("xm").toString();
string strsql= string.format(" select * from tabA where lct like '%{0}%'",strname);

+1
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,