SQL
USE [PrintMonitor]
GO
/****** Object:  StoredProcedure [dbo].[Set_Printer_Monitoring_State]    Script Date: 10/15/2008 21:26:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Set_Printer_Monitoring_State]
	(
		@ServerName varchar(255),
		@PrinterName varchar(220),
		@Monitored bit = 1
	)

AS
	SET NOCOUNT ON
	
	-- Add server if not already there
	IF NOT EXISTS (SELECT 'A' FROM dbo.[Print Servers]
	                WHERE Name = @ServerName)
	          INSERT INTO dbo.[Print Servers]
	              (
	              Name,
	              License
	              )
	          VALUES
	              (
	              @ServerName,
	              NewId()
	              )
	              
   -- Add printer if not already there 
   IF NOT EXISTS (SELECT 'A' FROM dbo.Printers
                   WHERE Name = @PrinterName
                     AND [Server Name] = @ServerName)
                     
           BEGIN
              DECLARE @NextPrinter AS INT
              
              SELECT @NextPrinter = 1 + IsNull(Max(Id),0)
                 FROM dbo.Printers
                 
              INSERT INTO dbo.Printers
                (
                Id,
                Name,
                [Server Name]
                )
              VALUES
                (
                @NextPrinter,
                @PrinterName,
                @ServerName
                )
           END	              
	
	UPDATE dbo.Printers
	  SET Monitor = @Monitored
	 WHERE [Server Name] = @ServerName
	   AND Name = @PrinterName
	   
	RETURN 

Last edited Oct 15, 2008 at 9:26 PM by Merrion, version 1

Comments

No comments yet.