SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Extract to a file


Extract to a file

Author
Message
patrickn
patrickn
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 Visits: 62
Hello,
Has anyone ever tried to run a query to get information from SQL 2005 and put the results to a file? I have address information in a table and I want to create a delimited file for label printing with the address information.

So, I would like to run a script on my local machine that gets the address information and puts it to a CSV '|' [Pipe] delimited file. Then I can email the file with column headings to a person to do a mail merge for label creation.

If not the what is the best way to do this?

Thank you,
Patrick
The Dixie Flatline
The Dixie Flatline
SSCertifiable
SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)

Group: General Forum Members
Points: 7244 Visits: 6903
If you can run your script from SMSS, try this:

Tools\Options\Query Results\SQL Server\Results to Text ... then choose your options.

At least that's what it is in 2008. I can't remember if that's it exactly in 2005, but it's similar. Then select output to text when you run your script in SMSS.

Also you can use BCP to execute a query, and BCP options can control the output format.

__________________________________________________

Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
steveb.
steveb.
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5724 Visits: 7195
Another way to do this would be to create a SSIS package that can extract the file and write to a csv file, you can even get the SSIS package to email the file once it has been created, the wizard will be able to get you started on this or check out BOL.
patrickn
patrickn
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 Visits: 62
Where could I find more information on 'BoL'?

Also, Besides the ways discussed previously; Could I do this through report manager?

Just curious, then the client could run a label when ever they want.
steveb.
steveb.
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5724 Visits: 7195
Bol = books on line = SQL sever help . search for SSIS tutorials to get you started.

If you want a way for the client to run this automaically then (assuming they are using Excel or Word to do the mail merge) you can create a database connection via ODBC to get the data from the database.
patrickn
patrickn
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 Visits: 62
Hello,
As anyone used SaveDelimitedColumns or SaveDelimitedColumnsNullQuoted?
These are some stored procedures that can to exactly what I am looking for but I am having a hard time getting fields with mixed data into the CSV file.

Thank you,
PN.
roger young-372270
roger young-372270
Grasshopper
Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)

Group: General Forum Members
Points: 20 Visits: 223
You could also try using the command line with BCP. Here's one for the AdventureWorks DB.

At the command line cd to C:\Program Files\Microsoft SQL Server\90\Tools\Binn

Then type

bcp "SELECT CONT.FirstName,C
ONT.LastName,ADDR.AddressLine1,ADDR.AddressLine2,ADDR.City,SP.StateProvinceCode,
ADDR.PostalCode FROM AdventureWorks.HumanResources.Employee EMP JOIN AdventureWo
rks.HumanResources.EmployeeAddress EA ON EMP.EmployeeID = EA.EmployeeID JOIN Adv
entureWorks.Person.Address ADDR ON EA.AddressID = ADDR.AddressID JOIN AdventureW
orks.Person.StateProvince SP ON ADDR.StateProvinceID = SP.StateProvinceID JOIN A
dventureWorks.Person.Contact CONT ON CONT.ContactID = EMP.ContactID ORDER BY CO
NT.LastName" queryout C:\Users\YourDesktop\Desktop\fileexport.txt -t "|" -S Server -T -c



You'll have to modify below for your server,database,query,authentication type etc.

You'll also want to checkout the rest of the parameters to tailor it specifically for your needs.
patrickn
patrickn
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 Visits: 62
Hello,
I got it to work with the Free ware: SaveDelimitedColumns. Works pretty nice. I can put it on the network drive and the client pick it up.

I tried the BCP and recieved a bunch of errors. Probably missing something to turn on.

I thank you all for the ideas and I have gotten good information pieces from you.

Best regards.
mm-1009269
mm-1009269
SSC-Enthusiastic
SSC-Enthusiastic (199 reputation)SSC-Enthusiastic (199 reputation)SSC-Enthusiastic (199 reputation)SSC-Enthusiastic (199 reputation)SSC-Enthusiastic (199 reputation)SSC-Enthusiastic (199 reputation)SSC-Enthusiastic (199 reputation)SSC-Enthusiastic (199 reputation)

Group: General Forum Members
Points: 199 Visits: 182
Patrickn,

I'm doing the same thing now with my project. In RS, I link to my datasource and insert my query and I do all the formatting I need in there to make it look pretty for the users. Then I have SSIS packages that execute the report (or CSV) on regular intervals to a reports server. And you can also store it on a network drive.

-M
patrickn
patrickn
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 Visits: 62
I be interested in seeing this a liitle closer. Where did you dig up the research? How do you handle parm data (parameters passed into the script)?

The thing I worked on is a quick script to run on demand.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search