Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to get the system date automatically in the columns


How to get the system date automatically in the columns

Author
Message
arthi.anan
arthi.anan
Grasshopper
Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)

Group: General Forum Members
Points: 20 Visits: 55
Hi experts,

I have a table called branch with columns
branch_code
branch_name
branch_desc
modified_by
modified_date

Here i have data for the 1st three columns and the rest 2 fields 'modified_by' and 'modified_date' has to get values automatically from the system...
I did a bulk insert to get the data into those 3 columns but it is expecting 'modified_by' and 'modified_date' fields.
How do i give it separately? the values in those last 2 fields should be given as 'system' and GETDATE()

Please help me with ur scripts
Stewart "Arturius" Campbell
Stewart "Arturius" Campbell
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5767 Visits: 7128
Have you tried binding default constraints to the columns, e.g.
ALTER TABLE [dbo].[branch] ADD  CONSTRAINT [df_mod_by]  DEFAULT (suser_sname()) FOR [modified_by]
GO

ALTER TABLE [dbo].[branch] ADD CONSTRAINT [df_mod_date] DEFAULT (sysdatetime()) FOR [modified_date]
GO



____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
arthi.anan
arthi.anan
Grasshopper
Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)

Group: General Forum Members
Points: 20 Visits: 55
Yes I tried...but that is not working. I'm getting the same error

GMBAR,BARBIL,ODISHA REGION
GMBBS,BHUBANESWAR,ODISHA REGION
GMBEL,BELLARY,SOUTH REGION
GMBHU,BHUJ,GUJARAT
GMKND,KANDLA(SEZ),GUJARAT (SPECIAL ECONOMIC ZONE)
GMHYD,HYDERABAD,SOUTH REGION
GMKOD,KODURU,SOUTH REGION
GMKOL,KOLKATA,EAST REGION
GMMGG,MANDIGOBINDGARAH,NORTH REGION

This is my branch data which is a .csv file which i have to load it using bulkinsert.
The last 2 fields should be given as 'system' and GETDATE()
Stewart "Arturius" Campbell
Stewart "Arturius" Campbell
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5767 Visits: 7128
Have you considered using INSERT ... SELECT * FROM OPENROWSET(BULK instead of BULK INSERT?
you can specify the columns to be inserted to with this command.

e.g.
INSERT testAll.[dbo].[branch](branch_code, branch_name, branch_desc)
SELECT * FROM OPENROWSET(BULK 'C:\myBranches.dat', SINGLE_BLOB) a



____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
McSQL
McSQL
SSC-Enthusiastic
SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)SSC-Enthusiastic (162 reputation)

Group: General Forum Members
Points: 162 Visits: 299
Have you tried adding default values on the fields within the database?
You sometimes have to set the fields to "Allow NULLs" if the data isn't contained within the set you're trying to import.
But just set a string value of "system" against the user field and the getdate() variable against the date field, as defaults and they should populate automatically with the imported dataset.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search