--Kullanım:
--[dbo].[Sp_TabloAktar]
@NewDatabaseName='TestDb2',@OldDatabaseName='BORSA',@TableName='Ay'
USE master
GO
/******
Object: StoredProcedure
[dbo].[STPMizanGider] Script Date:
19.09.2018 16:53:59 ******/
SET ANSI_NULLS
ON
GO
SET
QUOTED_IDENTIFIER ON
GO
alter PROCEDURE [dbo].[Sp_TabloAktar]
-- Add the parameters for the stored
procedure here
@NewDatabaseName nvarchar(50),
@OldDatabaseName nvarchar(50),
@TableName nvarchar(50)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @IntVariable int;
DECLARE @SQLString nvarchar(4000);
DECLARE @ParmDefinition nvarchar(500);
/* Build the SQL string one time.*/
SET @SQLString =
N' IF OBJECT_ID(N' + '''$db$.dbo.$tbl$''' +
', N''U'') IS NOT NULL
BEGIN
DROP TABLE $db$.dbo.$tbl$
end
Select * into
$db$.dbo.$tbl$ from $db1$.dbo.$tbl$ ';
SET @SQLString = REPLACE(@SQLString, '$db$',
@NewDatabaseName);
SET @SQLString = REPLACE(@SQLString, '$db1$',
@OldDatabaseName);
SET @SQLString = REPLACE(@SQLString, '$tbl$', @TableName);
/* Execute the string with the first
parameter value. */
PRINT @SQLString
EXECUTE sp_executesql @SQLString;
/* Execute the same string with the
second parameter value. */
END
Hiç yorum yok:
Yorum Gönder