Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have a huge csv file need upload to database. If we run a query, query will be
insert into test1..ddd(col1, col2, insertTime) values("col1","col2",GETDATE())
but my csv file only has two columns, col1, col2. then what about insertTime ? I can't modify table structure. Thanks
X002548
Not Just a Number
15586 Posts
Posted - 2011-11-09 : 16:09:48
Maybe you can post the DDL of the Table...howeverCan you creatye a staging tableCREATE Stage_Table(Col1 datatype, Col2 datatype)GODeclare @cnd varchar(8000)SELECT @cmd = 'dbname.dbo.bcp Stage_Table in D:\filepath\filename -c -t"," -Sservername -T'exec master..xp_cmdshell @cmdThen do analysis, clean up, whatever, the INSERT INTO From StageORYou can use a format file when you bcp into that table.Do you know if there are any contraints on your table?Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2011-11-10 : 01:08:47
quote:Originally posted by java148 I have a huge csv file need upload to database. If we run a query, query will be
insert into test1..ddd(col1, col2, insertTime) values("col1","col2",GETDATE())
but my csv file only has two columns, col1, col2. then what about insertTime ? I can't modify table structure. Thanks
is it one off activity? if yes, you can OPENROWSET for thatdatefield put a default constraint to point to GETDATE() and ignore it in insert/select list altogetherhttp://syntaxhelp.com/SQLServer/OPENROWSET/CSV------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
X002548
Not Just a Number
15586 Posts
Posted - 2011-11-10 : 09:39:41
quote:Originally posted by visakh16is it one off activity?