﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>InstantASP Community Forums / Old Forums / InstantForum.NET 4.x / Suggestions &amp; Requests  / SQL Script for Forum Subscriptions / Latest Posts</title><generator>InstantForum.NET v4.1.4</generator><description>InstantASP Community Forums</description><link>http://community.instantasp.co.uk/</link><webMaster>sales@instantasp.co.uk</webMaster><lastBuildDate>Fri, 09 Jan 2009 04:03:04 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: SQL Script for Forum Subscriptions</title><link>http://community.instantasp.co.uk/Topic8518-51-1.aspx</link><description>Hi Jon,&lt;/P&gt;&lt;P&gt;Many thanks for making this available. When i have a moment i'll review the SQL and provide any further comments. Good stuff :D</description><pubDate>Mon, 19 Sep 2005 08:38:55 GMT</pubDate><dc:creator>Ryan Healey</dc:creator></item><item><title>SQL Script for Forum Subscriptions</title><link>http://community.instantasp.co.uk/Topic8518-51-1.aspx</link><description>Here is a SQL script I created that will automatically subscribe all memebers to all forums in which they are a group member.  &lt;/P&gt;&lt;P&gt;The script was written quickly and probably needs to suggestions or adjustments. &lt;/P&gt;&lt;P&gt;I have added this script to execute as a trigger on the InstantForum_ForumsRoles and InstantASP_UsersRoles. Any time data is changed in these tables this trigger is fired.&lt;/P&gt;&lt;P&gt;One of the key points to this script is the second part. It automatically removes anyone from a forum subscription if their group permissions are removed from that forum. I am not that familiar with InstantASP Forum, my initial observation is if someone is removed from a forum, or banned from all the forums, they will still receive the subscription notices.&lt;/P&gt;&lt;P&gt;Anyway, take a look and let me know if this is problematic.&lt;/P&gt;&lt;P&gt;&lt;FONT style="BACKGROUND-COLOR: #dd99dd" face="Courier New"&gt;SET QUOTED_IDENTIFIER ON &lt;BR&gt;GO&lt;BR&gt;SET ANSI_NULLS ON &lt;BR&gt;GO&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT style="BACKGROUND-COLOR: #dd99dd" face="Courier New"&gt;ALTER  PROCEDURE sp_MITS_UpdateForumSubscriptions&lt;BR&gt;as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT style="BACKGROUND-COLOR: #dd99dd" face="Courier New"&gt;/* Insert any users that are assigned to forum roles in the forum subscriptions table */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT style="BACKGROUND-COLOR: #dd99dd" face="Courier New"&gt;INSERT INTO InstantForum_ForumSubscriptions (ForumId, UserId, SubscriptionType) &lt;BR&gt;SELECT fo.ForumId, u.UserId, SubType=4&lt;BR&gt;FROM InstantForum_ForumsRoles fr &lt;BR&gt;JOIN InstantASP_Roles r ON fr.RoleId=r.RoleId&lt;BR&gt;JOIN InstantForum_Forums fo ON fr.ForumId=fo.ForumId&lt;BR&gt;JOIN InstantASP_UsersRoles ur ON fr.RoleId = ur.RoleId&lt;BR&gt;JOIN InstantASP_Users u ON u.UserId = ur.UserId&lt;BR&gt;LEFT OUTER JOIN InstantForum_ForumSubscriptions fs ON fs.UserId=u.UserId AND fs.ForumId=fo.ForumId&lt;BR&gt;WHERE fo.IsCategory=0 AND fs.UserId is null&lt;BR&gt;GROUP BY u.UserId, fo.ForumId&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR&gt;&lt;FONT style="BACKGROUND-COLOR: #dd99dd" face="Courier New"&gt;/*Remove any users that no longer belong to the correct roles from the subscriptions tables */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT style="BACKGROUND-COLOR: #dd99dd" face="Courier New"&gt;DELETE FROM InstantForum_ForumSubscriptions &lt;BR&gt;WHERE ForumSubscriptionId IN &lt;BR&gt;(&lt;BR&gt;SELECT fs.ForumSubscriptionId&lt;BR&gt;FROM InstantForum_ForumSubscriptions fs&lt;BR&gt;LEFT OUTER JOIN &lt;BR&gt;(&lt;BR&gt;SELECT fs.ForumId, fs.UserId, fr.ForumRoleId&lt;BR&gt;FROM InstantForum_ForumSubscriptions fs&lt;BR&gt;JOIN InstantASP_UsersRoles ur ON fs.UserId=ur.UserId&lt;BR&gt;LEFT OUTER JOIN InstantForum_ForumsRoles fr ON fs.ForumId=fr.ForumId AND ur.RoleId=fr.RoleId&lt;BR&gt;WHERE fr.ForumRoleId is NOT NULL&lt;BR&gt;) &lt;BR&gt;fj ON fj.ForumId=fs.ForumId AND fj.UserId=fs.UserId&lt;BR&gt;WHERE fj.ForumId IS NULL&lt;BR&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR&gt;&lt;FONT style="BACKGROUND-COLOR: #dd99dd" face="Courier New"&gt;GO&lt;BR&gt;SET QUOTED_IDENTIFIER OFF &lt;BR&gt;GO&lt;BR&gt;SET ANSI_NULLS ON &lt;BR&gt;GO&lt;/FONT&gt;&lt;BR&gt;&lt;/P&gt;&lt;P&gt;&lt;BR&gt;&lt;FONT style="BACKGROUND-COLOR: #dd99dd" face="Courier New"&gt;CREATE TRIGGER tg_MITS_UpdateForumSubscriptions2&lt;BR&gt;ON InstantForum_ForumsRoles&lt;BR&gt;for DELETE,INSERT,UPDATE&lt;BR&gt;AS&lt;BR&gt; EXEC sp_MITS_UpdateForumSubscriptions&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT style="BACKGROUND-COLOR: #dd99dd" face="Courier New"&gt;go&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR&gt;&lt;FONT style="BACKGROUND-COLOR: #dd99dd" face="Courier New"&gt;CREATE TRIGGER tg_MITS_UpdateForumSubscriptions&lt;BR&gt;ON InstantASP_UsersRoles&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT style="BACKGROUND-COLOR: #dd99dd" face="Courier New"&gt;for DELETE,INSERT,UPDATE&lt;BR&gt;AS&lt;BR&gt; EXEC sp_MITS_UpdateForumSubscriptions&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT style="BACKGROUND-COLOR: #dd99dd" face="Courier New"&gt;go&lt;/FONT&gt;</description><pubDate>Sun, 18 Sep 2005 16:51:43 GMT</pubDate><dc:creator>jon.vickers</dc:creator></item></channel></rss>