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 |
|
ukgi
Starting Member
3 Posts |
Posted - 2005-03-10 : 05:20:23
|
| Hi there, I need to create a trigger that will help me achieve autonumbering. The table i want the trigger to be created is called FINTRADE. There is a Field in that table (Zordernumber) that holds integer values. What i need to do is before inserting a row in the table to be able to check for the max value of the spoken Field and add 1 to its value so that the record that is inserted gets the next value.Please help me out on this as my knowledge in Transact SQL is not that good. |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-03-10 : 05:29:42
|
why don't you use identity column for this? it has that functionality already buièt in and you don't have to worry about multi row inserts.Go with the flow & have fun! Else fight the flow |
 |
|
|
ukgi
Starting Member
3 Posts |
Posted - 2005-03-10 : 05:33:58
|
| I'll try that out now thx for the tip |
 |
|
|
ukgi
Starting Member
3 Posts |
Posted - 2005-03-10 : 06:35:39
|
| Nop... I need to be able to do it with a trigger cause I already have an Identity column in that table. Besides that i wanna be able to get the max(value) of the field while considering another field's (DSRID) value (i wanna be able to add a where clause to get that value). That means that there might be identical values in that field for different values of the DSRID field.Any thoughts on building the trigger? |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-03-10 : 06:47:07
|
decalre @value int select @value = max(ColumnName) + 1 from MyTablewhere ....select @valuehowever you will have problems with this on multi-row inserts.Go with the flow & have fun! Else fight the flow |
 |
|
|
|
|
|