I want to write a select query where i user have to pass two input ID and SourceID. But here is the twist, Input ID is mandetory and SourceID is Optional. I want to write a select query where if a user passes only Input ID then my select query will filter data based on ID but if user passes both ID and SourceID then user should Get Data based on Both Filters. I am pretty much new to database query so i am not able to figure out how to do this?
My request body:
<body>
<p:GetEntryByID xmlns:p="http://abcFarm.org/">
<!--Exactly 1 occurrence-->
<xs:ExistingID xmlns:xs="http://abcFarm.org/">?</xs:ExistingID>
<!--0 to 1 occurrence-->
<xs:TargetSourceID xmlns:xs="http://abcFarm.org/">?</xs:TargetSourceID>
</p:GetEntryByID >
</body>
I have written a sql query which is not working as:
select * from entry WHERE ID='ID1' AND (e.SourceID='SourceID1' Or ID='ID1');
But this is not fulfilling my above need. Please Help.Thanks in advance.