--如何把这句sql 改写为下面的那种方式?
update tb set cl=N'Sjöblom' where id=3
--改写为这种方式
declare @cl varchar(100)
set @cl='Sjöblom'
update tb set cl=@cl where id=3

解决方案 »

  1.   

    declare @cl nvarchar(100)
    set @cl=N'Sjöblom'
    update tb set cl=@cl where id=3
      

  2.   

    create table tb(id int,cl nvarchar(100))
    insert into tb select 3,null union all select 4,null
    go
    --如何把这句sql 改写为下面的那种方式?
    update tb set cl=N'Sjöblom' where id=3
    select * from tb
    /*
    id          cl
    ----------- ----------------------------------------------------------------------------------------------------
    3           Sjöblom
    4           NULL(2 行受影响)
    */
    --改写为这种方式
    declare @cl nvarchar(100)
    set @cl=N'Sjöblom'
    update tb set cl=@cl where id=4
    select * from tb
    /*
    id          cl
    ----------- ----------------------------------------------------------------------------------------------------
    3           Sjöblom
    4           Sjöblom(2 行受影响)
    */
    go
    drop table tb