July 20, 2010 at 3:04 pm
July 21, 2010 at 5:16 am
I would have thought Lynn's suggestion would have worked for you?
July 21, 2010 at 5:38 am
Hi..
I think we can meet your requirement by using REPLICATE function(i.e..Repeats a character expression a specified number of times)
An updated query using REPLICATE is given below
select sno+replicate(' ',datalength(sno)-len(sno) as sno
,name+replicate(' ',datalength(name)-len(name) as name
,comments+replicate(' ',datalength(comments)-len(comments) as comments
from xyz
I hope it works fine..
[font="Comic Sans MS"]Praveen Goud[/font]
July 21, 2010 at 11:25 am
Praveen,
If we use Replicate we will have one issue..
if datalength(name)-len(name) is in negative values, I mean actual length of variable is greater than the given datalength.. Then we will get NULL value..
For me using Cast(... as char()) is working fine..
Correct me if I am wrong..
🙂
July 21, 2010 at 11:32 am
Praveen Goud Kotha (7/21/2010)
Hi..I think we can meet your requirement by using REPLICATE function(i.e..Repeats a character expression a specified number of times)
An updated query using REPLICATE is given below
select sno+replicate(' ',datalength(sno)-len(sno) as sno
,name+replicate(' ',datalength(name)-len(name) as name
,comments+replicate(' ',datalength(comments)-len(comments) as comments
from xyz
I hope it works fine..
Praveen...
Please change your Avatar. I made that Avatar and I'd like to have exclusive use of it, please. Thank you very much.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 21, 2010 at 11:47 am
Ram:) (7/21/2010)
Praveen,If we use Replicate we will have one issue..
if datalength(name)-len(name) is in negative values, I mean actual length of variable is greater than the given datalength.. Then we will get NULL value..
For me using Cast(... as char()) is working fine..
Correct me if I am wrong..
I'm confused then... why did you need to repost here if you're using Lynn's CAST/CHAR??
--Jeff Moden
Change is inevitable... Change for the better is not.
July 21, 2010 at 11:57 am
Hi,
Sorry.. I was reposted this before Lynn's reply.. Thanks everybody and Lynn..
Please correct me on using replicate..
🙂
July 21, 2010 at 12:23 pm
Ram:) (7/21/2010)
Hi,Sorry.. I was reposted this before Lynn's reply.. Thanks everybody and Lynn..
Please correct me on using replicate..
Ah... understood.
Either way is fine for performance.... the CAST method is a bit easier to read IMHO.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 21, 2010 at 2:50 pm
Thanks Jeff,
The main reason why i am opting CAST is ,
SELECT 'RAMPRASAD'+REPLICATE('',5-LEN('RAMPRASAD'))-- in this case i will get NULL values.. But here i need to get only RAMPR
SELECT 'RAMPRASAD'+REPLICATE('',15-LEN('RAMPRASAD'))-- in this case no change with CAST..
🙂
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply