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 2005 Forums
 Transact-SQL (2005)
 Concatenating numbers without adding them

Author  Topic 

DavisJ44
Starting Member

9 Posts

Posted - 2009-05-22 : 12:01:03
Currently I have a variable defined as follows

@tbl = 0409

I want to subtract 1 from this variable without loosing the format when I subtract one I always get

408 for the following set

set @tbl = @tbl - 1

However, I want 0408 so I then try to subtract and concatenate

left(@tbl,2)+right(@tbl,2)-1, but this then gives me

40 + 8 = 12 literally when all I want is

0408

This is very annoying why is the concatenate symbol not

|| or & like in VBA?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-22 : 12:22:37
convert to integer then subtract after that convert back to string

right('0000' + convert(varchar(10), @tlb_int), 4)


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

Go to Top of Page
   

- Advertisement -