Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select into syntax error ?

Author  Topic 

java148
Yak Posting Veteran

63 Posts

Posted - 2011-11-09 : 16:50:17
where is the syntax error ? it said "Incorrect syntax near 'col1'", but my table has this column.

Please help.

Thanks



use test1
GO
create table #tmpTbl(col1 varchar(max), col2 varchar(max))
GO

insert into #tmpTbl values('ddd', 'fff');
GO

select col1, col2, GETDATE()
into test1..ddd(col1, col2, insertTime)
from #tmpTbl

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-11-09 : 17:03:07
quote:
Originally posted by java148

where is the syntax error ? it said "Incorrect syntax near 'col1'", but my table has this column.

Please help.

Thanks



use test1
GO
create table #tmpTbl(col1 varchar(max), col2 varchar(max))
GO

insert into #tmpTbl values('ddd', 'fff');
GO

select col1, col2, GETDATE() as insertTime
into test1..ddd(col1, col2, insertTime)
from #tmpTbl


Go to Top of Page

java148
Yak Posting Veteran

63 Posts

Posted - 2011-11-09 : 17:06:48
thanks
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-11-09 : 17:09:35
Welcome
Go to Top of Page

java148
Yak Posting Veteran

63 Posts

Posted - 2011-11-09 : 21:25:37
this is my final version. Thanks


create table #tmpTbl(col1 varchar(max), col2 varchar(max))
GO

insert into #tmpTbl values('ddd', 'fff');

create table tmpTbl(col1 varchar(max), col2 varchar(max), insertTime datetime)

insert into tmpTbl(col1 , col2 , insertTime)
select col1 as col1, col2 as col2, GETDATE() as insertTime from #tmpTbl

select * from tmpTbl

drop table tmpTbl;
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-10 : 01:22:46
quote:
Originally posted by java148

this is my final version. Thanks


create table #tmpTbl(col1 varchar(max), col2 varchar(max))
GO

insert into #tmpTbl values('ddd', 'fff');

create table tmpTbl(col1 varchar(max), col2 varchar(max), insertTime datetime)

insert into tmpTbl(col1 , col2 , insertTime)
select col1 as col1, col2 as col2, GETDATE() as insertTime from #tmpTbl

select * from tmpTbl

drop table tmpTbl;



i see lots of varchar(max) fields here
unless its abosolutely necessary dont use varchar(max) for storing the string data. always consider what will be maximum amount of data that you would require storing before determining data type. This will make sure you dont use up unnecessary resources and also retrieval operations will be much more optimised

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -