ich zwei Tabellen Meister haben - Detail und versuchen, mehr relevantes Ergebnis in Eingabeparameter zu finden basiertFinden der speziellsten Rekord - SQL
Create Table #Master(MasterId int, Method varchar(100))
Insert Into #Master Values(1,'MasterDefault')
Create Table #Detail(Id int, MasterId int,ATypeId int, BTypeId int,CTypeId int,DetailMethod varchar(100))
Insert Into #Detail
Values(1,1,1,1,1,'Detail All'),
(2,1,null,1,1,'Detail ATypeId null'),
(3,1,null,null,1,'Detail ATypeId and Btype null'),
(4,1,null,null,null,'Detail all null')
etwas Schritte wie unten (Was will ich die Methode finden, nur ist, entweder vom Master oder Detail)
declare @Id int =1,
@AtypeId int =1,
@BtypeId int=1,
@CtypeId int =1
Select *
from #Master M
left outer join #Detail D on M.MasterId = D.MasterId
Where M.MasterId = @Id
AND (([email protected]) OR (D.ATypeId IS NULL))
AND (([email protected]) OR (D.BTypeId IS NULL))
AND (([email protected]) OR (D.CTypeId IS NULL))
In diesem Fall möchte die Details zurückzukehren - Id 1 Datensätze wie alle Eingangsanpassung mit Detail row1
Id die Parameter wie unten
declare @Id int =1,
@AtypeId int =null,
@BtypeId int=1,
@CtypeId int =1
Würde die Zeile aus Detail mit Id 2
Jede Hilfe erwarten, dass diese