October 22, 2024
Chicago 12, Melborne City, USA
SQL

Using IIF in SQL update statement – Returns [S0001][207] Invalid column name


I am using IIF in an Update query to set a column in SQL Server table, however I am getting an error "Invalid column name ‘Y’"

Here is the query, I want to update a column called PREVIOUS_STATUS to ‘Y’ only if another column DATE_CREATED is not null

UPDATE [dbo].[ACCOUNT]
    SET STATUS            = 'ACTIVE'
        PREVIOUS_STATUS   = IIF(DATE_CREATED IS NULL, PREVIOUS_STATUS, 'Y')
    WHERE [dbo].[ACCOUNT].ACCOUNT_NUMBER = 100;



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video