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)
 right-justified ?

Author  Topic 

ratcho
Starting Member

18 Posts

Posted - 2002-09-05 : 15:30:02
Hi! My problem is:

I have a table (Product) which contains a column (section) of type char(4). Any value I insert is left-justified. For exemple:

insert into Product(section)
values('44')

The result is
section
'44 '

I need the values I insert right-justified. Like this:
' 5'
' 44'
' 123'

I know that this will work:

insert into Product(section)
values(' 5')

But may be you will have better idea.
Thanks a lot!

nr
SQLTeam MVY

12543 Posts

Posted - 2002-09-05 : 15:39:58
insert ...
select right(replicate(' ',4) + @value),4)

with something this small probably easier to use the literal rather than replicate.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

ratcho
Starting Member

18 Posts

Posted - 2002-09-05 : 16:05:45
This solves my problem. Actually, I have much more records, so your idea is very helpfull. Thanks a lot!

Go to Top of Page
   

- Advertisement -