SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 increment values on day basis on column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

paritosh
Starting Member

India
38 Posts

Posted - 08/28/2012 :  03:59:19  Show Profile  Reply with Quote
hi all,

i want to generate id column values on the basis of every day.

suppose table name like test and
table have column id then value of id column are

today is 28-aug-2012 then values are increased after each insert like this
:-
table name test

column name ID
and values are

id
2012082800001
2012082800002
....
....
2012082800002
and next day it will be on new insert :-
2012082900001
2012082900002
.......
........
and next day it will be on new insert :-
2012083000001
2012083000002
.......
........

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 08/28/2012 :  04:23:24  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
Split into two columns - you can use a calculated column to combine them if you wish.
Then yoou can use a trigger to get the max value for a day and add one t oit.

You could do that with the current data but it's poor design.
coalesce((select max(id)%100000 from tbl where id > convert(varchar(8),getdate(),112)*100000)+1,convert(varchar(8),getdate(),112)*100000+1)


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

paritosh
Starting Member

India
38 Posts

Posted - 08/28/2012 :  11:33:25  Show Profile  Reply with Quote
HI ALL

PLEASE PROVIDE SOME EASY WAY IF YOU KNOW

THANKS
Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 08/28/2012 :  12:14:51  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
Easier than I posted?
Don't think it's possible to get much easier given the structure.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000