[thelist] MS SQL Server - T-SQL
Joshua Olson
joshua at waetech.com
Tue Aug 19 11:48:36 CDT 2003
----- Original Message -----
From: "barry sweeney" <barry at springcottage.ndirect.co.uk>
Sent: Tuesday, August 19, 2003 12:37 PM
> In the database there is a topic table for all the topics, and a reply
table
> for all the replies (well, duh!). In the topics table There is a "Number
of
> Replies" column and I want to ensure that the figure in that field
actually
> agrees with the number of replies that have been posted for that topic.
Barry,
You may want to consider *not* taking this approach. With SQL Server (as
with Access) you could just as easily calculate this "number of replies"
column within the select. Example:
SELECT
whatever1,
whatever2,
(SELECT Count(*) FROM tblReply WHERE tblReply.topic_ID =
tblTopics.Topic_ID) AS T_Replies
FROM tblTopics
This way there's no chance of the information becoming out of synch.
You could also create a view with the above query and then use the view in
the script instead of accessing the table directly.
HTH,
<><><><><><><><><><>
Joshua Olson
Web Application Engineer
WAE Tech Inc.
http://www.waetech.com
706.210.0168
More information about the thelist
mailing list