1

Estoy usando SQL Server 2008 R2, estoy haciendo una consulta de selección SELECT que es la siguiente:

SELECT SalesOrderID
    , ShipDate
FROM Sales.SalesOrderHeader
WHERE ShipDate BETWEEN '7/28/2011 00:00:00' AND '7/29/2011 23:59:59'

Me da el siguiente error

Comenzó a ejecutar la consulta en la línea 125 Msg 242, Level 16, State 3, Line 1 La conversión del tipo de datos varchar en datetime produjo un valor fuera de intervalo. Tiempo total de ejecución: 00:00:00.011

Para solucionarlo hice lo siguiente:

SELECT SalesOrderID
        , ShipDate
FROM Sales.SalesOrderHeader
WHERE ShipDate BETWEEN CONVERT(VARCHAR, '7/28/2011 00:00:00', 22) 
AND CONVERT(VARCHAR, '7/29/2011 23:59:59', 22)

Select a la tabla

   SalesOrderID,RevisionNumber,OrderDate,DueDate,ShipDate,Status,OnlineOrderFlag,SalesOrderNumber,PurchaseOrderNumber,AccountNumber,CustomerID,SalesPersonID,TerritoryID,BillToAddressID,ShipToAddressID,ShipMethodID,CreditCardID,CreditCardApprovalCode,CurrencyRateID,SubTotal,TaxAmt,Freight,TotalDue,Comment,rowguid,ModifiedDate
43659,8,2011-05-31 00:00:00.000,2011-06-12 00:00:00.000,2011-06-07 00:00:00.000,5,0,SO43659,PO522145787,10-4020-000676,29825,279,5,985,985,5,16281,105041Vi84182,NULL,20565.6206,1971.5149,616.0984,23153.2339,NULL,79b65321-39ca-4115-9cba-8fe0903e12e6,2011-06-07 00:00:00.000
43660,8,2011-05-31 00:00:00.000,2011-06-12 00:00:00.000,2011-06-07 00:00:00.000,5,0,SO43660,PO18850127500,10-4020-000117,29672,279,5,921,921,5,5618,115213Vi29411,NULL,1294.2529,124.2483,38.8276,1457.3288,NULL,738dc42d-d03b-48a1-9822-f95a67ea7389,2011-06-07 00:00:00.000
43661,8,2011-05-31 00:00:00.000,2011-06-12 00:00:00.000,2011-06-07 00:00:00.000,5,0,SO43661,PO18473189620,10-4020-000442,29734,282,6,517,517,5,1346,85274Vi6854,4,32726.4786,3153.7696,985.5530,36865.8012,NULL,d91b9131-18a4-4a11-bc3a-90b6f53e9d74,2011-06-07 00:00:00.000
43662,8,2011-05-31 00:00:00.000,2011-06-12 00:00:00.000,2011-06-07 00:00:00.000,5,0,SO43662,PO18444174044,10-4020-000227,29994,282,6,482,482,5,10456,125295Vi53935,4,28832.5289,2775.1646,867.2389,32474.9324,NULL,4a1ecfc0-cc3a-4740-b028-1c50bb48711c,2011-06-07 00:00:00.000
43663,8,2011-05-31 00:00:00.000,2011-06-12 00:00:00.000,2011-06-07 00:00:00.000,5,0,SO43663,PO18009186470,10-4020-000510,29565,276,4,1073,1073,5,4322,45303Vi22691,NULL,419.4589,40.2681,12.5838,472.3108,NULL,9b1e7a40-6ae0-4ad3-811c-a64951857c4b,2011-06-07 00:00:00.000
43664,8,2011-05-31 00:00:00.000,2011-06-12 00:00:00.000,2011-06-07 00:00:00.000,5,0,SO43664,PO16617121983,10-4020-000397,29898,280,1,876,876,5,806,95555Vi4081,NULL,24432.6088,2344.9921,732.8100,27510.4109,NULL,22a8a5da-8c22-42ad-9241-839489b6ef0d,2011-06-07 00:00:00.000
43665,8,2011-05-31 00:00:00.000,2011-06-12 00:00:00.000,2011-06-07 00:00:00.000,5,0,SO43665,PO16588191572,10-4020-000146,29580,283,1,849,849,5,15232,35568Vi78804,NULL,14352.7713,1375.9427,429.9821,16158.6961,NULL,5602c304-853c-43d7-9e79-76e320d476cf,2011-06-07 00:00:00.000
43666,8,2011-05-31 00:00:00.000,2011-06-12 00:00:00.000,2011-06-07 00:00:00.000,5,0,SO43666,PO16008173883,10-4020-000511,30052,276,4,1074,1074,5,13349,105623Vi69217,NULL,5056.4896,486.3747,151.9921,5694.8564,NULL,e2a90057-1366-4487-8a7e-8085845ff770,2011-06-07 00:00:00.000
43667,8,2011-05-31 00:00:00.000,2011-06-12 00:00:00.000,2011-06-07 00:00:00.000,5,0,SO43667,PO15428132599,10-4020-000646,29974,277,3,629,629,5,10370,55680Vi53503,NULL,6107.0820,586.1203,183.1626,6876.3649,NULL,86d5237d-432d-4b21-8abc-671942f5789d,2011-06-07 00:00:00.000

Pero sigue saliendo el mismo error, ¿Cómo lo puedo solucionar?

5
  • 1
    ¿qué tipo de dato es ShipDate?
    – jachguate
    Commented el 13 jun. 2021 a las 0:57
  • Intenta cambiar las barras inclinadas por guiones y nos cuentas: '7-28-2011 00:00:00'
    – Arriel
    Commented el 13 jun. 2021 a las 3:49
  • Te invito a leer la respuesta a un problema parecido:es.stackoverflow.com/questions/117586/… Commented el 13 jun. 2021 a las 4:05
  • @jachguate DateTime Commented el 13 jun. 2021 a las 4:58
  • @Arriel Sale el mismo error SELECT SalesOrderID , ShipDate FROM Sales.SalesOrderHeader WHERE ShipDate BETWEEN '7-28-2011 00:00:00' AND '7-29-2011 23:59:59' Commented el 13 jun. 2021 a las 5:10

1 respuesta 1

2

Lo solucione de la siguiente manera yyyymmdd

    SELECT SalesOrderID
    , ShipDate
FROM Sales.SalesOrderHeader
WHERE ShipDate BETWEEN '20110728 00:00:00' AND '20110729 23:59:59'
1
  • Funcionó perfectamente esta solución!
    – Salvatiti
    Commented el 17 may. 2022 a las 9:33

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.