Solved

help with insert if statement

Posted on 2013-06-07
2
337 Views
Last Modified: 2013-06-07
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?
0
Comment
Question by:Gary Samuels
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
Simone B earned 500 total points
ID: 39229813
Try this (after backing up):

 UPDATE Shelby.NANames
 SET Salutation = FirstMiddle WHERE Salutation = '' AND FirstMiddle <> ''

Open in new window


It's a good idea to try a select first, to make sure you'll be updating the right data:

 SELECT * FROM Shelby.NANames
WHERE Salutation = '' AND FirstMiddle <> ''

Open in new window

0
 
LVL 70

Expert Comment

by:Qlemo
ID: 39229820
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.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how the fundamental information of how to create a table.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question