我在尝试使用sp_send_dbmail
参数调用@query
时执行查询时遇到问题。我的查询可以自行处理,但是一旦我在调用@query
时将其放在'sp_send_dbmail
参数中,它就会因语法错误错误而失败:
@query = 'SELECT DISTINCT "IINFO"."I_FIRST", "IINFO"."I_LASTNAME", "IINFO"."I_EMAIL", "STAY"."S_ADATE", "STAY"."S_GSTTYPE"
FROM "V1Data"."dbo"."STAY" "STAY"
INNER JOIN "V1Data"."dbo"."IINFO" "IINFO"
ON "STAY"."S_IRECID" = "IINFO"."I_RECID"
WHERE "STAY"."S_GSTTYPE"=''OWNER''
AND "STAY"."S_ADATE" >= DATEADD(day,-1,GETDATE())
AND "STAY"."S_ADATE" <= DATEADD(day,+7,GETDATE())
ORDER BY S_ADATE ASC',
我得到的错误:
Msg 22050,Level 16,State 1,Line 0
格式化查询时出错,可能是无效参数Msg 14661,Level 16,State 1,Procedure sp_send_dbmail,Line 517
查询执行失败:消息102,级别15,状态1,服务器TCCHECKDB,第1行 'I_FIRST'附近的语法不正确。