?
Solved

Substitute a value for zero in SQL Server

Posted on 2009-04-13
3
Medium Priority
?
240 Views
Last Modified: 2012-05-06
I have a list of products, some of which contain a default weight and some of which do not.
I need to create a list where this weight is used as a multiplier. I can't chenge the data as this would cause problmes elsewhere.

What I am looking for is something like COALESCE(BoxWeight, 25) but which would work for a zero value rather that a Null value as is the case for COALESCE

Any ideas?
0
Comment
Question by:grwallace
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Assisted Solution

by:bmatumbura
bmatumbura earned 600 total points
ID: 24129281
CASE WHEN BoxWeight = 0 Then 25 ELSE BoxWeight END
0
 
LVL 12

Assisted Solution

by:Dimitris
Dimitris earned 600 total points
ID: 24129287
use case
for example :

SELECT CASE WHEN ISNULL(BoxWeight,0 ) =0 THEN 25 * something
                       ELSE BoxWeight * something
             END as Result
FROM My_Table
0
 
LVL 1

Accepted Solution

by:
joshbenner earned 800 total points
ID: 24129302
Use a CASE expression.

See: http://msdn.microsoft.com/en-us/library/ms181765(SQL.90).aspx

Example:

SELECT
  ProductName,
  Weight,
  WeightMultiplier = CASE BoxWeight WHEN 0 THEN 25 ELSE BoxWeight
FROM
  Products
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question