• QuoteName\生成Sql语句



      if exists(select name from tempdb.dbo.sysobjects where id = object_id(N'tempdb.dbo.#tempWorkDate') and type='u') 
           drop table #tempWorkDate CREATE TABLE [#tempWorkDate] ( [WorkDate] [varchar] (100) NULL,[SeqNo] [int] NULL )
    Insert Into #tempWorkDate ([WorkDate],[SeqNo] ) values ( '2011-07-04','1' )
    Insert Into #tempWorkDate ([WorkDate],[SeqNo] ) values ( '2011-07-05','2' )
    Insert Into #tempWorkDate ([WorkDate],[SeqNo] ) values ( '2011-07-06','3' )
    Insert Into #tempWorkDate ([WorkDate],[SeqNo] ) values ( '2011-07-07','4' )
    Insert Into #tempWorkDate ([WorkDate],[SeqNo] ) values ( '2011-07-08','5' )
    Insert Into #tempWorkDate ([WorkDate],[SeqNo] ) values ( '2011-07-09','6' )
    Insert Into #tempWorkDate ([WorkDate],[SeqNo] ) values ( '2011-07-10','7' )
    Insert Into #tempWorkDate ([WorkDate],[SeqNo] ) values ( '2011-07-11','8' )
    Insert Into #tempWorkDate ([WorkDate],[SeqNo] ) values ( '2011-07-12','9' )

    declare @test varchar(8000)
    set @test=''
    select @test=@test+','+char(10)+'(case when workdate='+QUOTENAME(WorkDate,N'''')+' then TravelTypeID else null end )A'+cast(SeqNo as varchar)
    from   #tempWorkDate
    order by WorkDate
    print @test

  • 相关阅读:
    set, unordered_set模板类
    C/C++ Bug记录
    win10远程连接
    C/C++缓冲区刷新问题
    hihocoder1711 评论框排版[并查集+set]
    makefile
    Virtual Table
    粤语
    xilinx SDK开发 GPIO使用API总结
    基于zynq 7020的串口UART中断实验
  • 原文地址:https://www.cnblogs.com/chirs888888/p/2111368.html
Copyright © 2020-2023  润新知