SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Can I add parameters to a location?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

SergioM
Yak Posting Veteran

68 Posts

Posted - 06/12/2012 :  10:32:17  Show Profile  Reply with Quote
I have to reproduce the following code about 10 times. Where 'Distributor_001' should be a variable. Is this possible? I am able to use the variable as a column name, but not as a part of the table structure.

DELETE FROM [MyDB].[inbound].[Distributor_001]
WHERE [UPC] IN
    (
    SELECT UPC
    FROM [MyDB].[inbound].[Distributor_001]
    GROUP BY UPC
    HAVING COUNT(UPC) > 1
    )


Bustaz Kool
Flowing Fount of Yak Knowledge

USA
1429 Posts

Posted - 06/12/2012 :  10:40:43  Show Profile  Reply with Quote
You need to use dynamic SQL, if you want to do this on the fly. Another approach would be to write a code generator that reproduces your code pattern for the list of tables you want to delete from.

=================================================
There is a foolish corner in the brain of the wisest man. -Aristotle, philosopher (384-322 BCE)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000