Order by clause

Results 1 to 2 of 2

Thread: Order by clause

  1. #1
    Join Date
    Dec 1969

    Default Order by clause

    I have userid field and associated datetime field.Now I am trying to create a report for each day having for all the userid and date time for that day.my query is below but since the time1<BR>is datetime field in sql server instead of getting all the records associated with that day,it trying to get all the records associated with that datetimestamp.Is there a way when i do order by i can just use onlydate part from date1 field and not datetime<BR> Query = "SELECT time1,userid FROM data1 order by time1<BR> <BR>anyhelp appreciateddesc"

  2. #2
    Join Date
    Dec 1969

    Default Where is your WHERE clause???

    You aren&#039;t limiting the query to any particular day, so of course you get *all* the records.<BR><BR>To limit to one day, there are a couple of things you can do:<BR><BR>SELECT userid, time1 <BR>FROM data1<BR>WHERE Year(time1) = 2004 AND Month(time1) = 4 AND Day(time1) = 13<BR>ORDER BY time1 DESC<BR><BR>** or **<BR><BR>SELECT userid, time1 <BR>FROM data1<BR>WHERE CONVERT(DATETIME, CONVERT(VARCHAR(20), time1, 102), 102)= &#039;4/13/2004&#039;<BR>ORDER BY time1 DESC<BR><BR>That double convert is the ugly way you have to use with SQL Server to get only the date portion of a datetime field. <BR><BR>

Posting Permissions

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