You must Sign In to post a response.
  • Category: SQL Server

    Getting date range data

    I have a column TransationDate is decimal data type the data's like 20170121 I want to display data's in date range, The database columns data like 20170121 ..............20170129. I want to display data's these date range based on given strartdate,enddate as criteria. In my query it is displayed only one record. what's wrong my query could any body advise to me.

    declare @StartDate varchar(10)
    declare @EndDate varchar(10)
    set @StartDate ='20170121'
    set @EndDate ='20170129'

    SELECT *
    FROM LCOM.dbo.PORCPAH PORCPAH
    WHERE CONVERT(DATETIME, CONVERT(VARCHAR(8), PORCPAH.TRANSDATE), 112) >= @StartDate
    AND CONVERT(DATETIME, CONVERT(VARCHAR(8), PORCPAH.TRANSDATE), 112) <= @EndDate
  • #769602
    Can you get us the table definition and insert script for the data in that table. We can figure out why it is returning only one row as result.
    Please mark this as Answer, if this helps

    Regards,
    Alwyn Duraisingh.M 
    << Database Administrator >>
    Jesus saves! The rest of us better make backups...


  • Sign In to post your comments