希望在此脚本中使用case语句。第一次尝试它并且不确定它有什么问题。
SELECT DocumentDest.Keycode AS [Acct #],
Customer.Name,
DocumentDest.Emails,
Case
Customer.Freq AS [Weekly or Monthly]
When 'W' then 'Weekly'
When 'M' then 'Monthly'
Else 'None'
End
FROM DocumentDest
INNER JOIN Customer ON DocumentDest.Keycode = Customer.KeyCode
WHERE (DocumentDest.Type = 'cus') AND (DocumentDest.[Document] IN ('stmt', 'wstmt'))
答案 0 :(得分:0)
别名Weekly or Monthly
不得出现在CASE
语句的中间:这是一个SQL-Server版本,因此对于MySql表单别名。
SELECT
DocumentDest.Keycode AS [Acct #],
Customer.Name,
DocumentDest.Emails,
Case Customer.Freq When 'W' then 'Weekly' When 'M' then 'Monthly' Else 'None'
End AS [Weekly or Monthly]
FROM DocumentDest INNER JOIN Customer
ON DocumentDest.Keycode = Customer.KeyCode
WHERE DocumentDest.Type = 'cus'
AND DocumentDest[Document IN ('stmt', 'wstmt')