Friday, March 9, 2012

is there any way to sort the SELECT statement?

hi,

i have a stored procedure

SELECT PictureID,Left(Name, 16) +'...'AS ShortNameFROM Pictures

some pictures has their name lower that 16 characters, and when i show on the page is something like "Sunrise..."

how can i 'sort' the Select so to return the ShortName if the name is greater than 16 characters or return Name if is lower

i hope you understand what i mean...

thanks

Hi,

You have to use the Case Statement

SELECT PictureId, Case When Len(Name)>16 THEN Left(Name,16)+'...' ELSE Name End AS ShortName From Pictures.

Hope this helps.

|||

thank you v v much

|||

You are welcome. I am glad I could help.

No comments:

Post a Comment