Share via

Update Query Assistance

Johnathan Simpson 586 Reputation points
2022-05-05T17:22:26.543+00:00

Should be a basic update query, but vfr is never updated. What is incorrect in my queyr?

Update Mosa
  Set pv = 0
  ,vfr = 'Invalid Input;'+vfr
  WHERE Quantity = 0 OR Quantity IS NULL
  AND processed_file IS NULL
Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

0 comments No comments

Answer accepted by question author

Naomi Nosonovsky 8,906 Reputation points
2022-05-05T17:36:48.01+00:00

In this case, it is a simple fix:

Update Mosa
  Set pv = 0
  ,vfr = 'Invalid Input;'+ISNULL(vfr,'')
  WHERE Quantity = 0 OR Quantity IS NULL
  AND processed_file IS NULL

Run it only once.

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Tom Phillips 17,786 Reputation points
    2022-05-05T19:19:39.43+00:00

    Just to add to Naomi's response.

    CONCAT is a safer way to combine strings. It handles NULL values.

    vfr = CONCAT('Invalid Input;',vfr)
    

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. Naomi Nosonovsky 8,906 Reputation points
    2022-05-05T17:26:11.12+00:00

    The query looks OK. If you turn it into select statement, do you get result? Also, you can add OUTPUT Deleted., Inserted. to see what happened.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.