Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language 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 April 24th, 2005, 02:55 PM
Authorized User
 
Join Date: Apr 2005
Location: Vancouver, , Canada.
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default Case statement

Hi any comments on why the ELSE in the case statement will not work
This code is being used within a SProc and is failing on the ELSE
NOTE: the field attributes are
CoatingsEdge nvarchar (NULLS allowed)
score nvarchar
weight nvarchar
rating nvarchar

also 1st case condition the calculation is rounding up in the nvarchar.

Unfortunately, I didn't create the field attributes and need to work with them for reporting purpose.

--coatings edge

update #temptable
set SII = (select distinct
   Case
   When CoatingsEdge is not null then ((score *1.0)* (weight*1.0) )
   else (weight*1.0)
   END
   from tksii_maincategory
   where maincategory = 'coatings'
   and deficiency = 'edge'
   and rating = CoatingsEdge)

  +
--coatings weld
  (select distinct
   Case
  When CoatingsWeld is not null then ((score *1.0)* (weight*1.0) )
  else (weight*1.0)
  END
  from tksii_maincategory
  where maincategory = 'coatings'
  and deficiency = 'weld'
  and rating = CoatingsWeld)



Reply With Quote
  #2 (permalink)  
Old April 26th, 2005, 09:30 PM
Registered User
 
Join Date: Nov 2003
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Cole,

I think your lack of result may be caused by nulls. Your else statement depends on CoatingsEdge being null, but the where clause requires rating to be equal to CoatingsEdge. And that's the spot: when you ask for something to be tested as equal to a null.

Try this to see the dilemma directly and I'll bet you won't get any of the rows where CostingsEdge and rating are really the same but both null:
Select * from tksii_maincategory where rating = CoatingsEdge

To solve this, maybe a union would work. First get the result set where CoatingsEdge is not null, then union it with the set where it is null. This way you can skip the Case statement, and tailor the where clause as needed by each result set.

Stoney
Reply With Quote
  #3 (permalink)  
Old May 8th, 2005, 02:58 PM
Authorized User
 
Join Date: Apr 2005
Location: Vancouver, , Canada.
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Stoney
 Hey Cole,

I think your lack of result may be caused by nulls. Your else statement depends on CoatingsEdge being null, but the where clause requires rating to be equal to CoatingsEdge. And that's the spot: when you ask for something to be tested as equal to a null.

Try this to see the dilemma directly and I'll bet you won't get any of the rows where CostingsEdge and rating are really the same but both null:
Select * from tksii_maincategory where rating = CoatingsEdge

To solve this, maybe a union would work. First get the result set where CoatingsEdge is not null, then union it with the set where it is null. This way you can skip the Case statement, and tailor the where clause as needed by each result set.

Stoney

Reply With Quote
  #4 (permalink)  
Old May 8th, 2005, 03:02 PM
Authorized User
 
Join Date: Apr 2005
Location: Vancouver, , Canada.
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Stoney,

I did realize the problem just after I posted. I appreciate your response and thanks for verifying my theory.

brgrds
Quote:
quote:Originally posted by Stoney
 Hey Cole,

I think your lack of result may be caused by nulls. Your else statement depends on CoatingsEdge being null, but the where clause requires rating to be equal to CoatingsEdge. And that's the spot: when you ask for something to be tested as equal to a null.

Try this to see the dilemma directly and I'll bet you won't get any of the rows where CostingsEdge and rating are really the same but both null:
Select * from tksii_maincategory where rating = CoatingsEdge

To solve this, maybe a union would work. First get the result set where CoatingsEdge is not null, then union it with the set where it is null. This way you can skip the Case statement, and tailor the where clause as needed by each result set.

Stoney

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 statement Hudson40 Access VBA 1 February 11th, 2005 11:31 AM
case statement troubles!! ronny Classic ASP Databases 2 April 10th, 2004 07:32 PM
Using A CASE Statement fastcorvette Access 5 December 24th, 2003 01:39 PM
HELP - IF ELSE & CASE statement savoym SQL Language 3 September 12th, 2003 06:35 AM
case statement jakeone Beginning PHP 10 August 19th, 2003 03:03 PM



All times are GMT -4. The time now is 08:59 PM.


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