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.
| Author |
Topic |
|
davidb7
Starting Member
1 Post |
Posted - 2008-08-28 : 18:38:19
|
Hi, I am wondering if someone could help me out with a issue I am facing. I need a sequence number to be reset to 1 after July 1 of any year and in any month at any day for a report. For example the sequence number is 777 and the next time the report is ran on Jan 1 the sequence number is then reset to 1. How can I do this? I want to do this in a stored procedure. I could do GETDATE() < July 1 and this would work for the last half of a year but not the first half. Any help is appreciated. It's a great day to program :) |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2008-08-29 : 02:07:40
|
Please explain more..Where is this sequence number coming from?You can probably use a variation ofRow_Number() over (Partition by Year(dateadd(month,7,mydate) order by mydate ) This would start your sequence at 1 each july 1st (assuming there is a record on July 1st). If this is not what you want please explain more. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-29 : 02:15:20
|
quote: Originally posted by davidb7 Hi, I am wondering if someone could help me out with a issue I am facing. I need a sequence number to be reset to 1 after July 1 of any year and in any month at any day for a report. For example the sequence number is 777 and the next time the report is ran on Jan 1 the sequence number is then reset to 1. How can I do this? I want to do this in a stored procedure. I could do GETDATE() < July 1 and this would work for the last half of a year but not the first half. Any help is appreciated. It's a great day to program :)
You could simply create an identity field for your table and then use if check in your stored procedure to reset the identity if it satisfies your condition. use DBC CHECKIDENT(yourtable) to reset identity value. |
 |
|
|
|
|
|