Solved

Substitute a value for zero in SQL Server

Posted on 2009-04-13
3
200 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Merige returns error code when updating 15 51
Incremental load example 2 52
MS SQL page split per second is high 19 71
SQL Backup skipping a few tables 7 35
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now