Generate A Separate Txt File For Each Account In A Table, Need To Join Tables To Get Details, And Specify Output File Name?

May 16, 2008

Hey,



I'm looking for a good way to rewrite my T-SQL code with 'bcp' to SSIS package, any help would be greatly appreciated?



I have table1 contain account numbers and output-filename for each account,

I need to join table2 and table3 to get data for each account in table1, and then export as a txt file.



Here is my code using bcp (bulk copy)

DECLARE @RowCnt int,
@TotalRows int,
@AccountNumber char(11),
@sql varchar(8000),
@date char(10),
@ArchPath varchar(500)

SET @RowCnt = 1
SET @date = CONVERT(CHAR(10),GETDATE(),110)
SET @ArchPath = '\D$EDATAWorkFoldersSendSendData'
SELECT @TotalRows = count(*) FROM table1
--select @ArchPath

WHILE (@RowCnt <= @TotalRows)
BEGIN
SELECT @AccountNumber = AccountNumber, @output_filename FROM table1 WHERE Identity_Number = @RowCnt
--PRINT @AccountNumber --test
SELECT @sql = N'bcp "SELECT h.HeaderText, d.RECORD FROM table2 d INNER JOIN table3 h ON d.HeaderID = h.HeaderID WHERE d.ccountNumber = '''
+ @AccountNumber+'''" queryout "'+@ArchPath+ @output_filename + '.txt" -T -c'
--PRINT @sql
EXEC master..xp_cmdshell @sql
SELECT @RowCnt = @RowCnt + 1
END

View 7 Replies


ADVERTISEMENT

Generate SQL Scripts Creating A Separate File Per Object

Sep 13, 2007

Hello all,
What is an easy way of scripting all the database tables and sprocs automatically to a separate file each one? I can't find this option in SQL Server Management Studio.
Or is any other way of uploading all objects to a Visual Source Safe project that does not require to copy and paste each script into a VSS sql script?
Thanks!
David

View 3 Replies View Related

SQL 2012 :: Tables On Separate File Groups

Jul 30, 2014

We have a large Datawarehouse and the size is 50TB.. The tables are placed in filegroups based on the schema like fact, dimensions, raw data each sit on seperate filegroups. I am thinking will it make sense to seperate the large facts which are having billions of rows so that they reside on filegroups on their own..

View 9 Replies View Related

What Is The Best Approach To Export A Table Or Subtable(resultset) To A Separate .sdf File?

May 3, 2007

hi, guys

How to move one table or a ResultSet to a separate database .sdf file in compact edition?

For example, I have handheld installed the compact edition to do some order works. After the job done, I want move the new table Orders to our server or other place. Of course I don't want to move everything in the .sdf file. So, what is the best way to move table Orders out to a sparate .sdf file? (In my case, I can not use RDA or replication. )

Thanks.

View 5 Replies View Related

Output Sql Table To Text File

Nov 27, 2007

Is there an example anywhere of how to output selected fields in a sql table to a text file with fixed length fields. ie pad data out to required length.

View 2 Replies View Related

File System Task - Output File Variable Syntax????

Feb 7, 2007



Hi

This should be incredibly simple and easy, but I can't find any examples of how to do this.

I just want to make a File System Task move a file, and have the destination be filename + date and time. For example \serversharefilename02072007.txt

What syntax do I use in a variable to make this work?

Thanks

View 16 Replies View Related

Output Table To A Text File (was Newbie Needs Help!)

Dec 24, 2004

I have an assignment and need to dosomething that should be simple, basically output the contents of a table to a text file.

I have been trying this syntax:

bcp "dbo.items_with_constraints_tbl" out "J:items.txt" -c

But I keep on getting this error message:

Server: Msg 179, Level 15, State 1, Line 1
Cannot use the OUTPUT option when passing a constant to a stored procedure.

I am completely lost!! :confused:

Can anyone help me please?

View 12 Replies View Related

How Output All Stored Procedures To A Table Or File

Feb 22, 2005

I wish to ultimately have the content of all stored procedures related to a database in a single ASCII file for review. Is that doable? If so, how?

Thanks,

Peter

View 4 Replies View Related

How Can I Output Subset Of A Table To A Flat File In SSIS?

Aug 24, 2006

Hi All,

I have a table A. I need output subset of a table A to a flat file using query, like:

select A.* from A inner join B on... ..... inner join C......where left(A.id, 3) = B.sid.... AND B.num between 100 and 200).

How can I do this in SSIS? Which data flow item I may need?

Thanks

 

View 2 Replies View Related

Records From Internal Table Not Output In Order To Flat File

Oct 13, 2006

Hi -

I have a SSIS package that dumps data from an internal table to a flat file output using standard data flow tasks. The entire table is output - no special SQL. Most of the time the records are placed in the output file in the same order as the internal DB table, but occasionally the order appears to be more random. When that happens, the record order in the internal table is correct - it is just the output.

I can find no properties that seem to affect this. I would appreciate any hints and advice that anyone can give me. Has anyone else encountered this same problem?

Thanks in advance,

Jim Sweeney

View 4 Replies View Related

SSIS - Output Table To Flat Fixed-width File

Oct 19, 2007

I am new to SSIS and am having trouble with automatically setting up the destination output columns.

I am sure there must be an easy way to do this.

My table (source) has 86 columns in it of varying lenghts.

In my connection magagers, I have created one for the SQL Server (source data) and one for the flat file (destination output).

I have also created an OLE DB source data object and a destination Flat File object and set them up to the respective connection managers.

Finally I have linked the source to the destination.

Now when I look at the source, it shows me all 86 columns.

When I open up destination, there are no columns set up.

Problem: do I have to type in all the columns manually in the connection manager for the Flat File?

I would think there would be some automatic way that it would self-populate the columns over to the flat file destination.

View 3 Replies View Related

Transact SQL :: Output A File With A File Header

Aug 27, 2015

In my SSIS Package, I have to write my [FileHeaderRecord] row, then my [BatchHeaderRecord] row, then my details. How can I do this in a SQL Server Query? When I try my SSIS, my file looks like so..

FHTEST 00000208262015             BH000208262015  

I want my BH, Batch Header data, to appear on a new row in the file.Do I have to build a dynamic query to do this?Is there any trick in SSIS to do something like this?I did try creating separate Data Flow Tasks to Query the [FileHeaderRecord] and then use a Flat File Destination and then another Data Flow Task to Query the [BatchHeaderRecord] and use a Flat File Destination again NOT overwriting the file.

View 2 Replies View Related

Display Output On Separate Separate Line

Feb 10, 2007

How can i format my query so that each piece of data appears on a new separate line? Is there a command for a new line feed? does not work.

thanks.

For example:

a: data
b: data
c: data

a: data
b: data
c: data

View 6 Replies View Related

SQL Server 2012 :: Run Script Within A Table / String And Output Results To File?

Sep 21, 2015

I have been given a request at work that requires us to run the SQL scripts that are held in a report configuration table and output the results as .csv or.xls files in a desired folder with a file name that is also specified within the report config table.

An example of the table is as per script below with column A being the desired file name to be created and Column B contains the script that will be executed.

Ideally I require a script that i can drop into a Stored Proc that will run down each row in the table and export and create each rows results as a separate file in a desired folder.

------------------------------------------------------------------------------------------
-----SAMPLE TABLE SCRIPT -----------------------------------------------------------
------------------------------------------------------------------------------------------
/****** Object: Table [dbo].[Test_Table_PS] Script Date: 21/09/2015 09:14:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Test_Table_PS](
[File_Name] [nvarchar](100) NULL,

[Code] ....

View 7 Replies View Related

Package Execution Details To Log File

May 9, 2008

When you run a deployed package manually, there is a nice load of information output showing you what is going on, this would be very good log file info. Is there anyway to write the same output to a log file when the package is run as a Job from SQL Agent?

View 4 Replies View Related

C# Master-Details (Separate Pages)

Jan 25, 2006

My question is setting up master detail pages using stored procedrues.  In the tutorials C# Master-Details (Seperate Pages) example they use the following code for the master page for the navigation.
          <asp:HyperLinkField HeaderText="View Details..." Text="View Details..." DataNavigateUrlFields="au_id"            DataNavigateUrlFormatString="DetailsView_cs.aspx?ID={0}" />
The call to the Details Page DetailsView_cs.aspx uses the following code
 <asp:SqlDataSource ID="SqlDataSource1" Runat="server" SelectCommand="SELECT dbo.authors.au_id, dbo.titles.title_id, dbo.titles.title, dbo.titles.type, dbo.titles.price, dbo.titles.notes FROM dbo.authors INNER JOIN dbo.titleauthor ON dbo.authors.au_id = dbo.titleauthor.au_id INNER JOIN dbo.titles ON dbo.titleauthor.title_id = dbo.titles.title_id WHERE (dbo.authors.au_id = @au_id)"        ConnectionString="<%$ ConnectionStrings:Pubs %>">        <SelectParameters>          <asp:QueryStringParameter Name="au_id" DefaultValue="213-46-8915" QueryStringField="ID" />        </SelectParameters>      </asp:SqlDataSource>
I can replicate the example calling the detail page but I am unable to make the detail page work when using a stored procedure as the asp:SQLDataSource. Using the above sql code as a stored procedure in the  <SelectParameters>  I am not able to return the data set using either asp:QueryStringParameter or asp:Parameter as I have built other forms using stored procedures and have tested the procedure and know that it works. Can someone point me in the right direction.
Thanks
 
 

View 2 Replies View Related

Output Column Width Not Refected In The Flat File That Is Created Using A Flat File Destination?

May 11, 2006

I am transferring data from an OLEDB source to a Flat File Destination and I want the column width for all of the output columns to 30 (max width amongst the columns selected), but that is not refected in the Fixed Width Flat File that got created. The outputcolumnwidth seems to be the same as the inputcolumnwidth. Is there any other setting that I am possibly missing or is this a possible defect?

Any inputs will be appreciated.

M.Shah

View 3 Replies View Related

How To Create A File With Header, Details & Footer

Aug 31, 2006

Hi All,

I need to create a query which gives me something like this

HH20060831160342
DDasb IT 3000
FF20060831160709000000001


Where 'HH' is the header(followed by Date and time) and 'FF' is the footer (followed by Date, time and no of records)and 'DD' has some details (few fields) from database.I am using UNION to get this result but the problem is that if the count in the footer is 0 then query should not give any output.but If I am using the following query
select 'HH'+convert(varchar,getDATE(),112)+replace(convert(varchar,getdate(),8),':','') as filename,'' as name,'' as dept,'' as sal
union all
select 'DD'+'',filename,dept,sal from emp where empno like '%1%'
union all
select 'FF'+convert(varchar,getDATE(),112)+replace(convert(varchar,getdate(),8),':','')+ REPLICATE(0, 9-len(COUNT(*)))+''+convert(VARchar(10),COUNT(*)) as filename,'' as name,'' as dept,'' as sal from emp where empno like '%1%'

I am getting the result as


HH20060831161226
FF20060831161226000000000
if the second select statement has no records

Please help

View 3 Replies View Related

Importing .txt Files With Separate Definition File

Apr 13, 2006

Hi all,

I receive data via FTP to our webserver nightly as .txt files and .dic (if anybody is familiar with idx realtor websites, that's what this data is).
I've learned recently that I'm not going to be able to use Access to import or link to this data, so I'm trying to get my feet wet with SQL.
I have been practicing importing text files into SQL db, but I notice that the dts imports everything as varchar 8000, and that you can edit that. I've got a .dic file that accompanies every .txt file that contains definitions of each fieldname, fieldtype & length & I was wondering how to import that data as well, without having to manually retype everything.
I would be happy to email these text files to anybody willing to take a look.

Thanks,
Carrie

View 2 Replies View Related

SQL 2012 :: Creating Dynamic SSIS File Format - Dynamic CSV File As Output

Mar 2, 2014

I am trying to create an ssis package with dynamic csv file as output. and out format contains query output.

sample file name:

Unique identifier + query output + systemdate();

The expression is looking like this.

@[User::FilePath] + @[User::FileName] + ".CSV"

-- user filepath is a variable from ssis package. File name is the output from SQL query. using script task i have assigned the values to @[User::FileName] .

When I debugged the script task the value getting properly but same variable am using for Flafile destination. but its not working.

View 3 Replies View Related

'One Table' Record To Separate 'two Or Three Tables' Using Cursor?

Jan 28, 2005

I would like to 'one table' record to separate 'two or three tables'
. I just know use the DTS , try to import and export again and agian.
So trouble.

Could you give me some suggestions for me? For example ,
'Cursor' write in new table . But I try to SQL Server Books Online
which is not suitable for me solving problems. One table separate two
or three tables. Can you wirte the detail example for me?
Thx a lot.

View 1 Replies View Related

Use Single Table Or Multiple Separate Tables?

Sep 7, 2005

Hi,
We are building an application for online system for people to place ADs for selling various used items like Car, Electronics, Houses, Books etc.
If someone selling a car then he can fill out headline, year, make, model, mileage, transmission, condition, color, price, description, contact etc.
Similarly if someone selling a digital camera he will fillout headline, memory, zoom, megapixel, maker, model, color, batter, description etc.
Option 1: I can have a main table to hold the common attributes of all different types of ADs (headline, images, contact, price, color, condition, description)
+ 1 table to store string values of all ADs (car: maker, model, square feet (if house), memory, megapixel (camera) etc)
+ 1 table to store the droplist select values(car: transmission, door, seat etc; house: year_built)
pros: single table for all ADs. unique IDs for all ADs, easy to extend as new attributes can be dropped easily.
cons: lot of physical reads of 2nd and 3rd table from join. 10 times physical reads compared to option 2 when reading 5000 records.
Option 2: have different set of table for each AD type. Car will have its own main table + 1 table to store multiselect list box values.
Similarly housing will have its own set of tables
pros: 10% less physical read than option 1.
cons: hard to add new attributes. We have to modify the main table by adding one column.
Query will go to different table based on the category.
Do you have any suggestions on which way to go?Thanks

View 2 Replies View Related

Pros And Cons Of Placing Indexes On Separate File Groups

Apr 20, 2001

We are in the process of replacing our primary production server. In the process of determining how SQL server is going to be structured, it has been suggested that I place all current and new indexes on a separate file group. These filegroups would then reside on a separate shelf on the server. What are the pros and cons of doing this?

View 2 Replies View Related

Transact SQL :: Flat Text File - Separate HTML String

Jun 24, 2015

I have a flat text file with lots HTML tags and corresponding values 

For example 
<Near_Side> 5563 </Near_Side>
<Top_Down_Code> Xe345 <Top_Down_Code> 

So, For example I can use the a function 

ALTER function dbo.StripHTML( @text varchar(max) ) returns varchar(max) as
begin
    declare @textXML xml
    declare @result varchar(max)
    set @textXML = REPLACE( @text, '&', '' );

[Code] ...

To which Select dbo.StripHTML('<Near_Side> 5563 </Near_Side>')  Value 

I'll get 5563

However how would you get the values within the tag itself ? E.g. 

Value Name 
5563 Near_side
Xe345      Top_Down_Code

I was thinking along the Charindex but cant seem to get it right.

View 4 Replies View Related

Integration Services :: Query SSIS Packages Details From File System

May 1, 2015

I have around 500 packages (SQL 2005) deployed in file system & all this packages are running on daily basis via SQL agent. Now I need to migrated all 500 packages into SQL server 2008 R2.

There is no inventory to track which package belogs to which team and any other information.

Now, I need a method to query the pakages connection string details with database respective. Is there any method?

View 2 Replies View Related

How To Generate Txt File

May 2, 2006

hi all,

how to generate txt file from sql table. I want text file with respective columns without any seperator between columns. and if for an example a column of int having 5 digits but i want it in text file with 10 digits with remaining all as blanks. guide me how to do this.
thnks in adv

View 6 Replies View Related

Generate A .txt File

Apr 28, 2008

This is my first time on sqlteam forum so a big hello to everyone!!

Firstly I am very noive user of sql to say the least, but i have be requested to create a .txt file

Its for a program that will read the txt file i create to produce a letter i.e I will be extracting, TITLE, FORENAME, SURNAME etc

MR
JOE
BLOGGS

Here is the my code so far, like i said i am a very novice user so try to help me and not condem me for my lack of knowledge!

SELECT
LPA_INPUT.INPUT_TITLE,
LPA_INPUT.INPUT_SURNAME,
LPA_HISTORY.LPA_AMT,
LPA_HISTORY.ELIG_RATE,
LPA_HISTORY.RATE_REBATE,
LPA_HISTORY.RR_AMT,
LPA_HISTORY.LPA_APPLIC,
LPA_HISTORY.LPA_AMT
FROM LPA_HISTORY, LPA_INPUT
WHERE LPA_HISTORY.CLAIM_NO = LPA_INPUT.CLAIM_NO
----------------------------------------------------
Iv been asked to have these eight fields looping over and over for all the records in the database, So im not to how to do that and how to generate it in a txt file?!

Keith

View 5 Replies View Related

Add 2 Separate Columns From Separate Tables Using Trigger

Feb 15, 2012

I am trying to add 2 separate columns from separate tables i.e column1 should be added to column 2 when inserted and I want to use a trigger but i don't know the syntax to use...

View 14 Replies View Related

Service Account Details Not Accepted

Aug 8, 2015

just trying to run the install and cant get passed the service account page as unsure of the details.

im using the Clustered Instance lab/guide where it says that the account details are as follows:

SQL2K8WKSSQL2K8R2SVC for database agent
SQL2K8WKSSQLAgent2K8R2SVC for agent

but get errors when use these.

View 3 Replies View Related

Generate SQL Scripts To File Using DTS

Dec 20, 2001

Hi everybody
EM has ability to Generate SQL Scripts to file(S)
I traced it with profiler but can not see how Sql server output objects to file(s)

I want to run DTS and sript all procedures to files every night
I don't want to use
xp_cmdshell 'osql -UTheUser myPass-P -Qsp_helptext 'Mystproc -oc:est.txt'
Could it be done another way ?

View 3 Replies View Related

Generate Script File

Apr 23, 2003

i want to generate a sql script file along with the data

how to generate it?

View 12 Replies View Related

Generate A Strong Name Key File

May 22, 2006

I am a Newbie to programming and databases and would like to create a simple program for doing full text searching on a SQL database.

I have downloaded and installed Visual Basic 2005 Express, Web Developer 2005 Express, and SQL Server 2005 Express. I have watched several hours of video tutorials and done numerous tutorials. I feel I am making progress and having a lot of fun. My machine is running XP home edition.

I have found the following resource that looks like a good place for me to start with creating a full text search program:

€œSQL Server 2005 Books Online
Item Finder Sample
http://msdn2.microsoft.com/en-us/library/ms160844.aspx

However I am stuck at the beginning with trying to €œgenerate a strong name key file.€? I don€™t know how to €œopen a command prompt€? (I did confess to being a Newbie!!). I searched the database for this forum and found a relevant thread stating that €œSQLCMD is the command-line utility for SQL Server and is included with SQL Server 2005 Express Edition.€? I found the SQLCMD program on my computer but when I opened it, it does appear to provide the options listed below in the tutorial (i.e., €œclick start,€? €œPoint to all programs,€? etc.).

Initially here is what I need based on the first section of the tutorial:

Building the Sample

If you have not already created a strong name key file, generate the key file using the following instructions.

To generate a strong name key file

Open a Microsoft Visual Studio 2005 command prompt. ClickStart, point toAll Programs, point toMicrosoft .NET Framework SDK 2.0, and then clickSDK Command Prompt.

-- or --

Open a Microsoft .NET Framework command prompt. ClickStart, point toAll Programs, point toMicrosoft .NET Framework SDK 2.0, and then clickSDK Command Prompt.

Use the change directory command (CD) to change the current directory of the command prompt window to the folder where the samples are installed.
Note:
To determine the folder where samples are located, click theStartbutton, point toAll Programs, point toMicrosoft SQL Server 2005, point toDocumentation and Tutorials, and then clickSamples Directory. If the default installation location was used, the samples are located in <system_drive>:Program FilesMicrosoft SQL Server90Samples.

At the command prompt, run the following command to generate the key file:
sn -k SampleKey.snk

Important:
For more information about the strong-name key pair, see "Security Briefs: Strong Names and Security in the .NET Framework" in the .NET Development Center on MSDN.

How do I complete this initial step of generating a strong name key file for the tutorial? I guess I am missing something simple and once I get past this I will be able to complete the tutorial. Any help will be greatly appreciated.


View 7 Replies View Related

Process Of Generate Xml File

May 23, 2008



hi i was trying to generate a .xml file by using this command below



DECLARE @Table varchar(20),@filename varchar(50), @SQL nvarchar(4000)

SET @Table ='Authors'

SELECT TOP 1 @Filename = au_fname FROM Authors

SET @FileName = 'C:' + @Table+'_'+@FileName+ '.xml'

SELECT @FileName

DECLARE @Table varchar(20),@filename varchar(50), @SQL nvarchar(4000)

SET @Table ='Authors'

SELECT TOP 1 @Filename = au_fname FROM Authors

SET @FileName = 'C:' + @Table+'_'+@FileName+ '.xml'

SELECT @FileName



SET @SQL = 'EXEC master..xp_cmdshell '+ ''''+'bcp'+ ' "SELECT ''au_fname '' AS ''Name/First'', au_lname AS ''Name/Last '' FROM pubs.dbo.authors ORDER BY au_lname FOR XML PATH (''Books''), ROOT(''Authors''), TYPE, ELEMENTS " queryout '+ @FileName + ' -c -SlocalHost -Usa -P'+ ''' '

SELECT @SQL

EXEC(@SQL)




i got an error saying

Msg 102, Level 15, State 1, Line 1

Incorrect syntax near 'au_fname'.

i could no tfigure it out my mind window is closed.can any one help me put to find a bug.


many many thanks

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved