Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

SQL Trouble! Hair needs pulling out!

$
0
0

Hi all,

I was wondering if anyone could help me with this, I have had a go at a number of things like using union queries but I think I am looking in the wrong place.

I am trying to run a SQL query on a singular table to provide to users with only datareader permissions to discover total sales.

The table itself contains sales and refunds which have a type of 1 or 3 in the database.

Table example structure:

What I need to get is a total value for stock whereby the refund total is taken away from the total sum so that it appears as such:

This means that I would have to have a calcuation under one column that says:
Select (if type is 1 then sum(value) - (if type is 3 then sum(value)

In honestly I simply can't do it! I have tried using temporary tables and such but it has completely stumped me.

Can I anyone help a fellow spicehead in need? I will...

Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>