To keep this simple i'm going to include an example however there are actually several scripts that i need to do this to.
I have a manual process where i have, say, 30 scripts. Each one is dropping and creating all sorts of different sql objects. functions, tables, indexes, etc.
I want to be able to execute these scripts as a chunk. Like wrap each script in a stored proc. My problem is i need the "GO" in each to separate the if exists drop and create. Is there another way for me to wrap these scripts so i can make one call and the scripts runs?
Please advise if u have any questions. For some reason i dont feel i'm explaining it very well.
For example. Is there something i can wrap the below in so i make one call?
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[udf_GetCleanUsername]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[udf_GetCleanUsername]
CREATE FUNCTION [dbo].[udf_GetCleanUsername] (@Data VarChar(50))
Declare @Temp VarChar(50)
Declare @i Integer
Declare @Output VarChar(50)
Set @i = 1
Set @Output = ''
While @i <= Len(@Data)
Set @Temp = SubString(@Data, @i, 1)
If @Temp IN ('0','1','2','3','4','5','6','7','8','9') OR
@Temp IN ('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z')
Set @Output = @Output + @Temp
Set @i = @i + 1
Return (Select @Output)