我正在尝试使用an example from Microsoft创建带有CASE语句的计算列。
我将不胜感激任何帮助或指示!!
相关的示例代码是:
SELECT
ProductNumber, Category =
CASE ProductLine
WHEN 'R' THEN 'Road'
WHEN 'M' THEN 'Mountain'
WHEN 'T' THEN 'Touring'
WHEN 'S' THEN 'Other sale items'
ELSE 'Not for sale'
END,
Name
FROM
Production.Product
ORDER BY
ProductNumber;
GO
我认为'我在下面做同样的事情:
SELECT
Convert ( char(10),"") No,
Convert ( char(15),"") vendor,
car_type.car_type_desc,
origin_st =
case voucher.pu_is_airport
when 'F' then Convert( char(50), rtrim(ltrim(operator_archive.pu_st_no)) + " " + rtrim(ltrim(operator_archive.pu_st_name)) )
else Convert( char(50), "")
end
origin =
case voucher.pu_is_airport
when 'F' then Convert( char(50), rtrim(ltrim(operator_archive.pu_city)) + ", " + rtrim(ltrim(operator_archive.pu_county)))
else Convert( char(50), rtrim(ltrim(operator_archive.pu_county))
end
voucher.confirmation_no,
voucher.pu_is_airport,
operator_archive.dest_st_name
FROM
voucher,
car_type,
operator_archive
WHERE
(voucher.car_type = car_type.car_type_id) and
(operator_archive.confirmation_no = voucher.confirmation_no) and
((dbo.voucher.pu_date_time >= :start_date) AND
(dbo.voucher.pu_date_time <= :end_date) AND
(dbo.voucher.account_no = :account) AND
(dbo.voucher.status_flag not in ('9','X','C','F')) AND
(dbo.voucher.payment_type in ('1','2','3','4','5','6','7','8')))
但是服务器告诉我有一个错误:
SQLSTATE = 37000
[Microsoft] [ODBC SQL Server驱动程序] [SQL Server]&origin;&#39;附近的语法不正确。
我在“结束”之后用逗号尝试过它。然后我收到一个错误说明:
SQLSTATE = 37000
[Microsoft] [ODBC SQL Server驱动程序] [SQL Server]&#39; end&#39;附近的语法不正确。
答案 0 :(得分:1)
感谢Lamak的评论,我能够通过在&#39; end&#39;之后添加一个缺少的括号和逗号来解决这个问题。声明。谢谢喇嘛!