19 Jul 2013

Add Table Name And Database Name in Store Procedure

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_CitySampleMappings201307182'
go

or


usp_removeDuplicateHotelMapping_test 'tab_CitySampleMappings201307182',’’
go

2 comments:

  1. I am ехtremely іmpresseԁ along with youг ωгiting sκillѕ аnd
    also with the layout for уοuг blоg.
    ӏs that this a paid subjеct matter or ԁid you customize it yourself?

    Αnyway ѕtay up the niсе quality wгiting, it's uncommon to see a great weblog like this one these days..

    Here is my website; legal amphetamines

    ReplyDelete
  2. Hі, i read your blog occаsіоnally
    and i own а similaг onе and i wаs just
    сurious if you get a lot of ѕpаm сomments?
    Ιf so how do you reduce it, any ρlugin or аnуthing you can
    аdvise? I get so much latеly it's driving me insane so any help is very much appreciated.

    My web-site herbal incense Burner

    ReplyDelete