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 2000 Forums
 SQL Server Development (2000)
 SQL Query - include select in where stment

Author  Topic 

Eithne
Starting Member

8 Posts

Posted - 2004-08-30 : 12:05:48
Can anyone help with this sql query.
Is it possible to include a select statement in the where of an update statement.
I am trying to sum a number of fields together and when they are equal to zero and along with the other 'where' requirements i need to update the flag.

E.G
Update TABLE set FLAG='1'
where
(Select SUM(AMOUNT)
from TABLE
where SUM(AMOUNT) = 0.00
and FLAG = '2'
and ACC = '3')

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-30 : 12:17:18
something like this:

update t
set flag='1'
from myTable t
inner join (select id from myTable where FLAG = '2' and ACC = '3' group by id having SUM(AMOUNT) = 0) t1
on t.id = t1.id


for real solution we need more info. like table structure and sample data -> create and insert into statements


Go with the flow & have fun! Else fight the flow :)
Go to Top of Page
   

- Advertisement -