čtvrtek 24. listopadu 2016

ChangeScript - Přidání procedury pokud neexistuje

If  exists(SELECT * FROM sys.procedures WHERE name = N'Cpy_Search')
begin
 DROP PROCEDURE [dbo].[Cpy_Search]
end;
BEGIN
 exec('CREATE Procedure Cpy_Search
                 @CompanyId as int,
                 @Term as nvarchar(60)
                AS begin
                 DECLARE @Pattern nvarchar(62)
                 SELECT @Pattern = ''%'' + @Term + ''%'';
                     SELECT
                  Id,
                  Title
                 FROM [Company]
                 WHERE
             AgendaId = @CompanyId
                 AND (
                  Title COLLATE Latin1_general_CI_AI Like @Pattern  COLLATE Latin1_general_CI_AI
                  OR
                  IdentificationNumber LIKE @Pattern
                  OR
                  VatIdentificationNumber LIKE @Pattern
                 )
                END;')
           END;



Zdroj:
http://stackoverflow.com/questions/2072086/how-to-check-if-a-stored-procedure-exists-before-creating-it

Žádné komentáře:

Okomentovat