problem with year changing

Posted by Amar888 under C# on 12/31/2010 | Points: 10 | Views : 1373 | Status : [Member] | Replies : 2
hi,

i have one column in database i,e job number it is not auto increment not primary key , i am retrieving max value adding + 1.

it starts 001 if the year changes again it should be start with 001 only . if any one knows tell me code.




Responses

Posted by: T.saravanan on: 12/31/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Amar888,

Try the following query....

Select isnull(max(nJobNo),0)+1 from table 


Note : Here isnull use is if first time we can insert into table means it return null using isnull its return '0'.

Cheers :)

Thanks,
T.Saravanan

Amar888, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Suresh.mekkattil on: 1/9/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

You can group by the result by the year, this will let you get a year specific details.

Then Create a temp table, and insert the values(the group by result of the first query). While inserting you can check the previous row with the current row, if the date are different in the previous and the current, then start the number By "001";



-----
Suresh M

Amar888, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response