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 |
|
rjcurro
Starting Member
4 Posts |
Posted - 2009-07-06 : 17:53:21
|
| I've got a problem where I need to auto increment a field but it has to stay an nvarchar. The table is set up as such.My first field is an integer and starts at 1My second field is a nvarchar and needs to start at 1001My third field is an nvarchar and needs to start at 100001How do I write a sql statement that will do this?thanks for your help,Robert |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-06 : 18:17:50
|
do you mean auto increment the value by column or row ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-07-08 : 12:02:26
|
| http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-07-09 : 04:28:57
|
quote: Originally posted by rjcurro I've got a problem where I need to auto increment a field but it has to stay an nvarchar. The table is set up as such.My first field is an integer and starts at 1My second field is a nvarchar and needs to start at 1001My third field is an nvarchar and needs to start at 100001How do I write a sql statement that will do this?thanks for your help,Robert
Whay are you using nvarchar datatype to store numbers?MadhivananFailing to plan is Planning to fail |
 |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2009-07-09 : 10:14:38
|
| Sounds unnecessary, but you should be able to derive the values from the original number (which is why it's unnecessary) and cast it to varchar. |
 |
|
|
rjcurro
Starting Member
4 Posts |
Posted - 2009-08-13 : 14:33:15
|
| Sorry I solved my problem using temporary tables, autoincrement and some joins. I needed to use it to hide information and keep the original footprint of the database. |
 |
|
|
rohitkumar
Constraint Violating Yak Guru
472 Posts |
Posted - 2009-08-13 : 15:49:43
|
| you could have let the IDENTITY column remain as it is and add another "calculated column" based on the ID column |
 |
|
|
|
|
|