Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have this Select working fine.select distinct top 1000 accountnumber, sum(JobTotal) from dbo.stsJobHistory where DateEntered>'2005-12-31' group by accountnumber order by sum(JobTotal) descBut when I added another where like below, it dose not like it. select distinct top 1000 accountnumber, sum(JobTotal) from dbo.stsJobHistory where DateEntered>'2005-12-31' and accountnumber not exists in (Select account_number from #TopAccounts)group by accountnumber order by sum(JobTotal) descWhat is the alternative? Thanks!!
snSQL
Master Smack Fu Yak Hacker
1837 Posts
Posted - 2006-12-27 : 17:24:39
Your syntax is a little off, try this
select distinct top 1000 accountnumber, sum(JobTotal) from dbo.stsJobHistory where DateEntered>'2005-12-31' and not exists (Select * from #TopAccounts where account_number = accountnumber)group by accountnumber order by sum(JobTotal) desc