帮我完成这个TSQL案例查询

时间:2011-03-24 23:03:10

标签: tsql

我不得不在工作时使用石刀和熊皮,不幸的是LINQ对我来说太好了。这里有什么问题:

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'

我收到此错误:

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'FROM'.

3 个答案:

答案 0 :(得分:3)

CASEEND

附近缺少FROM

答案 1 :(得分:1)

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'

我在FROM

之前的cat_name之后添加了END

答案 2 :(得分:1)

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'

缺少CASE的END