none
Fechas Sql

    Question

  • Hola, estoy haciendo una consulta por FECHA ej en mi BD(2010-06-01 16:40:00.000) pero cuando hago por ejemplo

    select * from Pagos where Fecha = '2010-06-01 16:40:00.000'

    y no me trae nada, intente de todas la maneras que se me ocurrieron, fui leyendo en foros y no encontre nada que me reconosca la fecha, tambien con '20100601' ,  de otras formas.

    agradeceria a alguien me pueda ayudar.

    Thursday, September 02, 2010 5:10 AM

Answers

All replies

  • The language of this forum is English.
    Kalman Toth, SQL Server & Business Intelligence Training; SQL 2008 GRAND SLAM
    Thursday, September 02, 2010 5:18 AM
  • select * from Pagos where CONVERT(VARCHAR,Fecha,112)= '20100601'

     

    http://www.sqlusa.com/bestpractices2005/centurydateformat/

    http://www.codeproject.com/KB/showcase/RedGate_DateTime.aspx?msg=1930056

    Thursday, September 02, 2010 5:19 AM
  • select * from Pagos where CONVERT(VARCHAR,Fecha,112)= '20100601'

     

    http://www.sqlusa.com/bestpractices2005/centurydateformat/

    http://www.codeproject.com/KB/showcase/RedGate_DateTime.aspx?msg=1930056


    thx but i dont like for my real proyect, necesito pasarle de parametro una datetime igual de como lo guarda, porque cuando hago la consulta le vuelvo a pasar del mismo tipo 2010-06-01:

    ALTER

     

    PROCEDURE [dbo].[PagosSelectPorFecha] (

     

    @CodigoAdm int,

     

    @FechaDesde Datetime,

     

    @FechaHasta Datetime

    )

    AS

    SET

     

    NOCOUNT ON

    DECLARE

     

    @DBID INT, @DBNAME NVARCHAR(128);

    SET

     

    @DBID = DB_ID();

    SET

     

    @DBNAME = DB_NAME();

    SELECT

     

    [Pagos].Codigo,

     

    [Monto],

     

    [Nota],

     

    Pagos.[Tipo],

     

    [Fecha],

     

    [CodigoBoleta],

     

    [NroComprobante]

    FROM

     

    [Pagos] inner join Boletas on Pagos.CodigoBoleta = Boletas.Codigo inner join

     

    Consorcio on Consorcio.Codigo = Boletas.Consorcio inner join Administrador on Administrador.Codigo = Consorcio.CodigoAdministrador

    WHERE

     

     

    Administrador.Codigo = @CodigoAdm and @FechaDesde >= CONVERT(VARCHAR,Pagos.Fecha,112) and @FechaHasta <= CONVERT(VARCHAR,Pagos.Fecha,112)

    Thursday, September 02, 2010 5:41 AM
  •  

    @FechaDesde >= CONVERT(VARCHAR,Pagos.Fecha,112) and @FechaHasta <= CONVERT(VARCHAR,Pagos.Fecha,112)


    What is this condition how come a value will satisifeid both "greater than or equal to" or "less than or equal to" ? r u basically checking for equals condition?

    That means u need the records on that date?? then change the above condition like this for better indexes usage.

    Pagos.Fetcha >= @FechaDesde and Pagos.Fetcha < @FechaDesde + 1
    

     

     

    Thursday, September 02, 2010 6:03 AM
  • For more information about Date/Times please see this link

    http://www.karaszi.com/SQLServer/info_datetime.asp

     

    IMO it is required reading


    Dave Ballantyne ---- http://sqlblogcasts.com/blogs/sqlandthelike/
    Thursday, September 02, 2010 7:36 AM
  • I did not understand what you saud but the only safe datetime format is YYYYMMDD


    Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/
    Thursday, September 02, 2010 7:40 AM
  • I did not understand what you saud but the only safe datetime format is YYYYMMDD


    Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/
    Thursday, September 02, 2010 7:40 AM