Solved

help with insert if statement

Posted on 2013-06-07
2
332 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
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 69

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
convert in derived column 7 30
always on switch back after failover 2 35
Return 0 on SQL count 24 30
any adverse effect when modifying data type on a busy table. 4 13
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
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 utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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…

773 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