Link to home
Start Free TrialLog in
Avatar of Gary Samuels
Gary SamuelsFlag for United States of America

asked on

help with insert if statement

Need to copy data from FirstMiddle field to Salutation field if FirstMiddle is not empty and Salutation is empty. I've been trying this:
INSERT INTO [Shelby].[NANames] ([Salutation])
VALUES [Shelby].[NANames] ([FirstMiddle]);
 WHERE (([Shelby].[NANames].[FirstMiddle] <> '')  AND ([Shelby].[NANames].[Salutation] = '') )

Open in new window



But I'm getting a syntax error, can anyone help?
ASKER CERTIFIED SOLUTION
Avatar of Simone B
Simone B
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Qlemo
INSERT INTO creates a new row - not want you want to do, I assume. Sounds like you want to update the Salutation field:
UPDATE Shelby.NANames
SET Salutation = FirstMiddle
WHERE FirstMiddle <> '' and (Salutation = '' or Salutation is null)

Open in new window

Note that empty string is not the same as NULL, so I have checked for both.