Solved

Easy SQL Select Question (I think)

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now