How to save a query in SQL Server so it is visible in Object Explorer

11,782

You cannot save Query on SQL Server. It's better to create a View if you're planning to use it later

Share:
11,782

Related videos on Youtube

Liquidmetal
Author by

Liquidmetal

Updated on September 15, 2022

Comments

  • Liquidmetal
    Liquidmetal almost 2 years

    I am SQL Server newbie, many of my thnkings are based on Access DB work.

    I have searched for an answer to this question but have not found anything that answers it.

    I have opened my query builder and when I close it - it asks to 'save as' and takes me to a folder. I save it but the query is not visible in object explorer, so how do I have access to it and how can I use it for making forms with InfoPath etc.

    I have been searching all day and yet no results so I would be grateful for an explaination on how this can be done. Many thanks.

  • JayC
    JayC over 11 years
    Of course, views can't have a default ordering, IIRC, so his query might not work there.
  • Andrey Gordeev
    Andrey Gordeev over 11 years
    Well, OP is from MS Access, I think he meant a simple SELECT query
  • JayC
    JayC over 11 years
    I was refering to ORDER BY, sorry I wasn't being clearer. msdn.microsoft.com/en-us/library/ms187956.aspx => The SELECT clauses in a view definition cannot include the following: An ORDER BY clause, unless there is also a TOP clause in the select list of the SELECT statement ... <= often simple select queries do have an ORDER BY clause.. of course the OP could use a SQL Function, which (also IIRC) doesn't have this restriction.
  • Martin Smith
    Martin Smith over 11 years
    @JayC - A SELECT ... FROM dbo.Function() isn't guaranteed to return the result in any particular order either without an ORDER BY
  • Liquidmetal
    Liquidmetal over 11 years
    Many thanks for all your replies. Your replies show that I can create new views which will act as simple select queries but with user inout filters. I need the queries to be filters so by selecting from a drop down menu, a user can limit the data to the selected data. Also can someone point me in the right direction on how I can make forms for users to see the data, InfoPath is too dense for me at the moment and need something less weighty if possible?
  • Andrey Gordeev
    Andrey Gordeev over 11 years
    @user2083178 That's a subject for another question.