March 14, 2011 at 12:56 pm
I would like to do a bulk insert using the following query but on the last field have a date and time stamp. What is the proper syntax?
sql:
bulk insert Location
from '\\test\sql\loc-test4sql1.txt'
with
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '',
Keepnulls
)
GO
Text file:
136,135,,PLT3,3-010407,3-010-07,,,[system date and time]
137,136,,PLT1,1-0010319,1-001-03-19,,,[system date and time]
March 14, 2011 at 1:49 pm
getdate() is the system datetime. You could make getdate() be the default value in your SQL table so that it gets populated when rows are inserted.
March 14, 2011 at 4:42 pm
Agreed except that you'll also need either a BCP format file or an insertable view to skip the defaulted column.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 15, 2011 at 12:46 pm
The problem is that this is not an empty table. I am trying to append the records into it. The date field is mandatory. I have tried your method..getdate() and no luck. Sorry, I'm new to sql.
thanks
March 15, 2011 at 3:46 pm
Then my recommendation is to add GETDATE() to the table column as a default and create an "INSERT" view so you can skip it using BULK INSERT and have it still satisfy the "mandatory column" problem.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 15, 2011 at 3:49 pm
Jeff Moden (3/15/2011)
Then my recommendation is to add GETDATE() to the table column as a default and create an "INSERT" view so you can skip it using BULK INSERT and have it still satisfy the "mandatory column" problem.
Scratch that. I never BULK INSERT directly into the final table. I ALWAYS BULK INSERT into a staging table to do data validations, etc. If you do that first, then when you insert into the final table from the staging table, you can just add GETDATE() as the value to insert.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply