Solved

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

Posted on 2014-02-21
3
192 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
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

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

919 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

23 Experts available now in Live!

Get 1:1 Help Now