Case statement query

Mimi

Can I use case statement on a field to change the value of another field? Something like that,

SELECT  TaskDescription, 
CASE 
When TaskDescription='Lab Dips / Handloom Sent' then seq ='1'  
When TaskDescription='Lab Dips / Handloom Approve' then seq ='2' end,seq FROM SomeTable

I have some description of tasks in TaskDescription column, that I want to fetch in a certain order. That's why I want to add a seq number to each task description value so that I can get the expected order just writing 'order by seq'

Iraj

if you want update value of table , you can use this :

Update SomeTable
Set seq = '1'
Where TaskDescription='Lab Dips / Handloom Sent'

Update :

Select TaskDescription ,seq 
From (
      SELECT  TaskDescription, 
            (CASE 
             When TaskDescription='Lab Dips / Handloom Sent' then 1 
             When TaskDescription='Lab Dips / Handloom Approve' then 2
           end) As seq FROM SomeTable
     ) As TB 
Order by TB.seq

Or :

With tb As (
    SELECT  TaskDescription
           ,(CASE TaskDescription
             When 'Lab Dips / Handloom Sent' then 1 
             When 'Lab Dips / Handloom Approve' then 2
          end) As seq 
     FROM SomeTable
)
Select * from tb
Order by tb.seq

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Case Statement In Update Query

From Dev

mysql query with case statement

From Dev

Case statement in a SQL query

From Dev

VBScript Case statement query

From Dev

Case statement query

From Dev

SQL Query for CASE Statement

From Dev

CASE Statement using Dynamic query

From Dev

case statement in select query in sql

From Dev

CASE statement in SQL query in WHERE

From Dev

Adding case statement to SQL Query

From Dev

SQL Query with LISTAGG and CASE Statement

From Dev

Update SELECT query using CASE statement

From Dev

Order sql query before executing case statement

From Dev

Case statement with end = 1 in T/SQL query

From Dev

Whats wrong with my query with CASE statement

From Dev

Getting a count from a nested query with a case statement

From Dev

CASE statement in WHERE Clause of SQL Query

From Dev

"Case statement" in a "group by query" with Entity Framework 6

From Dev

unable to use case statement in inner sql query

From Dev

Increment temperory variable value in case statement query

From Dev

How to use Not Equal with CASE statement in SQL query

From Dev

CASE WHEN statement example in SQL query

From Dev

datediff with case statement in select query linq

From Dev

SQL Query with Case Statement with latest load time

From Dev

Oracle select column as Sub query with case statement

From Dev

MySQL query case statement in where optimization

From Dev

Convert MySql query containing case statement to codeigniter active record query

From Dev

Query with case statement from SQL Server to Linq query c#

From Dev

Convert MySql query containing case statement to codeigniter active record query

Related Related

HotTag

Archive