Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
TSQL 2000/2005 Query Conundrum
Message
 
 
À
10/12/2007 13:22:09
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01274411
Message ID:
01274499
Vues:
11
This message has been marked as a message which has helped to the initial question of the thread.
Sure
UPDATE i SET myfield = 'FANC' 
	from table1 i
  WHERE (i.field1 = 'FA' and field2 IN('AAA','BBB') AND i.field3 = 0)
     AND NOT EXISTS (SELECT * from table3 a WHERE a.table2id = i.table2id AND a.field4 = i.field4)
     AND (EXISTS (SELECT * from table2 s WHERE s.table2id = i.table2id AND s.fielda <> 'X' AND s.fieldb <> 'I')
     		OR NOT EXISTS (SELECT * from table2 s WHERE s.table2id = i.table2id and x.field4=i.field4))
>
>
>Can a field in the result set be updated based on the query result? In other words (I'm trying this unsuccessfully):
>
>UPDATE table1 x SET myfield = 'FANC'
>  WHERE EXISTS
>  (SELECT i.* from table1 i
>  WHERE (i.field1 = 'FA' and field2 IN('AAA','BBB') AND i.field3 = 0)
>     AND NOT EXISTS (SELECT * from table3 a WHERE a.table2id = i.table2id AND a.field4 = i.field4))
>     AND (EXISTS (SELECT * from table2 s WHERE s.table2id = i.table2id AND s.fielda <> 'X'
>                   AND s.fieldb <> 'I')
>     OR NOT EXISTS (SELECT * from table2 s WHERE s.table2id = i.table2id)) and x.field4=i.field4)
>
>
>I want to update a field in all the records in table1 that come back in that query (using tsql not fox)...
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform