我在sql server 2014中写了一个命令,命令失败,出现以下错误
select * from View_FirstReport
where Date Between '1392/03/20' and '1392/03/19', Insure_ID = '0', User_ID='2'
Group by insure_id, InsureTitle, status
Msg 102,Level 15,State 1,Line 2','。附近的语法不正确。
答案 0 :(得分:1)
您应该将查询的各个部分与AND
和OR
结合起来。
select
*
from
View_FirstReport
where
Date Between '1392/03/20' and '1392/03/19'
AND Insure_ID = '0'
AND User_ID='2'
Group by insure_id, InsureTitle, status
答案 1 :(得分:1)
将,
条款中的WHERE
替换为AND
:
SELECT *
FROM View_FirstReport
WHERE
Date Between '1392/03/20' AND '1392/03/19'
AND Insure_ID = '0' AND User_ID='2'
GROUB BY insure_id,InsureTitle,status
WHERE
的详细语法定义例如可以找到here。
答案 2 :(得分:0)
使用AND
代替,
:
SELECT * FROM View_FirstReport
WHERE Date BETWEEN '1392/03/20' and '1392/03/19'
AND Insure_ID = 0
AND User_ID = 2
GROUP BY insure_id, InsureTitle, status
此外,整数列不需要单引号来包围值。
答案 3 :(得分:0)
您必须更换your,with和operator,并仅选择您在组中包含的记录或MIN,MAX,AVG等其他列。
SELECT insure_id, InsureTitle, status FROM View_FirstReport
WHERE Date BETWEEN '1392/03/20' and '1392/03/19'
AND Insure_ID = 0
AND User_ID = 2
GROUP BY insure_id, InsureTitle, status
答案 4 :(得分:0)
试试这个,
SELECT insure_id
,InsureTitle
,[STATUS]
FROM View_FirstReport
WHERE [DATE] BETWEEN '13920320'
AND '13920319'
AND Insure_ID = '0'
AND [User_ID] = '2'
GROUP BY insure_id
,InsureTitle
,[STATUS]
这几乎与SandeepKumar的答案相似。