Add Table Name And Database Name in Store Procedure
alter PROCEDURE usp_removeDuplicateHotelMapping_test
(@tablename varchar(200), @databasename AS NVARCHAR(128)='')
as
DECLARE @execquery AS NVARCHAR(MAX)
SET @execquery = N'UPDATE ' + @databasename + '.[dbo].' + @tablename + ' SET mappedto=b.ID FROM ' + @databasename + '.[dbo].' + @tablename + ' A ' + 'INNER JOIN (SELECT MIN(ID) AS ID,mappedto FROM ' + @databasename + '.[dbo].' + @tablename + ' GROUP BY mappedto) B ON A.mappedto=B.mappedto where a.mappedto>a.id'
EXECUTE sp_executesql @execquery
go
usp_removeDuplicateHotelMapping_test 'tab_CitySampleMappings201507182'
go
or
usp_removeDuplicateHotelMapping_test 'tab_CitySampleMappings201507182',’’
go
Thank you for reading the article about Add Table Name And Database Name in Store Procedure on the blog NEW TECH If you want to disseminate this article on please list the link as the source, and if this article was helpful please bookmark this page in your web browser by pressing Ctrl + D on your keyboard keys.