Advertisement

11.27.2005 at 09:26PM PST, ID: 21644588
[x]
Attachment Details

SQL If else statement

Asked by jonesy2k in MS SQL Server

Tags: sql, else

Just quickie,

I need to return a string value based on data from a column.
For example, if data from a column contains "0" I need to return the string "Z", if it doesn't I need to return "C".

Wasn't sure the best way to approach this. Can you do if statements in the middle of a query??

SELECT
      column1,
        column2,
      if (column3 = 0)
      begin
            'Z',
      end
        else
      begin
            'C',
      end
FROM table1Start Free Trial
[+][-]11.27.2005 at 09:46PM PST, ID: 15371052

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: sql, else
Sign Up Now!
Solution Provided By: sajuks
Participating Experts: 2
Solution Grade: A
 
 
[+][-]11.27.2005 at 09:50PM PST, ID: 15371059

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11.27.2005 at 09:52PM PST, ID: 15371063

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.27.2005 at 10:14PM PST, ID: 15371111

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32