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 2000 Forums
 Transact-SQL (2000)
 how to insert preceeded values with zeroes

Author  Topic 

dasu
Posting Yak Master

104 Posts

Posted - 2004-11-22 : 00:36:10
i have following situation
@a varchar(10)
@b int
set @a='00001'
set @b=1
set @a=cast (@a as int ) + @b
now in @a value is 2
but i want 00002
can suggest me some solutions for this
regards
dasu.g



Kristen
Test

22859 Posts

Posted - 2004-11-22 : 02:08:36
[code]
DECLARE @a varchar(10)
DECLARE @b int
set @a='00001'
set @b=1
set @a=cast (@a as int ) + @b

SELECT [@a] = @a

set @a='00001'
set @b=1
set @a= RIGHT('00000' + CAST(cast (@a as int ) + @b AS varchar(5)), 5)

SELECT [@a] = @a
[/code]
Kristen
Go to Top of Page
   

- Advertisement -