Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Can I add parameters to a location?

Author  Topic 

SergioM
Posting Yak Master

170 Posts

Posted - 2012-06-12 : 10:32:17
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
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2012-06-12 : 10:40:43
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
   

- Advertisement -