Solved

SQL 2008 Output to Text File

Posted on 2011-03-02
6
641 Views
Last Modified: 2012-05-11
I have sql 2008 r2 and am needing to create a text file from a query result.  The data will need to be in certain row,character locations in the the text fields as it will be used to import into an existing system.  Can someone point me a direction of what sql commands to use?  I eventually would configure it as a stored procedure to run on a fixed interval of time.
0
Comment
Question by:amickfarms
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 15

Expert Comment

by:derekkromm
ID: 35017732
0
 

Author Comment

by:amickfarms
ID: 35017774
That really doesn't give me the results I was aiming for.  I need to place data in certain row,character locations in the text file.  A little more than just dropping to a text file.
0
 
LVL 15

Expert Comment

by:derekkromm
ID: 35017793
i'm not sure what you're looking for then

you want it to be formatted a specific way? if so, you may want to look at using char/nchar data types instead of varchar/nvarchar

those will be padded with spaces at the end, so if you want your file to look like

COLA.....COLB......etc
COA.......COB.......etc

char will pad the necessary # of spaces

not sure if that helps?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:amickfarms
ID: 35017805
That may work.  I will work with this for a while and see what I can come up with.
0
 
LVL 15

Accepted Solution

by:
derekkromm earned 500 total points
ID: 35017827
Ya, you can do some simple comparisons on that in SSMS by changing your output type to Text and doing something like

"select a,b,c from tbl"
"select convert(char(10),a), convert(char(20),b),convert(char(10),c) from tbl"

and seeing the differing displays
0
 

Author Closing Comment

by:amickfarms
ID: 35483357
I had to use oterh SQL functions to make this work.  Still not finished with the project.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS SQL + Insert Into Table - If Doesnt Exist 9 60
SQL Improvement  ( Speed) 14 37
SQL Select Query help 1 38
Database-Scoped Permissions 2 17
After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question