Click here to Skip to main content
15,943,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an SQL shown below that inserts a sentence substring of a description field into a table called test1 but only if the substring is not equal to the previous substring (this happens when I've gone past the last sentence).

SQL
    Insert into sentencerows (ItemNo, ItemDesc) 
    Values (1,
        (SELECT
        IF  (SUBSTRING_INDEX(SUBSTRING_INDEX(Description, '. ', 2), '. ', -1) = 
            SUBSTRING_INDEX(SUBSTRING_INDEX(Description, '. ', 1), '. ', -1), '',
            SUBSTRING_INDEX(SUBSTRING_INDEX(Description, '. ', 2), '. ', -1))
        FROM test1
        )
        );


What I'm trying to do is only do the insert when the 2 substrings are not the same - so I thought I could do this (below) but it doesn't work.

SQL
SELECT
    IF (SUBSTRING_INDEX(SUBSTRING_INDEX(Description, '. ', 2), '. ', -1) = 
        SUBSTRING_INDEX(SUBSTRING_INDEX(Description, '. ', 1), '. ', -1), '',
          (Insert into hhglobalrows (ItemNo, ItemDesc) 
           Values 
           (1,(SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(Description, '. ', 2), '. ', -1)
           FROM test1
           )
        )
        )
FROM test1;


If anyone can help I would be most grateful.

Thanks in anticipation.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900