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
 General SQL Server Forums
 New to SQL Server Programming
 RPAD

Author  Topic 

zwheeler
Starting Member

25 Posts

Posted - 2011-08-11 : 13:04:14
Hi
In oracle i could use the rpad or lpad functions to pad my variable,however, i do not believe these functions exsits in sql server. how can i do this.

Actually, i need my output to be fixed length

select
pjt_no, primary_street_addr, city,st, left( ' ' + cast( zip_code AS varchar(9))), 9 )
from
openquery(daps_linked, 'select * from app_property,a1_pipe_snapshot where application_id = dap_application_id ')
where pipe_stat_grp in ('IP','O','FIN REJ','WDRN','EXP')
Go

so, for example
pjt_no ----50 characters
primary_street_addr --- 100 characters

once i see one example i can code the rest

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-08-11 : 13:20:32
CAST the values as char with the correct length:

SELECT CAST(pjt_no AS char(50)), cast(primary_street_addr as char(100)), ... FROM ...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-11 : 13:25:30
may be this?

select pjt_no + SPACE(50),primary_street_addr,...


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

zwheeler
Starting Member

25 Posts

Posted - 2011-08-11 : 14:07:21
thanks robvolk
Go to Top of Page
   

- Advertisement -