我对此有一个小想法,但我不知道如何在SQL Server(MSDN)中解释它。
IF ('DateReception' is not NULL) AND ('DateMovement' is NULL)
SET @Requete = DATEDIFF (dd, @EndDatereq, 'DateReception')
SET @Requete = 'SELECT A.[AutomatonStatus]
FROM dbo.Automatons A
WHERE ((A.AutomatonStatus = "SNI") OR (A.AutomatonStatus = "PAI") OR (A.AutomatonStatus = "INP") OR (A.AutomatonStatus = "INT"))'
之后我收到一条错误消息:
Msg 207,Niveau 16,État1,Ligne 3
Nom de colonne non valide:'SNI'。
答案 0 :(得分:1)
您正在展示的SQL在上下文中没有多大意义。
由于某种原因,服务器将常量SNI
解释为列名。
答案 1 :(得分:0)
将字符串常量括在双引号中,而不是双引号:
IF ('DateReception' is not NULL) AND ('DateMovement' is NULL)
SET @Requete = DATEDIFF (dd, @EndDatereq, 'DateReception')
SET @Requete = 'SELECT A.[AutomatonStatus]
FROM dbo.Automatons A
WHERE ((A.AutomatonStatus = ''SNI'') OR (A.AutomatonStatus = ''PAI'') OR (A.AutomatonStatus = ''INP'') OR (A.AutomatonStatus = ''INT''))'
双引号标记标识符(列名等),而不是字符串。