开发者

Help me finish this TSQL case query

开发者 https://www.devze.com 2023-02-19 09:09 出处:网络
I\'m forced to use stone knives and bear skins at work and unfortunately LINQ has been too good to me. What is wrong here:

I'm forced to use stone knives and bear skins at work and unfortunately LINQ has been too good to me. What is wrong here:

SELECT cat_id, cat_parent, CASE WHEN LEN(cat_name) > 36 THEN SUBSTRING(cat_name,0,36) + '...' ELSE cat_name FROM Categories WHERE cat_parent != 0 AND cat_dir = 'Manufacturing'

I get this error:

Msg 156, Level 开发者_如何学Python15, State 1, Line 1
Incorrect syntax near the keyword 'FROM'.


CASE missing END near FROM


SELECT cat_id, cat_parent, 
CASE WHEN LEN(cat_name) > 36 THEN SUBSTRING(cat_name,0,36) + '...' ELSE cat_name END FROM Categories WHERE cat_parent != 0 AND cat_dir = 'Manufacturing'

I added END after cat_name before FROM


SELECT cat_id, cat_parent, CASE WHEN LEN(cat_name) > 36 THEN SUBSTRING(cat_name,0,36) + '...' ELSE cat_name END AS cat_name FROM Categories WHERE cat_parent != 0 AND cat_dir = 'Manufacturing'

It is missing an END for the CASE

0

精彩评论

暂无评论...
验证码 换一张
取 消