I have a stored procedure which receives 10 parameters type Date but I can show the information when the consult have null because a have to show the flow of information of all the clients on this consult. Sometimes the client has orders with creditnotes but on occasions only have an order but not have Credit notes…
I do this for the Where Clause:
WHERE
(Customer.cd_CustomerID = ISNULL(@customer, Customer.cd_CustomerID))
AND (@orderID IS NULL OR Orders.cd_OrderID = @orderID)
AND (@Location IS NULL OR CustomerSL.cd_LocID = @Location)
and (Convert(date,Orders.fh_Date,111) BETWEEN coalesce (@FechaPedido1,'1900-01-01') AND coalesce (@FechaPedido2,'3000-12-31' ))
and (Convert(date,Receipt.fh_Date,111) BETWEEN coalesce (@FechaRemision1,'1900-01-01') AND coalesce (@FechaRemision2,'3000-12-31' ))
and (Convert(date,Invoice.fh_Date,111) BETWEEN coalesce (@FechaFactura1,'1900-01-01') AND coalesce (@FechaFactura2,'3000-12-31' ))
and (Convert(date,CreditNote.fh_Date,111) BETWEEN coalesce (@FechaNotaCredito1,'1900-01-01') AND coalesce (@FechaNotaCredito2,'3000-12-31' ))
and (Convert(date,Dispersion.fc_CreatedDate,111) BETWEEN coalesce (@FechaDispersion1,'1900-01-01') AND coalesce (@FechaDispersion2,'3000-12-31' ))
But in this case, only show the information which has all the flow for the client. The consult doesn’t show me the flow of information who doesn’t have An order without remissions or Dispersion o whatever is the case… already try with IF in Where but I have some problems with the syntax is…
if (@fechapedido1 is null)
begin
(Convert(date,Orders.fh_Date,111) BETWEEN @FechaPedido1 and @FechaPedido2)
end
The SQL server shows me this message ‘Incorrect syntax near the keyword ‘Convert’.’
but that line is correct… :S Please Help Me 😀
thanks
😀
You can’t have
IFstatements in aWHEREclause, try this: