繁体   English   中英

SQL IF语句转换为文本

[英]SQL IF statement convert to text

我有一条SQL语句,如下所示:

SELECT 
 b.pricedate AS [Price Quote Date]
,b.jobid AS [Job No.]
,a.priceid AS [Price Quote Id]
,b.headline AS [Price Quote Title]
,a.activitytext AS [Activity Text]
,a.tnum AS [No. of Hours]
,a.tsale AS [Hourly Rate]
,b.stat AS [PQ Status]
FROM JobPriceactivity a
                        INNER JOIN JobPrice AS b ON a.priceid = b.priceid
WHERE a.Activitytext LIKE '%influencer%' and jobid >= '700000'and jobid <= '709999'
ORDER BY b.jobid

这给了我以下示例:

在此处输入图片说明

是否可以在我的原始select语句中使用IF语句来查看PQ状态并将代码更改为更有意义的文本?

例如:如果IF PQ状态= 50,然后转换为“已批准”

任何建议或帮助,不胜感激。

您可以使用CASE表达式:

CASE WHEN b.stat = 50 THEN 'Approved' ELSE b.stat END AS [PQ Status]

case when

b.pricedate AS [Price Quote Date]
,b.jobid AS [Job No.]
,a.priceid AS [Price Quote Id]
,b.headline AS [Price Quote Title]
,a.activitytext AS [Activity Text]
,a.tnum AS [No. of Hours]
,a.tsale AS [Hourly Rate]
,case when b.stat=50 then 'approved' 
else 'not approved'  end AS [PQ Status]
FROM JobPriceactivity a
                        INNER JOIN JobPrice AS b ON a.priceid = b.priceid
WHERE a.Activitytext LIKE '%influencer%' and jobid >= '700000'and jobid <= '709999'
ORDER BY b.jobid

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM