August 23, 2011 at 9:22 am
I want to delete data in a table in database 1, but reference a table in database 2
i.e. DELETE TABLEX INNER JOIN DATABASEZ.DBO.TABLE1 ON TBXRefNo = DBZRefNo
WHERE (DBZRefName = 'XYZ')
Is this possible? Will the above code work? So far it hasn't
August 23, 2011 at 9:28 am
That would work once the columns' name are corrected.
DELETE X FROM TABLEX X INNER JOIN DATABASEZ.DBO.TABLE1 T2 ON X.TBXRefNo = T2.DBZRefNo
WHERE (T2.DBZRefName = 'XYZ')
August 23, 2011 at 9:29 am
yup.
or
DELETE TABLEX
WHERE TBXRefNo IN (SELECT DBZRefNo
FROM DATABASEZ.DBO.TABLE1
WHERE DBZRefName = 'XYZ')
August 24, 2011 at 7:46 am
Actually I got it to work as follows:
DELETE FROM TABLEX
FROM TABLEX INNER JOIN DATABASEZ.DBO.TABLE1 ON TBXRefNo = DBZRefNo
WHERE (DBZRefName = 'XYZ')
Once I added the FROM TABLEX it worked beautifully.
Thanks for your help
August 25, 2011 at 11:48 am
Hi,
You need not use FROM TABLEX twice which is redundant and also makes the query unclear.
Whatever Ninja suggested works well.
Regards,
Durga
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply