views:

342

answers:

1

I am trying to query from a temp table and i keep getting this message:

Msg 102, Level 15, State 1, Line 1 Incorrect syntax near ' '.

Can somebody tell me what the problem is? Is it due to convert?

The query is

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** 
A: 

For the OP's command:

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** 

I get this error:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '*'.

when debugging something like this split the long line up so you'll get a better row number:

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** 

this now results in:

Msg 102, Level 15, State 1, Line 16
Incorrect syntax near '*'.

which is probably just from the OP not putting the entire command in the question, or use [ ] braces to signify the table name:

from [#tmp_CTF**]

if that is the table name.

KM
i did as u told. the error is near ,0 (just after ,101)..is there something wrong with use of convert?
sajad
this works fine for me: `select 0,2, convert(datetime, '01/01/' + CONVERT(char(4),2010) ,101) ,0, 11, 22, 33, 44 , 55, 66,1`, I had to replace the column names with values because I don't know what your table looks like. show your entire query.
KM