Solved

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

Posted on 2014-02-21
3
207 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
[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
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 39877370
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
ID: 39877503
That works!  Thanks!
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39877560
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

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.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

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