Can someone help me in writing this query. Doing some silly mistake but not able to recognize.
for testing purpose commented actual delete clause
if DB_name () = N'MyDB'
begin
IF( EXISTS( SELECT 1 FROM sch1.table1 WHERE guid= N'05172A47' and IntId=12 ))
print 'im deleting 1';
--DELETE FROM sch1.table1 where Guid = N'05172A47' and IntId=12
print 'im deleting 2';
IF( EXISTS( SELECT 1 FROM sch1.table1 WHERE Guid = N'3DFB856F' and IntId=13 ))
--DELETE FROM sch1.table1 where Guid = N'3DFB856F' and IntId=13
end
ELSE PRINT 'Nothing deleted'
end
Not sure if your GUID column is actually a uniqueidentifier or not, but if so I don't think either of your strings are valid. Also, I don't see where you stated what the actual problem/error is.
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service