Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 12-08-2009
Member
 
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?
Reply With Quote
  #2  
Old 12-08-2009
Member
 
Join Date: May 2008
Posts: 2,293
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
Reply With Quote
  #3  
Old 12-08-2009
Member
 
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.
Reply With Quote
  #4  
Old 12-08-2009
Member
 
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Use the CASE Statement in a SQL SELECT Clause"
Thread Thread Starter Forum Replies Last Post
Problem of WHERE clause in SQL statement Macario Software Development 4 15-10-2010 08:02 AM
Store procedure with 10 select statement.how to create datatable in dotnet? itechsasi Software Development 1 16-08-2010 02:03 PM
How to insert artificial data into a select statement? MAHAH Software Development 5 12-03-2010 09:03 PM
insert into select statement for database Aidan 12 Software Development 5 09-03-2010 10:08 PM
SWITCH....CASE statement in C# Aadarsh Software Development 1 10-11-2008 05:39 PM


All times are GMT +5.5. The time now is 08:38 PM.