August 31, 2009 at 10:28 am
Hey Guys,
I just wanted to know that do RTRIM and LTRIM have any issues when put inside a CASE WHEN statement ? Or in a MAX? or something like that?
I'm inserting data into a table using RTRIM LTRIM but none of it is getting trimmed for some reason. My insert statement where I do the trimming is below.
Insert ............
SELECTMAX(LTRIM(RTRIM(MinorCatCd))),
CASE MAX((LTRIM(RTRIM(Level1Desc))))
WHEN '' THEN 'None'
WHEN '-' THEN 'None'
ELSE MAX(LTRIM(RTRIM(Level1Desc)))
END,
MAX(LTRIM(RTRIM(Level2Type))),
CASE MAX((LTRIM(RTRIM(Level2Desc))))
WHEN '' THEN 'None'
WHEN '-' THEN 'None'
ELSE MAX(LTRIM(RTRIM(Level2Desc)))
END,
MAX(LTRIM(RTRIM(Level3Type))),
CASE MAX((LTRIM(RTRIM(Level3Desc))))
WHEN '' THEN 'None'
WHEN '-' THEN 'None'
ELSE MAX(LTRIM(RTRIM(Level3Desc)))
END
FROMTABLE A
Please let me know what I'm doing wrong here.
Thanks,
S
--
:hehe:
August 31, 2009 at 10:32 am
Do you have the CREATE TABLE to go along with this and some example data?
Generally, LTRIM and RTRIM problems turn out to be that the column is a CHAR or NCHAR instead of VARCHAR or NVARCHAR.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
August 31, 2009 at 10:52 am
Hmm.. let me try this out and then ill get back to you here. My column is a char... Im going to change it to varchar then insert data and see if it's trimmed or not. I'll post my results here and the create table script if needed.
EDIT: Yep... that surely worked. Thank you so much.
Thanks,
S
--
:hehe:
August 31, 2009 at 12:27 pm
Glad I could help. 🙂
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply