Solved

Easy SQL Select Question (I think)

Posted on 2013-06-18
3
193 Views
Last Modified: 2013-06-20
All,

I am trying to write an insert query that will look at a table (table1) and insert values into a new table (Table2) based on that original table (Table1).     In table1 I want to look at the BLF_Election field and if it is a 1 I want to put the letters BLF into a field in table 2, if it is not a 1 I want to put nothing.

This seems like it would be pretty simple. and  I tried this code

IF(table1.BLF_Election =  1) , BLF, '')

However that didn't seem to work.   Can anyone assist?
0
Comment
Question by:Earl Kelly
3 Comments
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 500 total points
ID: 39258035
try the psuedo code below

insert into Table2
SELECT CASE WHEN BLF_Election =  1 THEN 'BLF' ELSE '' END as Column1
FROM Table1

Open in new window


you have to replace the Table1 and Table2 with the correct tables and the Column1 should be the correct column name in the Table2.
0
 
LVL 32

Expert Comment

by:awking00
ID: 39260804
Can you provide some sample data and structures for table1 and table2 and what you would expect as results?
0
 
LVL 1

Author Closing Comment

by:Earl Kelly
ID: 39262494
This worked perfectly....thank you so much
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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