当前位置: 代码迷 >> Sql Server >> 高手快来,求一条sql.解决办法
  详细解决方案

高手快来,求一条sql.解决办法

热度:73   发布时间:2016-04-27 15:46:57.0
高手快来,求一条sql.
如果有一表A
Table   name:A
Column   :userID,countryCode,SMS

其中userID和countryCode为联合主键.现在这个表中有这样的数据:

userID         countryCode         SMS
[email protected]     HK                           259991
[email protected]     MY                           445588
[email protected]   MY                           445588
............

我想用一条sql语句search出来
[email protected]   and   countryCode=MY这条记录之后的所有记录出来

应该怎样写?

注:database为sql2000


------解决方案--------------------
select id=identity(int,1,1),* into # from A
select userID,countryCode,SMS from # where id> (select max(id) from # where userID= '[email protected] ' and countryCode= 'MY ')
------解决方案--------------------
select id=identity(int,1,1),* into tmp from exec(select sqlStatement from OtherTable)
但是这样的语法在sql2000中不允许.改怎么办?
--------------
--试试
exec( 'select id=identity(int,1,1),sqlStatement into tmp from OtherTable ')
  相关解决方案