Solved

Easy SQL Select Question (I think)

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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 …
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …

823 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