我有一个表 tb3,其中 id、name、sal 将使用语句显示,只有当标志为“Y”时SELECT,城市、描述字段才需要显示在同一语句中。SELECT我如何使用CASE语句来做到这一点?
      id    name    sal city    descrip flag
       7    john    80000.00    Canada  prog    y
       6    jone    90000.00    NY  test    y
       3    san 70000.00    NY        lead  y
       2    sam 70000.00    Cali    sub n
       1    sally   60000.00    Canada  archi   n
       4    carl    70000.00    SA  plain   n
我需要做这样的事情..我知道这是错误的,但是请看一下示例..
       declare @test varchar(1)
       select @test=flag from tb3
       select id,name,case @test
       when 'Y' then select city,descrip from tb3
       when 'n' then 'inactive'
       end as status from tb3