[英]PowerBuilder SQL on SQL Server 2008 - CASE statement with computed column in SELECT
I am attempting to create computed columns with a CASE statement using an example from Microsoft . 我正在尝试使用Microsoft的示例使用CASE语句创建计算列。
I will appreciate any help or pointers!! 我将不胜感激任何帮助或指示!
The relevant example code is: 相关的示例代码为:
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
And I 'think' I am doing the same thing below: 我“想”我在下面做同样的事情:
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')))
but the server tells me that I have an error as: 但是服务器告诉我,我的错误如下:
SQLSTATE = 37000
SQLSTATE = 37000
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'origin'.[Microsoft] [ODBC SQL Server驱动程序] [SQL Server]'origin'附近的语法不正确。
I have tried it with the comma after 'End' and then I get an error stating: 我已经在'End'之后用逗号尝试过,然后收到一条错误消息:
SQLSTATE = 37000
SQLSTATE = 37000
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'end'.[Microsoft] [ODBC SQL Server驱动程序] [SQL Server]'end'附近的语法不正确。
Thanks to comments from Lamak, I was able to resolve the issue by adding a missing parenthesis and commas after the 'end' statement. 感谢Lamak的评论,我能够通过在'end'语句之后添加缺少的括号和逗号来解决此问题。 Thanks Lamak!!
谢谢Lamak!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.