Sorry for might be a foolish question from a self-taught rookie. I have a complex SP I'm trying to improve. By necessity in the criteria there are date criteria plus string functions to break apart a text field (12345-123 representing customer-company) into its component parts so each can be tested. I'm wondering whether placing the date criteria first would prevent the string functions being applied to the entire table. The FROM clause looks like:
WHERE SalesHeader.DOCDATE Between @FmDate And @ToDate AND
RIGHT(RTrim(SalesHeader.CUSTNMBR), 3) = @CoCode AND
Left(SalesHeader.CUSTNMBR, len(SalesHeader.CUSTNMBR)-4) BETWEEN @FmCust AND @ToCust
If this is not the case, then I'll probably move the initial SELECT statements and the string functions to create numeric fields to a view, and then just query the view from the stored procedure. If it matters, there are 4 separate SELECT statements with UNION ALL to bring the data together.
Thanks in advance for any thoughts,