thank you for your help. So if I'm understanding you correctly, all the scripts that are doing some altering of tables or data need to be change to dynamic sql?
CREATE PROCEDURE dbo.UpdateProcedure
@guid VARCHAR(50)
AS
BEGIN
DECLARE @ClientSchema TABLE (client VARCHAR(50),clientSchema VARCHAR(50))
INSERT INTO @ClientSchema(client,clientSchema)
SELECT client,clientSchema from clientSchemaTable
DECLARE @client varchar(50)
DECLARE @clientSchema VARCHAR(50)
DECLARE @sql NVARCHAR(MAX)
SELECT TOP 1 @client = client, @clientSchema = clientSchema FROM clientSchemaTable
WHILE @clientSchema IS NOT NULL
BEGIN
SET @sql = '
UPDATE [' + @clientSchema + '].DealCustomMetaData SET DefaultLabel=''Employees'' WHERE FieldName=''SR_Employees''
UPDATE [' + @clientSchema +'].DealCustomMetaData SET DefaultLabel=''Locations'' WHERE FieldName=''SR_Locations''
INSERT INTO [' + @clientSchema + '].tblSchemaEvolution (ChangeID) VALUES(''' + @guid + ''')'
exec(@sql)
DELETE FROM @ClientSchema where client = @client and clientSchema = @clientSchema
SET @client = NULL
SET @ClientSchema = NULL
SELECT TOP 1 @client = client, @clientSchema = clientSchema FROM clientSchemaTable
END
END
Put the client and schema information into a temp or in memory table
Loop through the table by taking the first record execute some dynamic sql that takes the values from the record then delete the record it when you are done executing code something like this:
Open in new window