1.有用户mary,其不具备dbo所创建的数据库tu的权限,现要求用mary查询tu中tu_1的数据,如何写查询语句
2.原有数据
ID   NAME
1 AA
2 BB
3 CC
4 DD
5 EE
6 FF
7 GG
8 HH
进行一次update之后再次select
得到
ID   NAME
1 BB
2 BB
3 DD
4 DD
5 FF
6 FF
7 HH
8 HH
这个update怎么写,不能使用case和when

解决方案 »

  1.   

    update tb set name = (select top 1 name from tb where id > t.id order by id) from tb t where id % 2 = 1
      

  2.   

    create table tb(ID int,NAME varchar(10))
    insert into tb values(1 ,'AA')
    insert into tb values(2 ,'BB')
    insert into tb values(3 ,'CC')
    insert into tb values(4 ,'DD')
    insert into tb values(5 ,'EE')
    insert into tb values(6 ,'FF')
    insert into tb values(7 ,'GG')
    insert into tb values(8 ,'HH')
    goupdate tb set name = (select top 1 name from tb where id > t.id order by id) from tb t where id % 2 = 1select * from tb
    /*
    ID          NAME       
    ----------- ---------- 
    1           BB
    2           BB
    3           DD
    4           DD
    5           FF
    6           FF
    7           HH
    8           HH(所影响的行数为 8 行)
    */drop table tb
      

  3.   

    dawugui那句话太神奇了。什么语法?我太菜看不懂
      

  4.   

    2.
    update tb set name =char(64+id) +char(64+id):)
      

  5.   

    8楼有误,这个吧
    update tb set name =char(65+id%2+id/2+(id-1)/2) +char(65+id%2+id/2+(id-1)/2)
      

  6.   


    --1.用Execute AS语句
      先 EXECUTE AS USER = 'username' -- username是一个有权限的用户
      再 SELECT * FROM tu_1--2.
      update tb set name = (select name from tb a where tb.id = a.id - 1) where id % 2 = 1
    记得结贴哦