DECLARE @SenderID decimal(18,0)
DECLARE @MessageDateTime datetime
DECLARE @MessageBudy nvarchar(250)
DECLARE @GroupID decimal(18,0)

SET @SenderID = 1
SET @MessageDateTime = (SELECT GETDATE())
SET @MessageBudy = ' Hello My Group Is Very Good . . .  '
SET @GroupID = 12

IF EXISTS(SELECT [GroupMemberID] FROM [tblGroupMembers] WHERE [UserID] = @SenderID   AND [GroupID] = @GroupID)
	BEGIN
		INSERT INTO [tblMessageToGroups]
				   ([SenderID]
				   ,[MessageDateTime]
				   ,[MessageBudy]
				   ,[GroupID])
			 VALUES
				   (@SenderID
				   ,@MessageDateTime
				   ,@MessageBudy
				   ,@GroupID)
	END
ELSE
	BEGIN
		PRINT 'User has Not Access To This Group . . .'
	END           
GO
