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
 General SQL Server Forums
 New to SQL Server Programming
 Help with Trigger Count

Author  Topic 

sas0riza
Yak Posting Veteran

56 Posts

Posted - 2008-11-14 : 09:56:12
[code]
update Movies
set Movies.TotalInStock = Movies.TotaIInStock + 1
from Videos
where Movies.MovieID = Videos.MovieID
[/code]


My 2 tables:

Movies (MovieID,...,TotalInStock)
Videos (VideoID,MovieID,...)


The problem is say if I have a record in the Movies table already and
the count is correct. But if I add another movie and then add the
video(s), the new movie count gets incremented plus increments the
other movie.

e.g., BEFORE
MovieID TotalInStock
11 3

e.g, AFTER
MovieID TotalInStock
11 4
12 1

What am I doing wrong? Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-14 : 10:04:59
You are updating same video/movie twice because the JOIN criteria is fulfilled.
Someone suggested w3schools to you. I suggest you read up on those pages a bit.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

sas0riza
Yak Posting Veteran

56 Posts

Posted - 2008-11-14 : 10:14:39
quote:
Originally posted by Peso

You are updating same video/movie twice because the JOIN criteria is fulfilled.
Someone suggested w3schools to you. I suggest you read up on those pages a bit.



E 12°55'05.63"
N 56°04'39.26"




Thanks, I did check out w3schools.
Go to Top of Page
   

- Advertisement -