Re: UPDATE TABLE1 ONLY WHEN ALL RECORDS IN COLUMN IN TABLE2 ARE TRUE



EdwardH wrote:
Table2 has multiple records joined to single record in Table1. I want to
UPDATE column in Table1 only if all joined records in Table2 are True.
Help would much apprec.

Here's a guess. I'm assuming that "some_col" is not nullable. If you
post proper DDL for your tables then we won't have to make so many
guesses.

UPDATE table1
SET ... ??? /* unspecified */
WHERE NOT EXISTS
(SELECT *
FROM table2
WHERE table2.some_col = 'False'
AND table2.col1 = table1.col1) ;

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--

.



Relevant Pages

  • Re: HOWTO: Use conditions in FROM clause in Access sintax.
    ... If you execute them in SQL Server I ... and that means that I need all rows in Table1 and only matching one in ... >> Table2 Ref RefExt RefTwo Data ...
    (microsoft.public.access.queries)
  • How to increment record id in an insert stored procedure
    ... Within SQL server there is a facility to have ... I need to insert records from table2 ... to table1. ... >Commit Transaction ...
    (microsoft.public.sqlserver.programming)
  • Re: Not In and Not Exists
    ... > SQL Server will try to optimize query plans so neither technique ought to ... Col1 int NULL ... > INSERT INTO Table1 VALUES ... > INSERT INTO Table2 VALUES ...
    (microsoft.public.sqlserver.programming)
  • Re: Unique record match with multiple possibilities
    ... SQL Server MVP ... FROM table1 t1 ... FROM table2 t2 ... following Pins: ...
    (microsoft.public.sqlserver.programming)
  • Re: Tricky Visual Basic Code help...
    ... moves the current record into a new record in table2. ... this with a little VBA code and a couple custom queries. ... Set a "pushFlag" column in the record in table1 to a specific ... If a duplicate is not found, ...
    (microsoft.public.access.formscoding)