Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 Output of SQL Statement to Text File

Author  Topic 

dhumphries
Starting Member

18 Posts

Posted - 2008-12-29 : 16:45:07
I have a project were I need to be able to export the results of a sql statement to a flat file. while this is simple enough the statements I am using largely do not produce a column for export so I can no do any linking. I would prefer not to create a mess of temp table so how can I get it there. Here is an example of the statement

select '1: GROSS',
sum(PPRD_CHK_GROS_AM )
from pay_check_ext a, pay_check b
where a. int_ctrl_no = b.int_ctrl_no
and gtn_run_no = 762

This result and how it needs to be in the flat file is below.

----------- ---------------
1: GROSS 1972306.77

How can I complete this in SSIS or SQL 2005 in general

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-29 : 17:03:59
You can achieve this through bcp or SSIS. See Books Online for details on either approach.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dhumphries
Starting Member

18 Posts

Posted - 2008-12-29 : 17:16:52
I apologize I should have been more specific. I know how to do this several ways one being through a bcp but I need this to be a SSIS so that the end user can run a job and get the outputed file to be loaded into another application. I have looked online all over the place and can not figure out for the life of me how to output the raw result to a file in SSIS.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-29 : 17:24:42
Do you have Business Intelligence Development Studio installed?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dhumphries
Starting Member

18 Posts

Posted - 2008-12-29 : 17:27:10
Yes I have tried to build the package thinking I could simply run a sql command produce the output and stick it in a file. problem is I have no destination cloumns to output. becuase the select statement I am running does not realy result in any columns.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-29 : 17:29:11
Oh now I get your issue. Change your query to:

select '1: GROSS' AS Column1,
sum(PPRD_CHK_GROS_AM) AS Column2
from pay_check_ext a, pay_check b
where a. int_ctrl_no = b.int_ctrl_no
and gtn_run_no = 762

Change Column1, Column2 names to more appropriate, descriptive column headers.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dhumphries
Starting Member

18 Posts

Posted - 2008-12-29 : 17:30:41
I thought of that but the destination still does not see any columns available.
Go to Top of Page

dhumphries
Starting Member

18 Posts

Posted - 2008-12-29 : 17:33:17
I am trying to run this in the OLE DB Command under the data flow source. would there be a better transform to use that would allow the information to pass to the file destination?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-30 : 00:49:28
quote:
Originally posted by dhumphries

I am trying to run this in the OLE DB Command under the data flow source. would there be a better transform to use that would allow the information to pass to the file destination?


did you try clicking preview button on OLEDB source and see if it picked up column headers correctly. After that you need to go to column mapping tab and select the column by clicking checkbox for them to get included in pipeline metadata.
Go to Top of Page

dhumphries
Starting Member

18 Posts

Posted - 2008-12-30 : 08:56:37
I have looked at the source and no columns are selected. The reason for that is if you look at the select query I am running the output I am looking for is a sum of a column not necessarily a particular column in a table.
Go to Top of Page

dhumphries
Starting Member

18 Posts

Posted - 2008-12-30 : 09:08:46
I thought this might be a better disription of what I am trying to do.
I have a series of select statements. When you enter those in the qury window of sql Server you can select output to file. This will run all the statements and write the output to the file rather then the screen. What I want to due is simply create a job that will do the exact same thing.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-30 : 11:45:28
quote:
Originally posted by dhumphries

I thought this might be a better disription of what I am trying to do.
I have a series of select statements. When you enter those in the qury window of sql Server you can select output to file. This will run all the statements and write the output to the file rather then the screen. What I want to due is simply create a job that will do the exact same thing.


as you said earlier you can simply do this in ssis. but i just cant understand why this didnt work for you.
b/w were you trying to execute all select statements in the same oledb source? also are all there resultsets similar?
Go to Top of Page
   

- Advertisement -