Sum of cash and cheque from a table

how to write a check for cash withdrawal
can you write a check to yourself to get cash?
how to write a check for cash for someone else
can you cash a check made out to cash
check made out to cash traceable
can you write a check to yourself with no money
i found a check made out to cash
how to cash a check for cash

I need to get the sum of cash and cheque amount from a table in 2 columns order by salesman.

My table is like this:

Salesman A  Cash    21151
Salesman B  Cash    34510
Salesman C  Cash    21252
Salesman D  Cash    13356
Salesman A  Cheque  13944
Salesman B  Cheque  87368
Salesman C  Cheque  20182
Salesman D  Cheque  23862

SQL:

SELECT Ca.Cash,  Cr.Credit FROM 
    (SELECT Salesman, PayMode, SUM(Collection) AS Cash
        FROM Prospect_Detail WHERE(Purpose = 'Collections') AND (PayMode = 'Cash')
        GROUP BY Salesman, PayMode) AS Ca 
        CROSS JOIN
    (SELECT Salesman, PayMode, SUM(Collection) AS Credit
        FROM Prospect_Detail WHERE(Purpose = 'Collections') AND (PayMode = 'cheque')
        GROUP BY Salesman, PayMode) Cr

And I need to get the result like this:

Salesman       Cash      Cheque
Salesman A     21151     13944
Salesman B     34510     87368
Salesman C     21252     20182
Salesman D     13356     23862

You can pivot your table on the following way

With c as(
SELECT Salesman
     , Paymode
     , Sum(Collection) AS Cheque
FROM 
    Prospect_Detail
GROUP BY 
      Salesman
    , Paymode
)
Select Salesman
      ,[Cash]
      ,[Cheque] 
From C
Pivot(
    Sum(Cheque)
    For Paymode in ([Cash],[Cheque]) 
) as pvt;

I hope this works for you.

SQL: How to to SUM two values from different tables, select region,sum(number) total from ( select region,number from cash_table union all select region,number from cheque_table ) t group by region payments table with: CountryId (FK to countries), Total, Type (cash/cheque). i need to get the sum of cash and cheque amount from a table in 2 columns order by salesman my table is like this Salesman A Cash 21151.75 Salesman B Cash 34510.51 Salesman C Cash 21252 Salesman D Cash 13356 Salesman A Cheque 13944 Salesman B Cheque 87368.5 Salesman C Cheque 20182 Salesman D Cash 23862.05

You can try the following.

create table #Temp (name varchar(50), collectionType varchar(10), amount int)
insert into #Temp values
('Salesman A', 'Cash', 21151),
('Salesman B', 'Cash', 34510),
('Salesman C', 'Cash', 21252),
('Salesman D', 'Cash', 13356),
('Salesman A', 'Cheque', 13944),
('Salesman B', 'Cheque', 87368),
('Salesman C', 'Cheque', 20182),
('Salesman D', 'Cheque', 23862)

SELECT name, Cash, cheque 
FROM  
(SELECT collectionType, name , amount 
    FROM #Temp) AS SourceTable  
PIVOT  
(  
SUM(amount)  
FOR collectionType IN ( Cash ,  Cheque)  
) AS PivotTable;

The output is as shown below

name        Cash    cheque
--------------------------
Salesman A  21151   13944
Salesman B  34510   87368
Salesman C  21252   20182
Salesman D  13356   23862

You can find the live demo Here.

[Solved] Sum of cash and cheque from a table, Have a look at the pivot clause. Simple Way To Use Pivot In SQL Query[^] SQL Server: PIVOT Clause[^]. I have a number of tables with values I need to sum up. They are not linked either, but the order is the same across all the tables. Basically, I would like to take this two tables: CASH TABLE London 540 France 240 Belgium 340 CHEQUE TABLE London 780 France 490 Belgium 230 To get an output like this to feed into a graphing application:

Suggestions to pivot are a VAST over-complication for this. Ignore them. Just use conditional summation. A simplified example:

select Salesman, sum(case Paymode when 'Cash' then Collection else 0 end) as Cash, ...
from Prospect_Detail 
where Purpose = 'Collections'
group by Salesman 
order by Salesman;

Sum of cash and cheque from a table, 问题: I need to get the sum of cash and cheque amount from a table in 2 columns order by salesman. My table is like this: Salesman A Cash� One of the scenarios at work has left me with a number of tables with values I need to sum up. They are not linked either, but the order is the same across all the tables. Basically, I would like to take this two tables: CASH TABLE London 540 France 240 Belgium 340 CHEQUE TABLE London 780 France 490 Belgium 230

It is possible to use PIVOT operator to get the desired result:

DECLARE @tbl TABLE
(
   SalesMan varchar(50),
   PayType VARCHAR(10),
   Amount INT
)

INSERT INTO @tbl
(
    SalesMan,
    PayType,
    Amount
)
VALUES
  ('Salesman A', 'Cash',  21151)
, ('Salesman B', 'Cash',    34510)
, ('Salesman C', 'Cash',    21252)
, ('Salesman D', 'Cash',    13356)
, ('Salesman A', 'Cheque',  13944)
, ('Salesman B', 'Cheque',  87368)
, ('Salesman C', 'Cheque',  20182)
, ('Salesman D', 'Cheque',  23862)

SELECT * 
FROM 
(
    SELECT * FROM @tbl
)AS FooData
PIVOT(
    AVG(FooData.Amount)
    FOR PayType IN ([Cash], [Cheque])
) AS FooPivot

Ouptut:

SalesMan    Cash    Cheque
Salesman A  21151   13944
Salesman B  34510   87368
Salesman C  21252   20182
Salesman D  13356   23862

Accounting for Cash Transactions, Total deposits in transit added incorrectly. Double check your addition of deposits in transit. Bank balance transposed. Did you start with the correct amount at the� The SUM() Function adds numeric column values together and returns the result. It’s very easy to use it on one table: SELECT SUM(<column>) FROM <table>;; However

How to Write and Cash Checks Payable to Cash, When you write a check, you don't always have to specify who gets the money. A check that says "Pay to the Order of: Cash" can be cashed or deposited by� When you get paid with a check, there are two ways to get access to the money behind the check: You can either cash the check or deposit it. In the process of negotiating that check, you’ll want to keep fees to a minimum and avoid expensive mistakes.

How to Cash a Check as Quickly as Possible, need to wait before cashing it. Learn how to get access to your money as soon as possible. Depositing a check means adding it to your account at a bank or credit union. You'll be putting the you know the check writer. Table of Contents. Cash gifting is when someone gives you a sum of money as a gift rather than in exchange for goods or services. For example, your parents may give you money for a holiday or graduation present. However, it can also be an illegal pyramid scheme that can cost you money and potentially land you in jail.

7. Cash Transactions, On saving, the system checks whether the account to be credited is a Trust account or not. If it is a Trust account, the system will check whether the deposit amount� A lump-sum distribution is the payment of the full balance of a 401(k), pension, or another retirement account within a single tax year. This can be taken as a cash payout or rolled over into another retirement account. Tax consequences can be significant but will vary depending on the lump-sum recipient's age and how they take the payout.

Comments
  • What is current SQL's output?
  • I don't see that PIVOT is any more or less complicated than this. Swings and roundabouts for me really
  • @MartinSmith You may not, but OP is asking a question that is fairly basic for anyone with significant experience. Therefore, pivot (which is a command that one usually masters later) is IMO vastly over-complicated for OP. You have to walk before you can run.