SimonPrice33
asked on
vb.net dynamic SQL String
Hi Experts,
I am trying to see if there is a way where I can complete this search via my VB.Net application, or SQL Server without having multiple if functions
The application has a selection criteria, however it is not compulsory that every item is filled out depending on the search they want to complete.
the SQL that would complete this is
What I am trying to avoid is multiple if statements \ conditions for every possibility of the search
thanks
Simon
I am trying to see if there is a way where I can complete this search via my VB.Net application, or SQL Server without having multiple if functions
The application has a selection criteria, however it is not compulsory that every item is filled out depending on the search they want to complete.
the SQL that would complete this is
select w.WorkOrderNumber, w.WorkOrderType, r.result,
d.DeptDescription, u.UserID, w.DatetobeStarted, w.DatetobeFinished
from WorkOrders.WorkOrders w
left join Risks.RAM r on r.RiskID = w.RiskID
left join WorkOrders.Dept d on d.DeptID = w.DeptID
left join Users.Users u on w.Assignedto = u.UserIDNumber
where
(u.UserIDNumber is null or (UserIDNUmber = 1003))
and (d.DeptID is null or(d.DeptID = 1))
and (w.FaultID is null or (w.FaultID = 4))
and (r.Result is null or (r.Result = 2))
and (w.Status is null or (w.Status = 9))
and (w.DatetobeStarted is null or (w.DatetobeStarted = '2014-03-04'))
and (w.DatetobeFinished is null or (w.DatetobeFinished = '2014-03-04'))
What I am trying to avoid is multiple if statements \ conditions for every possibility of the search
thanks
Simon
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
lots of conditions to write for me then...
thank you