mikev1976 Posted February 17, 2012 Share Posted February 17, 2012 Attached is pick of my two tables. I can delete what I want manually by sending: delete from Outreach_HealthAdvisor.IdentifiedRiskFactors where CallAppointmentId = '9DE2B3B8-7957-460F-8446-9FFA00EE4BF1'delete from Outreach_Core.CallAppointments where CallAppointmentId = '9DE2B3B8-7957-460F-8446-9FFA00EE4BF1' I am having to do this alot but the CallAppointmentId is always changing. So I wanted to make it a little easier on my self. The CalleeId stays the same. So I tried: declare @test table (userid uniqueidentifier)insert into @testselect '5A0D4EBE-569A-4D6B-83BC-9FEB0104BF6F' delete from irffrom Outreach_HealthAdvisor.IdentifiedRiskFactors as irfjoin Outreach_Core.CallAppointments as ca on irf.CallAppointmentId=ca.CallAppointmentIdjoin @test as t on ca.CalleeId=t.useridwhere irf.CallAppointmentId =(select ca.CalleeId from Outreach_Core.CallAppointments where ca.CalleeId=t.userid) I've tried some other variations but I'm not having any luck. Any help would be appreciated.... Link to comment Share on other sites More sharing options...
mikev1976 Posted February 20, 2012 Author Share Posted February 20, 2012 Hmmm...lots of views but no help? Figured this would be an easy one for the gurus of SQL. But I figured out one approach. When creating my temporary table I inserted the appointment id: declare @test table (userid uniqueidentifier, appoinmentid uniqueidentifier)insert into @testselect '5A0D4EBE-569A-4D6B-83BC-9FEB0104BF6F', (select CallAppointmentId from Outreach_Core.CallAppointments cajoin Member.Users u on u.UserId=ca.CalleeIdwhere CalleeId='5A0D4EBE-569A-4D6B-83BC-9FEB0104BF6F') Then joined the temp table to the table I needed info deleted from and filtered accordingly: delete from irffrom Outreach_HealthAdvisor.IdentifiedRiskFactors as irfjoin @test t on irf.CallAppointmentId=t.appoinmentidwhere irf.CallAppointmentId = t.appoinmentid delete from cafrom Outreach_Core.CallAppointments as cajoin @test t on ca.CallAppointmentId=t.appoinmentidwhere ca.CallAppointmentId=t.appoinmentid Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.