Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Checking If A Proc Exists
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01245040
Message ID:
01245324
Vues:
19
I put togethere a simpl sp_DropProc routine. I'd like your thoughts, if you please.
It worked fine for both of these:
EXEC sp_DropProc 'fn_EncryptDecryptString'
EXEC sp_DropProc 'sp_AddSCUser'
USE SC
GO
--DROP PROC sp_DropProc

CREATE PROCEDURE sp_DropProc
	@SProcName nvarchar(100)

AS

  DECLARE @XType char(2)
  SET @XType = ''

  SELECT @XType = XType
    FROM dbo.sysobjects 
    WHERE Name = @SProcName
	
  IF @XType = 'FN'
    BEGIN	
      EXEC('DROP FUNCTION ' + @SProcName)
    END

  IF @XType = 'P'
    BEGIN	
      EXEC('DROP PROCEDURE ' + @SProcName)
    END

GO
>The 'DROP PROCEDURE statement dosen't support local variables in place of procedure name. You'll have to use dynamic SQL.
>EXEC('DROP PROCEDURE ' + @SProcName)
>
>
>>Getting an error:
>>
>>
>>CREATE PROCEDURE sp_ProcExists
>>	@SProcName nvarchar(100
>>AS
>>
>>  IF EXISTS (SELECT *
>>               FROM dbo.sysobjects
>>	       WHERE id = object_id(@SProcName) AND
>>	       OBJECTPROPERTY(id, N'IsProcedure') = 1)
>>
>>     DROP PROCEDURE @SProcName                 <=========== Errors here
>>
>>
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform