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
 Autonumber Strings

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 1
My second field is a nvarchar and needs to start at 1001
My third field is an nvarchar and needs to start at 100001

How 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]

Go to Top of Page

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
Go to Top of Page

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 1
My second field is a nvarchar and needs to start at 1001
My third field is an nvarchar and needs to start at 100001

How do I write a sql statement that will do this?

thanks for your help,

Robert


Whay are you using nvarchar datatype to store numbers?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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.
Go to Top of Page

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.
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -