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
 trigger for batchid

Author  Topic 

Anand.A
Posting Yak Master

109 Posts

Posted - 2012-02-21 : 03:10:47
hi

i want to write a trigger thats populate batch id for my table

if today is start loading ie, monday my batchid should be 1

so tomorrow my batchid should be 2, like this per day my batchid should be increament by 1.. how to write a trigger for this

anand

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-02-21 : 03:47:39
No need for trigger.
Just add a DEFAULT value for your BatchID column something like this
ALTER TABLE dbo.Table1 ALTER COLUMN BatchID DEFAULT DATEDIFF(DAY, '20120220', GETDATE())



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -