如何用case语句为sql编写串联?

时间:2015-11-05 10:25:49

标签: sql

我的查询如下:

SET @MainSQL='SELECT   UserProfile.empfullname, UserProfile.UnitId, OrgaMaster.Extension as OrgaID,Payroll.UserID,Payroll.Year,Payroll.PayrollID,<br>
(Case Payroll.Month when '1' then '''January'''<br>
 when '2' then '''February'''<br>
 when '3' then '''March''' <br>
 when '4' then '''April''' <br>
 when '5' then '''May''' <br>
 when '6' then '''June''' <br>
 when '7' then '''July''' <br>
 when '8' then '''August'''<br>
 when '9' then '''September''' <br>
 when '10' then '''October''' <br>
 when '11' then '''November''' <br>
 when '12' then '''December''' <br>
 end)as Month
                FROM     Payroll INNER JOIN
               UserProfile ON Payroll.UserID = UserProfile.UserID inner JOIN
               OrgaMaster on UserProfile.UnitId = OrgaMaster.OrgaID Where OrgaMaster.Level=1'


结果仍然显示不正确。如何在sql

中写入case的连接

1 个答案:

答案 0 :(得分:0)

CONCAT()函数 - (LINK) - 可以为您解析CASE语句并连接结果。

您应该能够将CASE语句放在CONCAT()函数中。

我没有看到您甚至试图使用CONCAT()