quary not giving desired results

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dreamer247
    New Member
    • Sep 2007
    • 12

    quary not giving desired results

    hii..

    I have written a quary in sqlserver 2000 and the out put is not as expected...

    the quary is..

    $sql="SELECT NAME,ROOM,DESIG ,EMAIL,PHONE,ST ART_DATE,END_DA TE,CHAIRED_BY FROM CRB_MEETING
    WHERE STATUS <>'D'AND (CAST('10-15-2007 ' AS DATETIME) BETWEEN
    CONVERT(datetim e, SDATE, 103) AND CONVERT(datetim e, EDATE,103) OR
    CAST('10-17-2007 'AS DATETIME)
    BETWEEN CONVERT(datetim e, SDATE, 103) AND CONVERT(datetim e, EDATE, 103))"



    now the motive is to get the value lying between sdate and edate field...but on executing the quary it is marely giving the first row of the database table.

    i am surprised that why the error is coming...can you please help me ..

    regards
    Dreamer.
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    Originally posted by dreamer247
    hii..

    I have written a quary in sqlserver 2000 and the out put is not as expected...

    the quary is..

    $sql="SELECT NAME,ROOM,DESIG ,EMAIL,PHONE,ST ART_DATE,END_DA TE,CHAIRED_BY FROM CRB_MEETING
    WHERE STATUS <>'D'AND (CAST('10-15-2007 ' AS DATETIME) BETWEEN
    CONVERT(datetim e, SDATE, 103) AND CONVERT(datetim e, EDATE,103) OR
    CAST('10-17-2007 'AS DATETIME)
    BETWEEN CONVERT(datetim e, SDATE, 103) AND CONVERT(datetim e, EDATE, 103))"



    now the motive is to get the value lying between sdate and edate field...but on executing the quary it is marely giving the first row of the database table.

    i am surprised that why the error is coming...can you please help me ..

    regards
    Dreamer.
    1. You didn't provide an error you get.
    2. There is no reason using third format parameter when converting to datetime datatype. SQL server can care less what format you sending to the query it is for diplay purposes only and use with varchar or char datatypes.

    Try this:

    Code:
    SELECT NAME,ROOM,DESIG,EMAIL,PHONE,START_DATE,END_DATE,CHAIRED_BY FROM CRB_MEETING
    WHERE STATUS <>'D' 
    AND (CAST('10-15-2007 ' AS DATETIME) BETWEEN CONVERT(datetime, SDATE) AND CONVERT(datetime, EDATE) OR 
         CAST('10-17-2007 ' AS DATETIME) BETWEEN CONVERT(datetime, SDATE) AND CONVERT(datetime, EDATE))
    Good Luck.

    Comment

    • dreamer247
      New Member
      • Sep 2007
      • 12

      #3
      thanks....

      that is solved

      Comment

      Working...