Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

STR FUNCTION

Status
Not open for further replies.

mike718

Programmer
Jul 7, 2004
58
US
Hello all. I am having a slight problem with the string function. I am trying to use the String funtion in conjunction with the convert function. What I would like to do is left justify a numerical value as a set Char lenght. When I try to use the convert (to Char) function without the str function, I get an exponential value such as 289xE59 or something like that. So I use the STR function.

CONVERT(CHAR(32), STR(QTYUNITSL_S_MTF, 32))

The only problem is that the value's come up right justified. Is there anyway that I can left justify it in a 32 block space of Characters.

The reason I am doing this is to create a flat file with a set width.

Thanks
 
i dont know if this might help but anytime I need left justification I use replicate

i.e.
Code:
declare @v1 numeric(19,3)
set @v1= 1582270.001

select convert(char(32), replicate(' ', 32 - len(@v1)) + convert(varchar,@v1)) as leftjustify
select convert(char(32), convert(varchar,@v1) + replicate(' ', 32 - len(@v1)) ) as rightjustify


"I'm living so far beyond my income that we may almost be said to be living apart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top