Results 1 to 4 of 4

Thread: Use the CASE Statement in a SQL SELECT Clause

  1. #1
    Join Date
    Dec 2008
    Posts
    69

    Use the CASE Statement in a SQL SELECT Clause

    Can any one tell me the how to use select case in sql? If there are multiple values in based on condition then where to put select case and what are formats of CASE expression?

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Use the CASE Statement in a SQL SELECT Clause

    This the example of select case in sql :
    Code:
    DECLARE @TestVal int
    SET @TestVal = 4
    SELECT
    CASE @TestVal
    WHEN one THEN 'First'
    WHEN two THEN 'Second'
    WHEN three THEN 'Third'
    WHEN four THEN 'fourth'
    ELSE 'Other'
    END

  3. #3
    Join Date
    Jan 2009
    Posts
    199

    Re: Use the CASE Statement in a SQL SELECT Clause

    The CASE expression has two formats:
    The simple CASE expression compares an expression to a set of simple expressions to determine the result.
    The searched CASE expression evaluates a set of Boolean expressions to determine the result.

  4. #4
    Join Date
    Dec 2008
    Posts
    177

    Re: Use the CASE Statement in a SQL SELECT Clause

    Select Case allows you to present data in various way. You can take numbers and return text values and express. You can take numbers and return text values and express.The SQL CASE statement has WHEN, THEN, and ELSE clauses along with an END terminator.

    Syntax :
    Code:
    CASE [expression]
    	WHEN [value | Boolean expression] THEN [return value]
    	[ELSE [return value]]
    END

Similar Threads

  1. Problem of WHERE clause in SQL statement
    By Macario in forum Software Development
    Replies: 4
    Last Post: 15-10-2010, 08:02 AM
  2. Replies: 1
    Last Post: 16-08-2010, 02:03 PM
  3. How to insert artificial data into a select statement?
    By MAHAH in forum Software Development
    Replies: 5
    Last Post: 12-03-2010, 09:03 PM
  4. insert into select statement for database
    By Aidan 12 in forum Software Development
    Replies: 5
    Last Post: 09-03-2010, 10:08 PM
  5. SWITCH....CASE statement in C#
    By Aadarsh in forum Software Development
    Replies: 1
    Last Post: 10-11-2008, 05:39 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,726,156.26016 seconds with 17 queries