Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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




Reply With Quote
  #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

Reply With Quote
  #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


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:53 PM.


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