I am trying to use IF... ELSE to insert data into a table deoending on the content of the original table. The script below is supposed to insert address data into field a certain way if one of the fields is NULL, and then a different way otherwise.Declare @Customer_no varchar (15), @Street2 varchar (55), @Street1 varchar (55), @City varchar (18), @Postcode varchar (10), @Country varchar (5), @Address_Type varchar (5), @Phone1 varchar (20),IF (SELECT ADDRESS2 FROM MASTER_ACCOUNT) LIKE NULLBEGIN Declare Cur_Grab_data Cursor FOR select ACCOUNT,ADDRESS2,ADDRESS1,CITY,POSTCODE,COUNTRY,Address_Type,DAY_PHONE from MASTER_ACCOUNT OPEN Cur_Grab_data FETCH NEXT FROM Cur_Grab_data INTO @Customer_no, @Street2, @Street1, @City, @Postcode, @Country, @Address_Type, @Phone1 WHILE @@FETCH_STATUS = 0 begin insert into T_Address values(@Customer_no, @Street2, @Street1, @City, @Postcode, @Country, @Address_Type, @Phone1) FETCH NEXT FROM Cur_Grab_data INTO @Customer_no, @Street2, @Street1, @City, @Postcode, @Country, @Address_Type, @Phone1 end close Cur_Grab_data DEALLOCATE Cur_Grab_dataENDELSE Declare Cur_Grab_data Cursor FOR select ACCOUNT,ADDRESS1,ADDRESS2,CITY,POSTCODE,COUNTRY,Address_Type,DAY_PHONE from MASTER_ACCOUNT OPEN Cur_Grab_data FETCH NEXT FROM Cur_Grab_data INTO @Customer_no, @Street2, @Street1, @City, @Postcode, @Country, @Address_Type, @Phone1 WHILE @@FETCH_STATUS = 0 begin insert into T_Address values(@Customer_no, @Street2, @Street1, @City, @Postcode, @Country, @Address_Type, @Phone1) FETCH NEXT FROM Cur_Grab_data INTO @Customer_no, @Street2, @Street1, @City, @Postcode, @Country, @Address_Type, @Phone1 end close Cur_Grab_data DEALLOCATE Cur_Grab_data
I am getting the following error:Incorrect syntax near the keyword 'IF'Can anybody help?ThanksP