SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Triggers
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

aidmondo
Starting Member

Ghana
23 Posts

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

Edited by - aidmondo on 05/12/2012 06:39:56

vijays3
Constraint Violating Yak Guru

India
311 Posts

Posted - 05/12/2012 :  06:28:22  Show Profile  Reply with Quote
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

India
311 Posts

Posted - 05/12/2012 :  06:47:11  Show Profile  Reply with Quote

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

sunitabeck
Flowing Fount of Yak Knowledge

5152 Posts

Posted - 05/12/2012 :  07:07:29  Show Profile  Reply with Quote
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

India
47023 Posts

Posted - 05/12/2012 :  19:55:17  Show Profile  Reply with Quote
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

Ghana
23 Posts

Posted - 05/13/2012 :  06:38:22  Show Profile  Reply with Quote
The article helped a lot Thanks.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000