[英]Incorrect syntax near '' SQL Server
i'm a beginner with sqlserver, and i'm trying to compile a function on db, but a got some issues我是 sqlserver 的初学者,我正在尝试在 db 上编译一个函数,但是遇到了一些问题
i'm guessing that is missing parentheses in importants components.我猜想在重要组件中缺少括号。
SELECT
somefields
FROM
table S,
table2 SF
WHERE
mycondition = myothercondition
AND mycondition = myothercondition
AND S.mycondition = myothercondition
AND SF.mycondition = myothercondition
-- BELOW IS MY PROBLEM
AND
(
(NOT EXISTS
(
SELECT
1
FROM
table3 s
WHERE
mycondition = 'S'
)
AND
(
SELECT
CONVERT(DATETIME, CONVERT(VARCHAR, DATEADD(mm, myfield, myfield),103), 103) <= CONVERT(DATETIME, CONVERT(VARCHAR, myfield, 103), 103) -- INCORRECT SYNTAX NEAR '<'
FROM
mytable A
WHERE
mycondition = '607'
)
)
OR
(
SELECT
1
)
) -- Incorrect syntax near ')'
AND CONVERT(DATETIME, CONVERT(VARCHAR, DATEADD(mm, MYFIELD, MYFIELD), 103), 103) <= CONVERT(DATETIME, CONVERT(VARCHAR, MYFIELD, 103), 103)
AND mycondition =
(
SELECT
MAX(MYFIELD)
FROM
MYFIELD WITH(NOLOCK)
WHERE
Mycondition = mycondition
AND mycondition = mycondition
AND mycondition = '086'
)
AND (NOT EXISTS -- Incorrect syntax near the keyword 'AND'
(
SELECT
1
FROM
table SF3 WITH(NOLOCK)
WHERE
SF3.myfield= SF.myfield
AND SF3.myfield= SF.myfield
AND SF3.myfield IN
(
'086',
'086'
)
AND SF3.myfield= 'S'
)
I imagine that is happening some problems with the '(', but i really don't know, what's the problem. sorry but i need hide the field names and tables.我想'('会发生一些问题,但我真的不知道,有什么问题。抱歉,我需要隐藏字段名称和表格。
The first problem:第一个问题:
(SELECT CONVERT(DATETIME, CONVERT(VARCHAR, DATEADD(mm, myfield, myfield),103), 103)
<= CONVERT(DATETIME, CONVERT(VARCHAR, myfield, 103), 103)
FROM
mytable A
WHERE
mycondition = '607')
If you remove the SELECT
it removes the error line under the <=
.如果删除
SELECT
它会删除<=
下的错误行。 Without further detail of the tables/columns, I can't go too deep into an answer.如果没有表/列的更多细节,我无法深入回答。 But you might try something similar to this (hypothetical example):
但是您可以尝试类似的操作(假设示例):
(CONVERT(DATETIME, CONVERT(VARCHAR, DATEADD(mm, mytable.myfield, othertable.myfield),103), 103)
<= CONVERT(DATETIME, CONVERT(VARCHAR, mytable.myfield, 103), 103)
)
and
mycondition = '607'
You cannot SELECT
a boolean value:您不能
SELECT
布尔值:
SELECT
CONVERT(DATETIME, CONVERT(VARCHAR, DATEADD(mm, myfield, myfield),103), 103)
<=
CONVERT(DATETIME, CONVERT(VARCHAR, myfield, 103), 103)
-- INCORRECT SYNTAX NEAR '<'
replace this expression with a CASE
evaluating to 1 or 0:用计算结果为 1 或 0 的
CASE
替换此表达式:
(SELECT CASE WHEN
CONVERT(DATETIME, CONVERT(VARCHAR, DATEADD(mm, myfield, myfield),103), 103)
<=
CONVERT(DATETIME, CONVERT(VARCHAR, myfield, 103), 103)
THEN 1 ELSE 0 END
...
) = 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.