0

I want to insert some data in my column only if my query parameters are not already added.

For example, if my row contains :

a=4&b=7&c=9

and now, when update happens with : b=7&c=9, then i should not append it.

o/p:a=4&b=7&c=9

But if update happens with d=9&e=9 then it should append it.

o/p : a=4&b=7&c=9&d=9&e=9

My normal Update query is :

@AdditionalParams = 'b=7&c=9'
SELECT @id = mid FROM Table2 WHERE sid = @SId
                AND cid = @CId;

            UPDATE Table1
            SET additional_params = CONCAT (
                    additional_params
                    ,iif(additional_params IS NULL, NULL, '&')
                    ,@AdditionalParams
                    )
            WHERE mid = @id

How can i use here the NOT EXIST Clasue.

But with not exist clause it checks whole row, I just want to check if parameters exist, then dont insert it.

1
  • 5
    that's a pretty terrible way to store data Commented Jul 29, 2016 at 16:33

1 Answer 1

1

I guess you are looking for a not like clause

declare @AdditionalParams varchar(50) = 'b=7&c=8'
SELECT @id = mid 
   FROM Table2 
  WHERE sid = @SId
   AND cid = @CId;

  UPDATE Table1
  SET additional_params = CONCAT (
                     additional_params
                    ,iif(additional_params IS NULL, NULL, '&')
                    ,@AdditionalParams
                    )
   WHERE mid = @id
     and additional_params not like '%'+ @AdditionalParams +'%';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.