I have a little problem in my query. My database at my local development server is running with French date format (dd/mm/yyyy) but my release server is on North American format (mm/dd/yyyy).
So this throws an error
SELECT CodPeriodoInsc,
CONVERT(VARCHAR, FechaDesde, 103) AS FechaDesde,
CONVERT(VARCHAR, FechaHasta, 103) AS FechaHasta
FROM SedesPeriodosInscripcion
WHERE FechaDesde <= '25/06/2012'
But it works on development, and this works on release
SELECT CodPeriodoInsc,
CONVERT(VARCHAR, FechaDesde, 103) AS FechaDesde,
CONVERT(VARCHAR, FechaHasta, 103) AS FechaHasta
FROM SedesPeriodosInscripcion
WHERE FechaDesde <= '06/25/2012'
But it doesn’t work on development.
Is there a way I can make the query work on both databases?
You can pick a format and use SET DATEFORMAT
But you could always just pick a canonical format for your date literals like: yyyyMMdd, which in your case would be ‘20120625’ These are never ambiguous (not even for humans).
or use an ISO format or use DATETIMEFROMPARTS to construct a date if you are using SQL Server 2012.