本文介绍了查询错误.破碎的 !的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨.
为什么此查询不起作用?
Hi .
why this query does not work ?
SELECT TOP 50 * FROM
SELECT fIDUser1 AS fIDUser FROM UserFeature.Relationship WHERE fIDUser2=5 AND fIDStatus=141
UNION ALL
SELECT fIDUser2 AS fIDUser FROM UserFeature.Relationship WHERE fIDUser1=5 AND fIDStatus=141)
执行时显示错误:
消息156,第15级,状态1,第2行
关键字"FROM"附近的语法不正确.
消息156,第15级,状态1,第4行
关键字"SELECT"附近的语法不正确.
消息102,第15级,状态1,第4行
'')''附近的语法不正确.
when execute show error :
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword ''FROM''.
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword ''SELECT''.
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near '')''.
推荐答案
SELECT TOP 50 * FROM
(SELECT fIDUser1 AS fIDUser FROM UserFeature.Relationship WHERE fIDUser2=5 AND fIDStatus=141
UNION ALL
SELECT fIDUser2 AS fIDUser FROM UserFeature.Relationship WHERE fIDUser1=5 AND fIDStatus=141)
应该可以做到的:
1-第一个FROM
必须移到括号之外
2- UNION ALL SELECT SELECT
不正确
should do the trick :
1- The first FROM
must be moved outside the parenthesis
2- UNION ALL SELECT SELECT
was incorrect
SELECT TOP 50 * FROM (
SELECT fIDUser1 AS fIDUser FROM UserFeature.Relationship WHERE fIDUser2=5 AND fIDStatus=141
UNION ALL
SELECT fIDUser2 AS fIDUser FROM UserFeature.Relationship WHERE fIDUser1=5 AND fIDStatus=141
) as Users
这篇关于查询错误.破碎的 !的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!