pink
pink

Reputation: 11

Incorrect syntax near '=' in SQL statement

My query below is giving the error: Incorrect syntax near '='.

"UPDATE EF_MOCCU_MAP_MAIN"+
" SET CAST(MONETARY_CLAIM AS NVARCHAR(1))= ? ," +  
" DATA_INPUT_SELECT=?"+
" WHERE COURT_UNIT_ID=? AND MOC_CODE=?";

Initially I had the error:

Conversion failed when converting the nvarchar value 'Y' to data type int

Then I cast the SQL like "SET CAST(MONETARY_CLAIM AS NVARCHAR(1))= ? " and after that I receive the incorrect syntax error.

Upvotes: 0

Views: 2226

Answers (2)

Paul Maxwell
Paul Maxwell

Reputation: 35563

Try:

SET MONETARY_CLAIM = CASE WHEN ISNULL(?,'N') = 'Y' THEN 1 ELSE 0 END

If you are collecting a parameter/value 'Y', but sending it into a BIT or INT field [MONETARY_CLAIM] you must change the data type of the parameter to suit the field. I suggest you try using a case expression.

Upvotes: 0

peter.petrov
peter.petrov

Reputation: 39437

As others noted this is wrong.

SET CAST(MONETARY_CLAIM AS NVARCHAR(1)) = <something>

You can set a value into a column, you cannot set a value into any expression.
It just doesn't make sense (as in most programming languages).

Upvotes: 1

Related Questions