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)
 Converting BigInt to Char left padded

Author  Topic 

Ken Blum
Constraint Violating Yak Guru

383 Posts

Posted - 2008-07-31 : 11:14:30
Brain Cramp!

declare @x bigint
SET @x = 190020
SELECT CONVERT(char(19),@x)

This comes out as '190020 ', where the spaces are on the right.

I need it to come out as ' 190020' where the spaces are to the left.

Duh....

pootle_flump

1064 Posts

Posted - 2008-07-31 : 11:28:17
Sounds like you are treating text as a number....
declare @x bigint
SET @x = 190020
SELECT RIGHT(REPLICATE(' ', 19) + CAST(@x AS VARCHAR), 19)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-01 : 07:59:37
quote:
Originally posted by Ken Blum

Brain Cramp!

declare @x bigint
SET @x = 190020
SELECT CONVERT(char(19),@x)

This comes out as '190020 ', where the spaces are on the right.

I need it to come out as ' 190020' where the spaces are to the left.

Duh....


Where do you want to show data?
If you use front end application, do this formation there

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -