您的位置:程序门 -> .net技术 -> c#



c#中sql语句小错误,急...


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


c#中sql语句小错误,急...[已结贴,结贴人:luoyong269]
发表于:2007-04-02 10:43:52 楼主
sql语句如下:
int   i=3;
select   top   (i-1)*3   name   from   xxx;

出现错误,在sql查询分析器里这样写也不行,
select   top   (3-1)*3   name   from   bikes

请问我该怎么写?
发表于:2007-04-02 10:48:581楼 得分:4
top   后不能写表达式或变量。拼好sql语句再执行。
发表于:2007-04-02 10:50:222楼 得分:11
只能用常量
strsql= "select   top   "+   (i-1)*3   + "   name   from   xxx "
发表于:2007-04-02 10:51:073楼 得分:1
select   top   (i-1)*3,name   from   xxx;
发表于:2007-04-02 10:55:534楼 得分:2
int   i=3;

string   str   =   ((i-1)*3).tostring();

"select   top   "   +   str   +   "   name   from   xxx ";
发表于:2007-04-02 10:59:365楼 得分:2
先组成字符串联 然后EXECspl那条字符串
发表于:2007-04-02 11:00:346楼 得分:0
多谢楼上的高手们,结贴
发表于:2007-04-02 11:02:077楼 得分:0
declare   @i   int
set   @i   =   3
declare   @s   nvarchar(1000)
set   @s   =   'select   top   '   +   str((@i-1)*3)   +   '   name   from   xxx '
EXEC   (@s)


快速检索

最新资讯