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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to generate random id and places zero infront

Author  Topic 

shinelawrence
Starting Member

32 Posts

Posted - 2014-04-29 : 00:49:25
Hi Everyone,
I generated one random ID in sql based one Employee name, i generated but the zero doesn't come.
EG:
Employee Id : L001 it is the first id of starting letter 'L', again i created another id for starting letter 'L' it shows L2 only instead of L002. If I hotcode 00 is previously the after 99th record it shows L0100 instead of 'L100'. How to do. Please tell the solution.

This is my example Query:
DECLARE @fname varchar(20)
set @fname='L099'
select CONVERT(varchar(10),(SUBSTRING('L056',2,LEN(@fname))+1))
SELECT SUBSTRING(@fname,1,1)+'0'+CONVERT(varchar(10),(SUBSTRING(@fname,2,LEN(@fname))+1)) FROM Aud_UserRegister WHERE FName ='Lawrence'

Lawce

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-04-29 : 03:03:20
duplicate post of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=193936

Please continue of that thread


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -