Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
cjhardie
Yak Posting Veteran
58 Posts |
Posted - 2007-01-23 : 16:15:34
|
| I need to make my result set only show one row any help??declare @startdate datetime, @enddate datetimeset @startdate = '1/1/2007'set @enddate = '1/1/2020'select b.businessname, bb.businessname, (select sum(amount) from billingschedule bs1 where billingdate >= @startdate and bs1.clientcontractid = cc.clientcontractid)from clientcontract cc inner join contact c on cc.salesrepcontactid = c.contactid inner join business b on c.businessid = b.businessid inner join business bb on cc.businessid = bb.businessid inner join venue v on cc.venueid = v.venueid inner join contact c1 on cc.businessid = c1.businessid and c1.deletedate is null inner join billingschedule bs on cc.clientcontractid = bs.clientcontractid and bs.deletedate is null where cc.startdate < @startdate and cc.enddate >= @startdate and cc.deletedate is null and b.businessid != 1 order by b.businessnameAOM-Austin American Home Mortgage 225.00AOM-Austin American Home Mortgage 225.00AOM-Austin American Home Mortgage 225.00AOM-Austin American Home Mortgage 225.00AOM-Austin American Home Mortgage 225.00AOM-Austin American Home Mortgage 225.00AOM-Austin American Home Mortgage 225.00AOM-Austin American Home Mortgage 225.00AOM-Austin American Home Mortgage 225.00AOM-Austin American Home Mortgage 225.00AOM-Austin American Home Mortgage 225.00AOM-Austin American Home Mortgage 225.00 |
|
|
sshelper
Posting Yak Master
216 Posts |
Posted - 2007-01-23 : 17:12:07
|
| Try adding a DISTINCT clause to your SELECT statement:declare @startdate datetime, @enddate datetimeset @startdate = '1/1/2007'set @enddate = '1/1/2020'select DISTINCTb.businessname, bb.businessname,(select sum(amount) from billingschedule bs1 where billingdate >= @startdate and bs1.clientcontractid = cc.clientcontractid)from clientcontract cc inner join contact c on cc.salesrepcontactid = c.contactid inner join business b on c.businessid = b.businessidinner join business bb on cc.businessid = bb.businessidinner join venue v on cc.venueid = v.venueidinner join contact c1 on cc.businessid = c1.businessid and c1.deletedate is nullinner join billingschedule bs on cc.clientcontractid = bs.clientcontractid and bs.deletedate is nullwhere cc.startdate < @startdate and cc.enddate >= @startdate and cc.deletedate is nulland b.businessid != 1 order by b.businessnameSQL Server Helperhttp://www.sql-server-helper.com |
 |
|
|
|
|
|