[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 655
  • Last Modified:

SQL 2008 Output to Text File

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
amickfarms
Asked:
amickfarms
  • 3
  • 3
1 Solution
 
amickfarmsAuthor Commented:
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
 
derekkrommCommented:
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
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
amickfarmsAuthor Commented:
That may work.  I will work with this for a while and see what I can come up with.
0
 
derekkrommCommented:
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
 
amickfarmsAuthor Commented:
I had to use oterh SQL functions to make this work.  Still not finished with the project.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now