Solved

Substitute a value for zero in SQL Server

Posted on 2009-04-13
3
231 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 150 total points
ID: 24129281
CASE WHEN BoxWeight = 0 Then 25 ELSE BoxWeight END
0
 
LVL 12

Assisted Solution

by:Dimitris
Dimitris earned 150 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 200 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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