sql server -- result wants into txt file or exel file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sachin28880
    New Member
    • Aug 2007
    • 2

    sql server -- result wants into txt file or exel file

    hi all

    i want sql query result into text file (by using query) can any one tell me...

    like this Select * from employee where empname='sachin ' to 'c:\result.txt'

    from sachin shah
  • bwestover
    New Member
    • Jul 2007
    • 39

    #2
    Originally posted by sachin28880
    hi all

    i want sql query result into text file (by using query) can any one tell me...

    like this Select * from employee where empname='sachin ' to 'c:\result.txt'

    from sachin shah
    You should be able to set 'Results to File' in Query Analyzer. To do this in Query Analyzer click Query->Results to File, or press Ctrl+Shift+T.

    Then when you execute your query, it will go to a file of your choosing.

    The other way is to simply copy and paste the results grid to Excel.

    What version of SQL are you running? Are you trying to do this once or twice or are you trying to write a program that does this?

    Comment

    • sachin28880
      New Member
      • Aug 2007
      • 2

      #3
      Originally posted by bwestover
      You should be able to set 'Results to File' in Query Analyzer. To do this in Query Analyzer click Query->Results to File, or press Ctrl+Shift+T.

      Then when you execute your query, it will go to a file of your choosing.

      The other way is to simply copy and paste the results grid to Excel.

      What version of SQL are you running? Are you trying to do this once or twice or are you trying to write a program that does this?
      hi

      i know these thing, but i want the query....

      i am using sql 2000...

      Comment

      • azimmer
        Recognized Expert New Member
        • Jul 2007
        • 200

        #4
        Originally posted by sachin28880
        hi

        i know these thing, but i want the query....

        i am using sql 2000...
        unfortunately it isn't that easy; in fact a simple query can hardly do it

        one way to go is to build a DTS package (if you start from Enterprise Manager / Data Transformation Services, it is fairly straightforward , though not necessarily simple)

        another possibility is to do it the other way round: via ODBC from Excel (it doesn't work for TXT)

        Comment

        • azimmer
          Recognized Expert New Member
          • Jul 2007
          • 200

          #5
          Originally posted by azimmer
          unfortunately it isn't that easy; in fact a simple query can hardly do it

          one way to go is to build a DTS package (if you start from Enterprise Manager / Data Transformation Services, it is fairly straightforward , though not necessarily simple)

          another possibility is to do it the other way round: via ODBC from Excel (it doesn't work for TXT)
          oh yea', and one more, maybe the best fit to your needs: OPENROWSET

          Comment

          Working...