Solved

Easy SQL Select Question (I think)

Posted on 2013-06-18
3
196 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

624 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