Although this question has already been answered, I want to make my contribution.
Sometimes queries with dates are usually complicated since it depends on the language, to avoid this type of inconvenience it is advisable to use a standard format in the query, I recommend using the format YYYYMMDD that is achieved using a convert in this way :
select convert(nvarchar, getdate(), 112)
Your query would look like this:
SELECT *
FROM PR_11
WHERE convert(nvarchar, FECHA_DESDE, 112) > '20140728' AND CODIGO='4891'
Now, it seems tedious to convert the dates to YYYYMMDD format but the savings in headaches is important, I have been using this method for more than 12 years and I must say that I have never had any problems due to the regional configuration.
Another example assuming that I have a stored procedure that receives a datetime or smalldatetime, it would have to be converted to the format before said.
CREATE PROCEDURE usp_devuelve_listado_fecha_mayor
@fecha datetime,
@codigo int
as
SELECT *
FROM PR_11
WHERE convert(nvarchar, FECHA_DESDE, 112) > convert(nvarchar, @fecha, 112)
AND CODIGO = @codigo
A last option is to convert the date to the YYYYMMDD format from the application and send the string to the stored procedure.
CREATE PROCEDURE usp_devuelve_listado_fecha_mayor
@fecha nvarchar(8),
@codigo int
as
SELECT *
FROM PR_11
WHERE convert(nvarchar, FECHA_DESDE, 112) > @fecha
AND CODIGO = @codigo
I hope it can be useful as it served me for so long.
PS: For the sake of simplicity we used Select *
PLEASE in real queries only use the necessary fields.
Greetings.