How can I use AND condition in IF EXISTS in SQL?
Posted
by
user811433
on Stack Overflow
See other posts from Stack Overflow
or by user811433
Published on 2013-07-01T23:00:34Z
Indexed on
2013/07/01
23:05 UTC
Read the original article
Hit count: 402
IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'X' AND COLUMN_NAME = 'Y')
IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Z' AND COLUMN_NAME = 'A')
BEGIN
UPDATE [dbo].[X]
SET Y= (SELECT inst.[A] FROM [dbo].[Z] s WHERE s.[B] = [dbo].[x].[B]);
END
GO
I want to combine the 2 IF confitions and perform the update only when both of them are satisfied. Is there some way in which I can club 2 IF EXISTS?
© Stack Overflow or respective owner