Click here to Skip to main content
12,449,762 members (77,742 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL-Server
Hi

I have a query that has to find values VIA

select  distinct strclient,
SUM(intTotalValue) as Total
from tblBatch
where
  Year(dtmDateTransmitted) = 2012
and MONTH(dtmDateTransmitted) =  6
group by strClient


So when I run the query I need the clients that don't have values as well as the ones that do.

I need this to run in SQL server 2008 .

any suggestions?
Posted 20-Sep-12 22:53pm
Updated 20-Sep-12 23:40pm
v7
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try the COALESCE operator
select distinct Clients,
SUM(COALESCE (intTotalValue,0)) as TotalForMonth
from TblPayments
  Permalink  
Comments
Member 9374423 21-Sep-12 5:01am
   
No, says invalid colum than
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Try this:
SELECT  DISTINCT strclient,
	SUM(ISNULL(intTotalValue, 0)) AS Total
	FROM tblBatch
	WHERE
		YEAR(dtmDateTransmitted) = 2012
		AND MONTH(dtmDateTransmitted) =  6
GROUP BY strClient

--Amit
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160826.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100