首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Execute@ with another @

Execute@ with another @
EN

Stack Overflow用户
提问于 2013-02-05 23:18:08
回答 1查看 75关注 0票数 0

我怎么才能让它工作呢?我希望能够根据变量是0还是1来更新@result 0,然后将其放入另一个集合@,然后调用@result。##tempz表确实存在。但是,当我运行此命令时,它只给出:(125行受影响)

代码语言:javascript
复制
DECLARE @result nvarchar(max),@result0 nvarchar(max)
SET @showstore = 1
SET @showcashier = 0
SET @showregister = 0
SET @showdate = 0  

set @result = 'select '+@result0+' from ##tempz'
set @result0 = 'Amex,[Gift Card],Debit,[Off Line C.Card],[Str Cr],[House Acct],Cash,Rebate,[C.Card],VIP,Discover,[Check],MasterCard,[Visa/MC]'

If @showstore = 1
    begin
        set @result0 = 'StoreID,' + @result0
    end
If @showcashier = 1
    begin
        set @result0 = 'Cashier,' + @result0
    end
If @showregister = 1
    begin
        set @result0 = 'Register,' + @result0
    end
If @showdate = 1
    begin
        set @result0 = 'Date,' + @result0
    end
execute(@result)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-05 23:22:21

在所有IF..ELSE之后,您应该在最后一行设置@result的值

代码语言:javascript
复制
DECLARE @result nvarchar(max),@result0 nvarchar(max)
SET @showstore = 1
SET @showcashier = 0
SET @showregister = 0
SET @showdate = 0  

set @result0 = 'Amex,[Gift Card],Debit,[Off Line C.Card],[Str Cr],[House Acct],Cash,Rebate,[C.Card],VIP,Discover,[Check],MasterCard,[Visa/MC]'

If @showstore = 1
    begin
        set @result0 = 'StoreID,' + @result0
    end
If @showcashier = 1
    begin
        set @result0 = 'Cashier,' + @result0
    end
If @showregister = 1
    begin
        set @result0 = 'Register,' + @result0
    end
If @showdate = 1
    begin
        set @result0 = 'Date,' + @result0
    end
set @result = 'select '+@result0+' from ##tempz'
execute(@result)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14710801

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档