Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 19th, 2005, 06:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: abu dbabi, , United Arab Emirates.
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default case clause in query

How can use the case clause in the following query ?

data in the table like this.

userid...vdate....video1..........video2......vide o3.............video4.....to.....video14
----------------------------------------------------------------------------------------
Martin..5/2/2005..Office Safety..Road Safety.....................
Martin..8/2/2005..--------....................Electrical Safety.................
John....2/2/2005.........------...............Electrical Safety...............
John....4/2/2005..Office Safety..Road Safety...............
Peter...5/2/2005..Office Safety.............---------------------Back Safety.....
Peter...6/2/2005.......---------..............Eelectrical Safety......


I use query like this.

select userid, vdate,
video1 = case when video1 is null then 'not completed' else 'completed' end,
video2 = case when video2 is null then 'not completed' else 'completed' end,
video3 = case when video3 is null then 'not completed' else 'completed' end,
video4 = case when video4 is null then 'not completed' else 'completed' end
from
(select userid, vdate = max(vdate), video1=max(video1), video2=max(video2), video3=max(video3),video4=max(video4)
from pvideo
group by userid
) t

Query result like this

userid...vdate....video1..........video2......vide o3.......video4......to..video14
--------------------------------------------------------------------------------
Martin..5/2/2005..completed.....completed...completed.....comp leted....completed...
John....2/2/2005..completed.....completed...completed.....comp leted....completed...
Peter...5/2/2005..completed.....completed---completed.....completed....completed....


I want that if user not view the video it should display not completed and if user view the video it diplay completed in
the respective fields how ?

regards

Mateen




  #2 (permalink)  
Old February 21st, 2005, 06:51 AM
Authorized User
 
Join Date: Feb 2005
Location: Pune, Maharashtra, India.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Query you have used seems pretty correct, should return desired result...

Regards,
Pooja Falor

  #3 (permalink)  
Old February 22nd, 2005, 05:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: abu dbabi, , United Arab Emirates.
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I trying, but it not return desired result.
but it retrieve in all fields completed.

where fields are empty it should display "not completed" how ?

regards.

Mateen




Similar Threads
Thread Thread Starter Forum Replies Last Post
Case in Where Clause acko SQL Server 2000 12 September 12th, 2011 01:43 PM
CASE WHEN WHERE CLAUSE deontae45 SQL Server 2000 2 January 11th, 2011 10:03 AM
Problems using case statement in where clause vghiya SQL Server 2000 3 May 28th, 2007 05:12 AM
Case in Where Clause demiwolf SQL Server 2000 3 March 23rd, 2006 12:45 PM
case clause in Access mateenmohd Access 19 May 6th, 2004 03:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.