Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old August 8th, 2008, 08:46 PM
Newbie
 
Join Date: Aug 2008
Posts: 1
Default case when gone wrong

I meant for the following query (run on a friday) to return "FRIDAY" in the first column and "1" in the second column. It returns FRIDAY alright, but in the second column returns 0. Can anyone tell my why and how to fix it?

SELECT a.dayofweek, (CASE WHEN a.dayofweek = 'FRIDAY' THEN 1 ELSE 0 END) daynum
FROM (SELECT TO_CHAR(sysdate,'DAY') as dayofweek
FROM dual
) a
Reply
  #2  
Old August 11th, 2008, 06:55 AM
Administrator
 
Join Date: Sep 2006
Posts: 11,312
Default

The field might not be exactly 'FRIDAY' in the database. Perhaps there are extra spaces e.t.c. Try TRIMming the values before comparing.
Reply
  #3  
Old August 11th, 2008, 08:39 AM
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 6,870
Default

As suggested in the previous post ry the following.

Expand|Select|Wrap|Line Numbers
  1. SELECT a.dayofweek, (CASE WHEN TRIM(a.dayofweek) = 'MONDAY' THEN 1 ELSE 0 END) daynum
  2. FROM (SELECT TO_CHAR(sysdate,'DAY') as dayofweek
  3. FROM dual
  4. ) a 
  5.  
  6.  
Reply
Reply

Bookmarks

Thread Tools

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 Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles