[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Added an IF clause to a select query

Posted on 2011-03-08
4
Medium Priority
?
316 Views
Last Modified: 2012-05-11
I'm using a select and insert statement to insert data and need to use an IF statment to do the following:

Select the field if it is >0 otherwise return and insert a null value, first attempt which broke the script is below!!!:

SELECT IF de.gr_Percent >0 ELSE return NULL
0
Comment
Question by:mbs2000
[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
4 Comments
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 35069427
IF de.gr_Percent >0
begin
    select statement here
end
ELSE
begin
    return NULL
end
0
 
LVL 10

Expert Comment

by:Humpdy
ID: 35069436
you're looking for a CASE statement

http://www.tizag.com/sqlTutorial/sqlcase.php
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35069442
use case

SELECT case
                when de.gr_Percent > 0
                    YourField
                 ELSE
                      NULL
              end
0
 
LVL 3

Accepted Solution

by:
CarlsbergFTW earned 500 total points
ID: 35069449
you might want to try this query:

SELECT CASE de.gr_Percent WHEN > 0 THEN de.gr_Percent ELSE null END
FROM YOUR_TABLE_HERE
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

656 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