消息102,级别15,状态1,行1'''附近的语法不正确

saj*_*jad 6 sql sql-server-2008

我试图从临时表中查询,我不断收到此消息:

Msg 102, Level 15, State 1, Line 1 Incorrect syntax near ' '.
Run Code Online (Sandbox Code Playgroud)

有人能告诉我问题是什么吗?它是否应该转换?

查询是

select compid,2, convert(datetime, '01/01/' + CONVERT(char(4),cal_yr) ,101) ,0,  Update_dt, th1, th2, th3_pc , Update_id, Update_dt,1
from  #tmp_CTF** 
Run Code Online (Sandbox Code Playgroud)

KM.*_*KM. 6

对于OP的命令:

select compid,2, convert(datetime, '01/01/' + CONVERT(char(4),cal_yr) ,101) ,0,  Update_dt, th1, th2, th3_pc , Update_id, Update_dt,1
from  #tmp_CTF** 
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '*'.
Run Code Online (Sandbox Code Playgroud)

当调试这样的东西时,将长行分开,这样你就会得到更好的行号:

select compid
,2
, convert(datetime
, '01/01/' 
+ CONVERT(char(4)
,cal_yr) 
,101) 
,0
,  Update_dt
, th1
, th2
, th3_pc 
, Update_id
, Update_dt
,1
from  #tmp_CTF** 
Run Code Online (Sandbox Code Playgroud)

现在的结果是:

Msg 102, Level 15, State 1, Line 16
Incorrect syntax near '*'.
Run Code Online (Sandbox Code Playgroud)

这可能只是来自OP,没有将整个命令放入问题中,或者使用[]大括号来表示表名称:

from [#tmp_CTF**]
Run Code Online (Sandbox Code Playgroud)

如果这是表名。