Wrox Programmer Forums
| 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 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
 
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)



 
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
 
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

 
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





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





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