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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Update and Count in the same Qry

Author  Topic 

Trudye
Posting Yak Master

169 Posts

Posted - 2008-06-19 : 12:58:00
Hi Guys, I cannot seem to get the syntax right on this one. I am trying to Update a field in a table with the recount of another table. Is it even possible to do this???

Update P_Dates SET RecCount = RecCnt
FROM
(SELECT Count(ACCTNO) As RecCnt
FROM IMPORT
Where @sDate = StartDate AND @eDate = EndDate)

any ideas?
Thanx,
Trudye

Hommer
Aged Yak Warrior

808 Posts

Posted - 2008-06-19 : 13:11:07
Use a #Table or subquery.
UPDATE doesn't work with aggrigate functions.
Go to Top of Page

Trudye
Posting Yak Master

169 Posts

Posted - 2008-06-19 : 13:14:13
Thanks so much Homer for responding so quickly. I really wanted to put it in a Stored Proc, so I guess I'll use a scalar to assign the count to.

thanx again
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-19 : 13:14:55
[code]Update P_Dates
SET RecCount = t.RecCnt
FROM
(SELECT Count(ACCTNO) As RecCnt
FROM IMPORT
Where @sDate = StartDate AND @eDate = EndDate)t[/code]
Go to Top of Page
   

- Advertisement -