Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to update count column from child table?
Message
De
18/11/2000 15:26:20
 
 
À
17/11/2000 13:30:39
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00443143
Message ID:
00443395
Vues:
13
update parent
set childcount =
(select COUNT(item_code)
from child
where child.pcode = parent.pcode)
from parent

If you do this in an insert trigger to the child you can do something like...

update parent
set childcount =
(select COUNT(item_code)
from child
where child.pcode = parent.pcode)
from parent
join inserted on parent.pcode=inserted.pcode

**********
BOb


>Hello,
>
>I'm trying to figure out the syntax for updating a count column based on the child table count.
>Parent table has the columns columns pcode, childcount
>Child table has the columns pcode, childname
>
>I'm thinking I want to do something like the following, though I'm stuck
>figuring out how to finish the sql
>
>update parent
>set childcount =
> (select COUNT(item_code)
> from child
> where child.pcode = parent.pcode)
>
>How do I tell the subquery what the parent.pcode is?
>
>Any suggestions would be greatly appreciated.
>
>Thanks,
>-Isaac
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform