Export Data from SQL Server to FlatFile using SSIS - sql-server

I am learning SSIS.
Had a question regarding the same.
I have a SQL Table
`(File id, File name, File content)
(1,abc,hi)
(2,ghi,how)
(3,ghi,you)`
I want to give an input in SSIS:
File ID and Destination Folder
Output:
I want to export 'File Content' in the destination folder as FileName.txt.
Example: From the above table if I give input as
File ID=1
I want all the files
(file ID>1)
in the destination folder as
abc.txt
def.txt
ghi.txt
having the respective File Content in them.
Can you please help me with this?
I have trued using Script task but its not giving the right output.
Thank You!!

Related

Importing *.DAT file into SQL server

I am trying to import *.DAT file(as flat file source) into sql server using SQL server import and export wizard. It has DC4 as delimiter which is causing error while trying to separate the columns and their respective data and importing them in sql server.
Are there any setting changes to be made during the importing process?
If you don't have to use the wizard, you can script it like:
BULK INSERT [your_database].[your_schema].[your_table]
FROM 'your file location.dat'
WITH (ROWTERMINATOR='0x04' -- DC4 char
,MAXERRORS=0
,FIELDTERMINATOR='รพ'
,TABLOCK
,CodePage='RAW'
)
The wizard uses SSIS under the hood. Instead of executing it directly, chose CrLF as row delimiter, then chose to save it as file. Open the file and edit it using any text editor. It's a simple xml file.
It's not clear whether 0x04 is the column delimiter or the row delimiter. Assuming it's the row delimiter,
Replace all instances of
Delimiter="_x000D__x000A_"
with
Delimiter="_x0004_"
there're two instances: DTS:HeaderRowDelimiter and DTS:ColumnDelimiter
Save the file and execute it with a double clik or "Open with: Execute package utility". I tested the solution on my PC using an account with limited permissions.

SSIS - Create Summary Output File

I would like to use SSIS in orded to perform tranformations on multiple files (CSVs, Excels) which are comming from various datasources and the output should be always CSV files in certain structure.
One of the requirement after performing tranformation steps is to create a output summary file (MANIFEST FILE) about the results of the process in following structure.
BATCH_ID|EXTRACTED_FILE_NAME|MODEL_TYPE|RECORD_COUNT|TOTAL_QTY|GENERATED_ON_TE|CONTENTS_FROM_DATE|CONTENTS_TO_DATE|WORKSET_ID|FILE_STATUS|FILE_STATUS_TS
000005|NSL_B_YFRCARRAB0_PRODUCT_MASTER_20171122.txt|B|829||20171122121525|||||
Important columns:
Batch ID: ID of run
EXTRACTED_FILE_NAME: Name of created CSV file by SSIS (output file)
RECORD_COUNT: Number of rows in output file
TOTAL_QTY: SUM of column QTY
GENERATED_ON_TE: When the file was generated
STATUS_TS: Status - OK / FAIL
Is this output possible to achive in SSIS? Can I create it without using script compontent? If I have to use script compontent, can you navigate me little bit?
Many thanks,
Martin!

SSIS error handling: redirect rows that have zip code field more than 5 from a flat file

I have been given a task to load a simple flat file into another using ssis package. The source flat file contains a zip code field, now my task is to extract and load into another flat file that accepts only the ones with correct zip code which is 5 digit zip code , and redirect the invalid rows to a new file.
Since I am new to SSIS, any help or ideas is much appreciated.
You can add a derived column which determines the length of the field. Then you can add a conditional split based on that column. <= 5 goes the good path, > 5 goes the reject path.

How to get path of a document using sql server 2012

I am using an document management application which uses SQL Server 2012.
I am trying to fetch document names along with its path. For example,
If my document name is test.txt and it is under folder structure A/B/C, my output should be A/B/C/test.txt.
Could anyone please help me with a query?
Table name: DTree
DataId Name
======= ========
12345 test.txt
If the folder structure is not in the database, or you don't have a mechanism to tell SQL what the file path is, I don't think you can do this.
You could have a file named test.txt in every single folder, so you will need to have the file path explicitly. If the file path is stored in that table as A/B/C, you can just concatenate the file path with the file name like
SELECT filepath + '/' + filename

How to view 'data' file which is included by .odb database file?

I am trying to extract the data from .odb database file. For this, at first I unzipped the .odb file and then tried to read 'data' file came from this unzipped. But I guess there is an encoding problem during the reading process. I get some meaningless symbols. As far I search, this file could be a binary file. By the way, I can not see the extension of the 'data' file. I wonder how to read file to exract data?
i'm brazilian, and i saw this question without a answer.
i'm python user and i did this:
try to open the file that contains database *.odb
___________________________a file.py________________________
import sys, zipfile
myfile = zipfile.ZipFile(yourfile.odb)
listoffiles = myfile.infolist()
for s in listoffiles:
if s.orig_filename == "database/data":
print(bh.decode("utf-8", "ignore"))
____________________________eof_________________________________
my table is very simple, but it may help.
I've found this jointing parts from several websites.
as you see, an odb file is simply a zipped file that contains a xml file that contains a table information "content.xml" but only table information.
the content of database is in database/data. the values are stored here. you can decode with decode on python.
thanks to http://www.linuxjournal.com/ too, were i found some scripts

Resources