首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

大家看看这条SQL语句有什么不对,应该如何写

2012-08-10 
大家看看这条SQL语句有什么不对,应该怎么写PIDConn.Execute(select count(id) from test where id&Nu

大家看看这条SQL语句有什么不对,应该怎么写
PID=Conn.Execute("select count(id) from test where id<="&Num&" and id="&rs("id")&" and TID="&cccid&"")(0)
id为当前行id,TID为父ID,Num为在父ID下的总行数,rs("id")为当前id的值,比如9,默认排序升序
我要实现的功能是判断当前行在数据中的位置并返回结果
比如
test表
id name TID
3 A 147
4 B 147
1 D 147
2 E 147
7 Z 147
9 X 147
6 H 147
12 J 147
现在我要查出name="X"在第几行
也就是得出"6"

[解决办法]
就是查ID?
那不就是:

C# code
select id from test where name=@name
[解决办法]
没意义啊,位置的前提是排序,你要先排序才能确认位置!
如果要默认序列的位置,用sql简单点就是 select identity(int, 1, 1) sortNo, * into #t from tbname,select sortNo from #t where id name = 'X'
[解决办法]
探讨
没意义啊,位置的前提是排序,你要先排序才能确认位置!
如果要默认序列的位置,用sql简单点就是 select identity(int, 1, 1) sortNo, * into #t from tbname,select sortNo from #t where id name = 'X'

热点排行
Bad Request.