Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2008
    Posts
    12

    Unanswered: add specific date

    Hi all

    How do i set a specific between date in here


    i want to add this line or How do i set specific between date
    WHERE between '06-06-2005' And '04-01-2007'

    SELECT * FROM gradeaverage
    WHERE Name='student'
    ORDER BY Date

    Thank advance

  2. #2
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    SELECT * FROM gradeaverage
    WHERE Name='student'
    and Date between '06-06-2005' And '04-01-2007'
    ORDER BY Date

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    April 1st or January 4th?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Apr 2008
    Posts
    12
    Quote Originally Posted by jezemine
    SELECT * FROM gradeaverage
    WHERE Name='student'
    and Date between '06-06-2005' And '04-01-2007'
    ORDER BY Date
    Thanks for replied, when i ran that codes in Query Analyzer i got invalid column name "Date"

    thank

  5. #5
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    do you have a column called date in your table?

    try enclosing date in [] like this [date].
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  6. #6
    Join Date
    Apr 2008
    Posts
    12
    okay one last question...is possible to export into excel format instead text?

  7. #7
    Join Date
    Jan 2004
    Location
    In a large office with bad lighting
    Posts
    1,040
    Easiest way is to set the results window to grid, execute your query, then either right mouse click in the results window and save the results as a csv file, or copy and paste the results directly into a spreadsheet.

    -- This is all just a Figment of my Imagination --

  8. #8
    Join Date
    Apr 2008
    Posts
    12
    okay..one more question..hopefully this is a last one

    Is possible to write a query to add specific date and in certain table.

    for example i want to add 04/02/2008 from hours 1-24. can i tell the query to add up the date and the hours give me the average

    sorry i am newbie to this stuff

    Thanks advance

  9. #9
    Join Date
    Jan 2004
    Location
    In a large office with bad lighting
    Posts
    1,040
    I don;t understand the question ... can you provide an example? Also, surround your exanple with the output of clicking on the # symbol above the text entry box ... that will keep the original alignment of your example.

    -- This is all just a Figment of my Imagination --

  10. #10
    Join Date
    Jan 2004
    Location
    In a large office with bad lighting
    Posts
    1,040
    Is it something like this?
    Code:
    create table #temp (gdate datetime)
    insert into #temp
    select top 10 U5_Date from dbo.Agents_U5_Data order by U5_Date desc
    /*
    1999-03-08 00:00:00.000
    1999-01-04 00:00:00.000
    1998-12-29 00:00:00.000
    1998-12-29 00:00:00.000
    1998-12-29 00:00:00.000
    1998-12-29 00:00:00.000
    1998-12-29 00:00:00.000
    1998-12-29 00:00:00.000
    1998-11-12 00:00:00.000
    1998-11-06 00:00:00.000
    */
    select avg(gdate) from #temp
     
    Results:
    Server: Msg 409, Level 16, State 2, Line 17
    The average aggregate operation cannot take a datetime data type as an argument.

    -- This is all just a Figment of my Imagination --

Posting Permissions

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