Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Save results from table

Save results from table

Scheduled Pinned Locked Moved Database
databasesharepointsql-serversysadmin
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Waheed Ur Rehman
    wrote on last edited by
    #1

    Hi all I am working with SQL Server express edition. I want to save the results of my query in a text file. SELECT UserName,JoinDate,PostCount FROM Posts i have written this query in a SP. What i want is when i call the procedure the results should be saved in a text file. Thanks

    P S Z 3 Replies Last reply
    0
    • W Waheed Ur Rehman

      Hi all I am working with SQL Server express edition. I want to save the results of my query in a text file. SELECT UserName,JoinDate,PostCount FROM Posts i have written this query in a SP. What i want is when i call the procedure the results should be saved in a text file. Thanks

      P Offline
      P Offline
      Parwej Ahamad
      wrote on last edited by
      #2

      Do some research on CLR Stored procedure.

      Parwej Ahamad R & D: REST services with WCF

      1 Reply Last reply
      0
      • W Waheed Ur Rehman

        Hi all I am working with SQL Server express edition. I want to save the results of my query in a text file. SELECT UserName,JoinDate,PostCount FROM Posts i have written this query in a SP. What i want is when i call the procedure the results should be saved in a text file. Thanks

        S Offline
        S Offline
        SimulationofSai
        wrote on last edited by
        #3

        If you're using SSMS to connect to your SQL Server express instance, hit Ctrl + Shift + F and execute your SP.

        W 1 Reply Last reply
        0
        • S SimulationofSai

          If you're using SSMS to connect to your SQL Server express instance, hit Ctrl + Shift + F and execute your SP.

          W Offline
          W Offline
          Waheed Ur Rehman
          wrote on last edited by
          #4

          Hi i have searched a lot and found that BCP can be used for this purpose. Now i have written a simple query Declare @str nvarchar(4000) set @str='bcp "Select DISTINCT MAIN_ID from mydb.dbo.Postings " QUERYoUT "E:\Temp1.txt" -T' Print(@str) Execute master..xp_cmdshell @str But i get the Output SQLState = 08001, NativeError = 126 Error = [Microsoft][SQL Native Client]VIA Provider: The specified module could not be found. NULL SQLState = HYT00, NativeError = 0 Error = [Microsoft][SQL Native Client]Login timeout expired SQLState = 08001, NativeError = 126 Error = [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connecti ons. NULL I have checked remote connections are enabled...... Looking forward for your reply. Thanks

          S M 2 Replies Last reply
          0
          • W Waheed Ur Rehman

            Hi i have searched a lot and found that BCP can be used for this purpose. Now i have written a simple query Declare @str nvarchar(4000) set @str='bcp "Select DISTINCT MAIN_ID from mydb.dbo.Postings " QUERYoUT "E:\Temp1.txt" -T' Print(@str) Execute master..xp_cmdshell @str But i get the Output SQLState = 08001, NativeError = 126 Error = [Microsoft][SQL Native Client]VIA Provider: The specified module could not be found. NULL SQLState = HYT00, NativeError = 0 Error = [Microsoft][SQL Native Client]Login timeout expired SQLState = 08001, NativeError = 126 Error = [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connecti ons. NULL I have checked remote connections are enabled...... Looking forward for your reply. Thanks

            S Offline
            S Offline
            SimulationofSai
            wrote on last edited by
            #5

            Your BCP command must have the -S "Server Name" included, or else it'll search for the default instance.

            set @str='bcp "Select DISTINCT MAIN_ID from mydb.dbo.Postings " QUERYoUT "E:\Temp1.txt" -S InstanceName -T'

            1 Reply Last reply
            0
            • W Waheed Ur Rehman

              Hi i have searched a lot and found that BCP can be used for this purpose. Now i have written a simple query Declare @str nvarchar(4000) set @str='bcp "Select DISTINCT MAIN_ID from mydb.dbo.Postings " QUERYoUT "E:\Temp1.txt" -T' Print(@str) Execute master..xp_cmdshell @str But i get the Output SQLState = 08001, NativeError = 126 Error = [Microsoft][SQL Native Client]VIA Provider: The specified module could not be found. NULL SQLState = HYT00, NativeError = 0 Error = [Microsoft][SQL Native Client]Login timeout expired SQLState = 08001, NativeError = 126 Error = [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connecti ons. NULL I have checked remote connections are enabled...... Looking forward for your reply. Thanks

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              I find this easier to bring the result set to the client as a datatable and then write out the table as a CSV file. BCP is fine for ETL processes but there are a number of issues around security (passwords in clear) and file system permissions.

              Never underestimate the power of human stupidity RAH

              1 Reply Last reply
              0
              • W Waheed Ur Rehman

                Hi all I am working with SQL Server express edition. I want to save the results of my query in a text file. SELECT UserName,JoinDate,PostCount FROM Posts i have written this query in a SP. What i want is when i call the procedure the results should be saved in a text file. Thanks

                Z Offline
                Z Offline
                zahedonline
                wrote on last edited by
                #7

                Yes you can do it for sure... i have done this somany times Reffer here.. http://www.sqlteam.com/article/osql-storing-result-of-a-stored-procedure-in-a-file[^] Cheers,

                ZAK

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups