Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2006
    Posts
    87

    Unanswered: problem getting results with dates

    Hi everybody.. couldn't get this query right... I have two tables with the first listing all the employees (tblemp). the second table is the travel dates of employees (tblviaggi) they are joined with tblemp,tblempID=tblviaggi.tblempIDFK
    I just want to get all the employees who are out tommorow...comparing it with the startdate and enddate.. my query below just get's me 2 results while the truth is it is more...


    DECLARE @TODAY DATETIME
    DECLARE @TOMMOROW DATETIME
    DECLARE @TOMMOROWFINAL DATETIME

    SET @TODAY=GETDATE()
    SET @TOMMOROW=DateAdd("d",1,@Today)
    SET @TOMMOROWFINAL=(SELECT CAST(FLOOR(CAST( @TOMMOROW AS float)) AS datetime))

    select * from tblemp e inner join tblviaggi v on e.strempID=v.strempIDFK
    where e.strempID=v.strempIDFK and dtviagSdate >=@tommorowfinal and dtviagEdate <= @tommorowfinal

    thanks

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    A few questions.

    Why start a new thread when this is a continuation of another?
    What is that FLOOR monstrosity?
    Is the end date ever null?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    /*
     Yesterday | Today      | Tomorrow 
               |            |
     A[---]    |            |
           B[--|--]         |
            C[-|------------|-]
               |   D[----]  |
               |        E[--|--]
               |            |    F[---]
               |            |
    
    We are only interested in A and F:
    */
    DECLARE @today    datetime
          , @tomorrow datetime
    
    SELECT @today = DateAdd(dd, DateDiff(dd, 0, GetDate()), 0)
         , @tomorrow = DateAdd(dd, 1, @tooday)
    
    SELECT *
    FROM   tblemp As e
     INNER
      JOIN tblviaggi As v
        ON e.strempID = v.strempIDFK
    WHERE  dtviagSdate > @tomorrow
    AND    dtviagEdate < @today
    Last edited by gvee; 04-14-09 at 10:01.
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •