Solved

SQL - Add negative sign if matlfer.xtype = 'INVSUB'

Posted on 2014-02-21
3
190 Views
Last Modified: 2014-02-21
 SELECT 
        CASE matlxfer.xtype
          WHEN 'ADDINV' THEN '552'
          WHEN 'INVSUB' THEN '551'
        END AS ADJUSTMENT ,
             matlxfer.xfer_qty 

Open in new window


Add negative sign if matlfer.xtype = 'INVSUB'
Data

 matlfer.xtype matlxfer.xfer_qty
ADDINV   1
INVSUB  2
ADDINV 3
INVSUB  4

Open in new window


Our database doesn't have negatives, but I need to send data with them and i've tried variables and other things, but none have worked as I wanted.  Basically I need it to show as this.

matlxfer.xfer_qty
1
-2
 3
-4

Open in new window


Thanks
0
Comment
Question by:gpsdh
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
Comment Utility
That would be another CASE block that refers to xtype..
SELECT 
   CASE matlxfer.xtype WHEN 'ADDINV' THEN '552' WHEN 'INVSUB' THEN '551' END AS ADJUSTMENT,
   CASE matlfer.xtype WHEN 'INVSUB' THEN -1 * matlxfer.xfer_qty ELSE matlxfer.xfer_qty  END as xfer_qty 

Open in new window

0
 

Author Closing Comment

by:gpsdh
Comment Utility
That works!  Thanks!
0
 
LVL 65

Expert Comment

by:Jim Horn
Comment Utility
btw I have an article out there on SQL Server CASE Solutions that has a wompload of CASE examples.  Hit the 'Yes' button if it helps you out.

Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

772 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

12 Experts available now in Live!

Get 1:1 Help Now