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 |
|
collie
Constraint Violating Yak Guru
400 Posts |
Posted - 2005-03-28 : 08:23:40
|
| Hi,I have a table in sql with the following fields:Pid =identity primary keySid =intRowNumber =intI need that for each sid the rownumber will be unique but that the rownumber can repeat itself for a different sid. Also, I want to automatically enter the rownumber (the first entry must start at the value 1 ,second entry will be 2 etc.)I have a asp.net application that inserts the values into the database but I don't want the users to enter the rownumber-I want it done automatically.I need the table to look similar to this:sid | RowNumber12 | 112 | 212 | 314 | 114 | 2etcHow can I do this. |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-03-28 : 08:56:11
|
| Why do you feel you need to store this RowNumber value in your database? What are you using it for?- Jeff |
 |
|
|
DustinMichaels
Constraint Violating Yak Guru
464 Posts |
Posted - 2005-03-28 : 09:31:03
|
| INSERT INTO <Your Table> (Sid, RowNumber)SELECT @Sid, COALESCE((SELECT MAX(RowNumber) + 1 FROM <Your Table> WHERE Sid = @Sid), 1)Dustin Michaels |
 |
|
|
collie
Constraint Violating Yak Guru
400 Posts |
Posted - 2005-03-30 : 02:46:58
|
Thanks that is exactly what I was looking for. |
 |
|
|
|
|
|