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
 Auto incrementing field till a certain condition

Author  Topic 

conqueror123
Starting Member

2 Posts

Posted - 2012-10-13 : 10:02:07
Hi guys,
I have the following table
SNo Value Item
where Sno is a column which exists in another table also. Right now , what I need is a self incrementing field which will go on incrementing if the value of sno is a constant and then get back to 0 and start incrementing again once the value of sno changes. IS there any way to do this?

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-10-13 : 13:33:49
I am only vaguely following what you are asking. Are you describing what should happen when you insert anew row into the table? Can you post some sample data and show examples of the conditions under which a value should be icremented and conditions under which it should be 0?
Go to Top of Page

conqueror123
Starting Member

2 Posts

Posted - 2012-10-13 : 20:56:42
Lets say I have four columns:
SNO|Value |Item | AUtoIncrementingField
1___344_____a________0
1___345_____b________1
1___346_____c________2
2___568_____d________0

So when I say insert into this table , and the value of SNO becomes two the value of the auto incrementing field should go back to 0. Is there any inbuilt way of doing this, or writing some code on top of mysql to achieve this. If not what other option do I have to uniquely identify each value/item belonging to a certain value of sno?
Go to Top of Page
   

- Advertisement -