I have a procedure that takes, among other things, start and end date parameters. These two parameters are optional inputs and default to NULL. What I would like to do is modify one of the current
SELECT statements so that if the start and end dates are supplied it will return only the results between those two dates. I considered just throwing a
CASE WHEN... in the
WHERE statement but that that is messy and does not seem right. Is that the appropriate way to deal with this or is there something more efficient?
SELECT do.OrdrNmbr AS 'Order Number', mb.BOLNmbr AS 'BOL Number', do.DlvryDt AS 'Deliver Date', mh.Text3 AS 'Truck', do.DlvrdQntty AS 'Gallons Delivered', ba.BANme AS 'Carier Business Associate' FROM dbo.DeliveryOrder AS do WITH (NOLOCK) INNER JOIN dbo.ManifestBOL AS mb WITH (NOLOCK) ON do.OrdrNmbr = mb.OrdrNmbr INNER JOIN dbo.BusinessAssociate AS ba WITH (NOLOCK) ON do.CrrrBAID = ba.BAID INNER JOIN SRA.dbo.MovementDocument as md WITH (NOLOCK) ON md.MvtDcmntExtrnlDcmntNbr = 'DOD' + CONVERT(VARCHAR, mb.OrdrNmbr) INNER JOIN SRA.dbo.MovementHeader AS mh WITH (NOLOCK) ON mh.MvtHdrMvtDcmntID = md.MvtDcmntID WHERE mb.OrdrNmbr = @OrderNumber;
and the start/end dates would run against
P.S. I know the table/column names are horrid but this is a 3rd party application the query is running against.