gpt4 book ai didi

sql - 如何根据 SQL Server 2008 中的特定参数返回所需的手动值

转载 作者:行者123 更新时间:2023-12-01 13:43:43 25 4
gpt4 key购买 nike

我在 SQL Server 2008 中有一个像这样的 SQL 查询:

declare @Waited6_8 varchar(max) = 'true'
declare @Waited8_12 varchar(max) = 'false'
declare @Waited12_18 varchar(max) = 'true'

Select
choice = case when @Waited6_8 = 'true' then '6-8'
when @Waited8_12 = 'true' then '8-12'
when @Waited12_18 = 'true' then '12-18'
end

在这里,我得到 6-8 作为结果。

我希望看到的是:6-8、12-18 作为一个字符串(而不是不同的行)

我怎样才能得到这个?如果您能提供帮助,我将不胜感激。

谢谢!

最佳答案

declare @Waited6_8 varchar(max) = 'true'
declare @Waited8_12 varchar(max) = 'false'
declare @Waited12_18 varchar(max) = 'true'


Select choice = isnull(case when @Waited6_8 = 'true' then '6-8' end + ', ','') +
isnull(case when @Waited8_12 = 'true' then '8-12' end + ', ','') +
isnull(case when @Waited12_18 = 'true' then '12-18' end,'')

关于sql - 如何根据 SQL Server 2008 中的特定参数返回所需的手动值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37575848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com