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
 increment values on day basis on column

Author  Topic 

paritosh
Starting Member

42 Posts

Posted - 2012-08-28 : 03:59:19
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
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-08-28 : 04:23:24
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

42 Posts

Posted - 2012-08-28 : 11:33:25
HI ALL

PLEASE PROVIDE SOME EASY WAY IF YOU KNOW

THANKS
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-08-28 : 12:14:51
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
   

- Advertisement -