REPLACE & PATINDEX issue

  • Using the data setup from Eirikur and the data I added, the following works. Not knowing the state of your data, however, I can't promise anything.

    SELECT

    sd.SystemID

    ,ca1.IP

    ,ca2.MAC

    FROM

    dbo.SystemsRE sd

    CROSS APPLY (SELECT LEFT(sd.IpAddress, PATINDEX('%,%', sd.IpAddress) - 1)) ca1(IP)

    CROSS APPLY (SELECT RIGHT(sd.IpAddress, LEN(sd.IpAddress) - PATINDEX('%,%', sd.IpAddress) - 1)) ca2(MAC)

    WHERE

    patindex('%,%', sd.IpAddress) > 0;

  • TJT (5/29/2015)


    Wow! Well done!

    Yes I found one entry missing a comma. I don't suppose you have a trick to handle this one?

    Fix the data.

Viewing 2 posts - 31 through 31 (of 31 total)

You must be logged in to reply to this topic. Login to reply