Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding a descriptive/commenting column on query results
    primarykey
    data
    text
    <p>I want to add a descriptive column at the end of my query results. For example I have </p> <pre><code>SELECT sum(amount) as Balance FROM tbDebits WHERE CustomerID =@CustomerID; </code></pre> <p>Now if the Balance is positive I want to add another column called 'Description' in my query results describing each result as positive or negative. Any ideas?</p> <p>Here is my original query:</p> <pre><code>SELECT t.CustomerID, c.name, c.Surname, (SELECT ( (SELECT ISNULL(SUM(cashout),0)- ((select ISNULL(sum(Buyin),0) from [Transaction] where TYPE='Credit' and CustomerID=t.CustomerID ) + (select ISNULL(sum(Paid),0) from [Transaction] where TYPE='Credit' and CustomerID=t.CustomerID )) FROM [transaction] WHERE TYPE='Credit' AND CustomerID=t.CustomerID ) ------------------- + ( (SELECT ISNULL(SUM(cashout),0) - (select ISNULL(sum(Paid),0) from [Transaction] where TYPE='Debit' AND Cashout&gt;buyin and CustomerID=t.CustomerID ) + (select ISNULL(sum(Cashout),0)- (select ISNULL(sum(PAID),0) from [Transaction] where TYPE='Debit' AND Cashout&lt;buyin and CustomerID=t.CustomerID ) from [Transaction] where TYPE='Debit' AND Cashout&lt;Buyin and CustomerID=t.CustomerID ) + (select ISNULL(sum(Cashout),0)- (select ISNULL(sum(PAID),0) from [Transaction] where TYPE='Debit' AND Cashout=buyin and CustomerID=t.CustomerID ) from [Transaction] where TYPE='Debit' AND Cashout=Buyin and CustomerID=t.CustomerID ) FROM [Transaction] WHERE CustomerID=t.CustomerID AND TYPE='Debit' AND Cashout&gt;buyin ) ) -------------- - ( select ISNULL(sum(Paid),0) from [Transaction] where type='Debit Settlement' AND CustomerID =t.CustomerID ) -------------- + ( select ISNULL(sum(Paid),0) from [Transaction] where type='Credit Settlement' AND CustomerID =t.CustomerID ) )) as Balance FROM [Transaction] as t inner JOIN Customer AS c on t.CustomerID = c.CustomerID GROUP BY t.CustomerID, c.name, c.Surname </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload