August 3, 2009 at 8:23 am
union all
select SUBSTRING('123' + ' ',0,12) + '456789'
does not return 4 below 8 but moves it to the left, which is inconvenient, for I'm tinkering with the Ajax toolkits auto-complete extender. Trying to make it multi-column without doing too much work. And it does work... sort of but I would like to make second column start at the fixed length so as not to be ugly.
Is there any way I can achieve this effect?
August 3, 2009 at 1:08 pm
I think your prob is not in the SQL.
In MSMS, if you send your Results to Text, you get this:
1234567 89
123 456789
1 23456789
Isn't this what you are trying to acheive?
-MarkO
"You do not really understand something until you can explain it to your grandmother" - Albert Einstein
August 3, 2009 at 7:52 pm
You might also consider using the char datatype, which is fixed length, instead of padding and using SUBSTRING. It will save you a few CPU cycles.
declare @char char(10)
set @char = '12345'
select @char+'67890'
-- or
select cast('12345' as char(10))+'67890'
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
August 3, 2009 at 8:44 pm
I guess I don't understand... textual datatypes are naturally "left justified" and there is no need to RPAD.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 4, 2009 at 1:23 am
Yeah, you are right sql is not the problem. Apparently problem is the treatment of white-space in .NET display controls. For when you run this query and send results to grid you get them garbled, and apparently same thing happens when I send this result as datatable to my c#-asp.net code.
which means this is not the right forum for this question.
Anyway, I am grateful for your replies, thank you.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply