question

artistlover avatar image
artistlover asked

TSQL LEFT AND RIGHT OF FIELD WITH COMMA

I Have the code below pulls everything to left of comma when CHARINDEX(',', ADDRSS3) > 0 then RTRIM(LEFT(ADDRSS3, CHARINDEX(',', ADDRSS3) - 1)) else ADDRSS3 But for the next field I need everything to the right of the comma I have tried a number of things but I don't get right of the comma it is everything after the first four. when CHARINDEX(',', ADDRSS3) > 0 then RIGHT(ADDRSS3, CharIndex(',', ADDRSS3 + ',')-1) else ADDRSS3
tsql
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
artistlover avatar image
artistlover answered
,case when CHARINDEX(',', ADDRSS3) > 0 then right(ADDRSS3,(CHARINDEX(',',REVERSE(addrss3),0))-1) else addrss3 END Got it.. Thoughts on what to do if field before it has what the third field should. For instance Field1 Field2 Field3 1253 main st somewhere, al instead of Field1 Field2 Field3 1253 main st po box 999 somewhere, al In the above I am setting field3 to somewhere and field four to AL There are not many where city, state is in field2 but I saw some.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.