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
 Triggers

Author  Topic 

aidmondo
Starting Member

23 Posts

Posted - 2012-05-12 : 06:17:12
Hi, I'm trying to create an auto generated string Culomn. Need lots of
Help. For example, SudentID should in the form S000000000001
S000000000002

vijays3
Constraint Violating Yak Guru

354 Posts

Posted - 2012-05-12 : 06:28:22
what kind of string do want to store..Can you please let us know the scienerio with data and your required output.
Go to Top of Page

vijays3
Constraint Violating Yak Guru

354 Posts

Posted - 2012-05-12 : 06:47:11
[code]
declare @a varchar(20)
set @a = 'S00'
declare @i int
set @i = 1
while (@i <= 100)
begin


insert into #Mytable (id) values(@a+ cast(@i as varchar(50)))

set @i= @i+1
end

select * from #Mytable
[/code]
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-05-12 : 07:07:29
Take a look at Jeff Smith's article here: http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server

It has some advice and tips that may be useful to you.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-12 : 19:55:17
we usually implement it by means of computed column based on identity column as specified in article

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

aidmondo
Starting Member

23 Posts

Posted - 2012-05-13 : 06:38:22
The article helped a lot Thanks.
Go to Top of Page
   

- Advertisement -