Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Easy SQL Select Question (I think)

Posted on 2013-06-18
3
Medium Priority
?
198 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
[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
3 Comments
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 2000 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

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…
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

722 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