troubleshooting Question

Return All Values if Filter Item is Left Blank

Avatar of melikins
melikinsFlag for United States of America asked on
Microsoft SQL Server
3 Comments1 Solution302 ViewsLast Modified:
I would like to update a Crystal report with the below subselect.  I have added the following line of code 'and WL.scode = '#sCode#'' to the query below.  When a user enters a value for wl.scode (on the report filter), the code works properly.  However, when a user does not enter a value for wl.scode (on the report filter), the report lists nothing (rather than listing ALL wl.scodes that apply).  How do I write the code to include ALL wl.scodes if a users leaves the wl.scode field blank on the report filter?  Please feel free to ask additional questions if I am not explaining myself clearly (I openly admit to being a self-taught SQL novice)!  Thanks in advance for any and all suggestions!  

select CAST(WLG.iBedroomSize as char(1)) + ' Bedroom' as wlglist,
  WL.sDesc            WLsDesc,
  WLGD.hWlApplic      WLGDhWlApplic,
  WLGD.dtApplied      WLGDdtApplied,
  WLGD.iWLPosition      WLGDiWLPosition

from WlGenDet WLGD, WlGen WLG, WlWaitList WL
where WLGD.hGen = WLG.hMy
  and WL.hProperty = #hProp#
  and WL.scode = '#sCode#'
  and WLG.hWaitList  = WL.hMy
  and WLG.bListArchived = 0
Sharath S
Data Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros