views:

51

answers:

1

I'm trying to use this query to delete the rows that are already on a linked server's Database:

GO
USE TAMSTest
GO
DELETE from [dbo].[Hour]
 WHERE [dbo].[Hour].[InHour] = (SELECT [InHour] 
                                  FROM [TDG-MBL-005].[TAMSTEST].[dbo].[Hour])
GO

When there is only 1 row in the linked server's table, SELECT [InHour] FROM [TDG-MBL-005].[TAMSTEST].[dbo].[Hour] returns that single row and the DELETE works as expected. However, with multiple rows in the linked sever's table, it doesn't work since that part of the query returns mutiple rows as its result. How can I work around this?

If there is further information needed please ask, I need to get this done ASAP.

Thanks in advance, Eton B.

+7  A: 

Change your equal sign to an IN statement

DELETE from [dbo].[Hour]
 WHERE [dbo].[Hour].[InHour] IN (SELECT [InHour] 
    FROM [TDG-MBL-005].[TAMSTEST].[dbo].[Hour])

The IN clause allows you to have multiple values in your WHERE clause, and can be used in subqueries as well. Here's more information.

LittleBobbyTables
Heh! That was quite an easy one.. now I feel like much more of a newbie. Thanks!
Eton B.
Glad I could help
LittleBobbyTables