April 1, 2009 at 1:27 am
Hi friends,
how to fiend the last word .example like my table
ID ADDRESS
1 1_94 SO MATTA REDDY RAJIV CHOWK SAGAR ROAD MIRYALAGUDA
2 1_187 KERALA ROAD CHILUKUR
3 Y KRISHNA REDDY ADVOCATE
4 ADVOCATE VIJAY GARDEN BACKSID
5 CH CHANDRAIAH ADVOCATE 6_2_15A
6 NEAR 6_7_49 RAVINDRA NAGAR NALGONDA
here i want last word of ADDRESS for example.....
ID ADDRESS1
1 MIRYALAGUDA
2 CHILUKUR
3 ADVOCATE
4 BACKSID
how to write the quary plz help me
April 1, 2009 at 1:58 am
Hi
Answer to your question:
;WITH t (id, addr) AS
(
SELECT 1, '1_94 SO MATTA REDDY RAJIV CHOWK SAGAR ROAD MIRYALAGUDA'
UNION SELECT 2, '1_187 KERALA ROAD CHILUKUR'
UNION SELECT 3, 'Y KRISHNA REDDY ADVOCATE'
UNION SELECT 4, 'ADVOCATE VIJAY GARDEN BACKSID'
UNION SELECT 5, 'CH CHANDRAIAH ADVOCATE 6_2_15A'
UNION SELECT 6, 'NEAR 6_7_49 RAVINDRA NAGAR NALGONDA'
)
SELECT *, RIGHT(addr, CHARINDEX(' ', REVERSE(addr)) - 1)
FROM t
FOR FUTURE
Please have a look to the following link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
... well posted information will help you to get more, faster and even better response! 😉
Greets
Flo
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply