Several SQL questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SuperPhil

    Several SQL questions

    Hi all,

    I'd like to know if it's possible to sort twice in a same SQL query.

    I use SQL for retrieving Data into an Excel Spreadsheet.
    (Excel 2000 or XP) and to paste the queries results into an Excel
    spreadsheet.

    1. I tried to sort by date and the only way was to use the serail number
    instead of the litteral name

    I tried SELECT * FROM [Sheet1$] Where [Date] <= 07/20/2003"
    but this does not work.
    I then tried SELECT * FROM [Sheet1$] Where [Date] <= 37822" and it
    works.

    Do you know a way to use 07/20/2003?

    2. I need to sort my data twice, first by name and second by date. Is it
    possible to sort twice in one query?
    Something like:
    "SELECT * FROM [Sheet1$] Where [Date] <= 07/20/2003 ORDER BY [NAME] ASC,
    ORDER BY [DATE] DESC"


    3. Even if the first row of my Excel sheet includes the headers, I can
    not perform a query other than SELECT * FROM, for exemple, SELECT [NAME]
    FROM, does not work. do you know how to do that?


    Thanks in advance for sharing your experience,

    Phil

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Erland Sommarskog

    #2
    Re: Several SQL questions

    John Bell (jbellnewsposts @hotmail.com) writes:[color=blue]
    > SELECT * FROM [Sheet1$] Where [Date] <= '07/20/2003'
    >
    > Usually it is better to use a safe date format e.g. '20030720'[/color]

    '20030720' is the safe format in SQL Server, but it appears that we're
    talking Excel here. What is a good format for Excel, I have no idea.
    '2003-07-20' appears to be a good bet, but I don't know. (It surely
    will work on my computer - because that is my regional setting.)


    --
    Erland Sommarskog, SQL Server MVP, sommar@algonet. se

    Books Online for SQL Server SP3 at
    SQL Server 2025 redefines what's possible for enterprise data. With developer-first features and integration with analytics and AI models, SQL Server 2025 accelerates AI innovation using the data you already have.

    Comment

    Working...