Quote Encapsulate Output During BCP Export To Csv File
Apr 4, 2007
I'm exporting from a View using the bcp utility. I have the -t switch set for comma delimited. My first 3 columns are integers, but the rest of my columns need to be wrapped in double quotes because some of the string data contains commas. I can't find a simple way to do this, although I keep coming across notes about format files without any good examples.
I have a table which has few columns as Numeric value. I need to export the output into a csv file as a report with column headers. I have used bcp command. Here column name and Column Header name is the same. The BCP query which i have used is Below
i am running sql server 2000 on windows 2000. i have a need to export a view and delimit the columns with double quotes as it has imbedded commas in the columns, how do i do this??
I'm having trouble importing a CSV file into SQL using SSIS. The trouble seems to stem from truncation and from quote encapsulated fields.
Firstly it's worth noting that some of the data within the quotes contains the separator. E.g.
12,"some text, and a comma",34
Thankfully SSIS seems to cope with that by specifying " as the Text Qualifier. My next problem was that the SSIS Import and Export Wizard gave an error: "failed because truncation occurred". But I fixed this by specifying the OutputColumnWidth for the NCHAR and NVARCHAR type columns to be the width from the table definition.
But now I have another problem with the length of fields. Consider the following where the center column is NCHAR (22)
101,"some text, and a comma",303 102,"some ""quoted text"" bye",303
The first row has the correct width (once the encapsulating quotes are stripped out), but the second row does not, because it seems that when I exported the table the export wizard escaped the quote characters within encapsulated strings using quote characters. So I am back to getting the "truncation occurred" error. How can I get around this within SSIS?
I've been installing SQL with a unattended install for awhile, and have the following settings in my install_configuration.ini file. I happened to come across a password with a quote in it today, what is the proper way to escape that quote? I've tried the standard backslash method, and found that to not work.
; SQL Server Agent Service Account AGTSVCACCOUNT="DomainUserName" AGTSVCPASSWORD="PasswordWith"AQuoteInIt" ; SQL Server Service Account SQLSVCACCOUNT="DomainUserName" SQLSVCPASSWORD="PasswordWith"AQuoteInIt" ; SSRS Service Account RSSVCACCOUNT="DomainUserName" RSSVCPASSWORD="PasswordWith"AQuoteInIt"
The cool thing is the install apparently tries a few time to authenticate before giving up, because it ends up locking out the account each time.
I have a table that has an encrypted account number column. In order to give users access to the data BUT not access to the symmetric key used to encrypt the data, I'm trying to implement the following:
I would like to wrap the following code in a function and reuse it. I use this code in many triggers.
DECLARE @Action as char(1); SET @Action = (CASE WHEN EXISTS(SELECT * FROM INSERTED) AND EXISTS(SELECT * FROM DELETED) THEN 'U' -- Set Action to Updated. WHEN EXISTS(SELECT * FROM INSERTED) THEN 'I' -- Set Action to Insert. WHEN EXISTS(SELECT * FROM DELETED) THEN 'D' -- Set Action to Deleted. ELSE NULL -- Skip. It may have been a "failed delete". END)
Is it possible to write a function and pass the INSERTED and DELETED logical tables to it?
Once again, SSIS is giving me a 'F.U.N.' time (ask for definition of the F.U.N. acronym another time ).
I have a relatively simple task - create an excel spreadsheet with 3 columns of data - Id, Description and Sales. ID and Description are text, sales is int.
So my SP aggregates and creates my resultset in my OLE DB Source in the Data Flow. It proceeds to the Excel destination, and that all seems fine. My issue is that the data is being written as text. Looking at the excel destination in Advanced editor: the Excel Destination Input, Input columns are formatted as I expected: DT_WSTR 8 for the ID, DT_WSTR 100 for the Description and DT_I4 for the Sales. Excel Destination Input, External columns refuse to fall in line, though. They are all listed as DT_WSTR 255.
The target excel spreadsheet is being created from a template file. That template file has header columns. The target column for the Sales has the entire column formatted to NUMBER (0 decimals). Yet to now avail.
When I check the spreadsheet, the column has retained the cell formatting, and I have a 'I' pop-up to inform me that 'someone' has inserted text data into the number column (even though the data IS number).
Since the SP spits out INT, it isn't a case of receiving a text value, imho. While trying to change the external column data type in the advanced editor, SSIS is quite happy to let me change the value for the Sales output to DT_I4, apply, and ok. Then, when I open it immedaitely aftgerwards, it has reverted to the DT_WSTR's! AArrgh. If is can't handle it, at least tell me when I try and change it. don't let me change it, and then revert back without telling me! Grumble grumble...
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
What is the easiest way to accomplish this task with SSIS?
Basically I have a stored procedure that unions multiple queries between databases. I need to be able to export this to a text file on a daily basis and add a total records: row to the end of the text file.
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.
I am using BCP to export a Table to a TAB delimited file. This works great, but in some fields a NULL in the Table is being exported as a character zero in the Tab file. I confirmed this by looking at the Tab file with a Hex editor.
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?
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.
Hi all! My question is quite simple I think... I am directing the result of my query to an output file my problem is how to set the rowsize of my output file to more than 256 (that is the default maximum)? My query result is quite long per row (assuming one column) in query anlyzer, I can easily adjust the result to more than 256 but the result in the output file is truncated because the ouput is more than 256 characters per row...how can I set (in the code) the length of the row of the result in the output file... thanks for the help... this is quite urgent...
I'm not new to sql server, but making my first experience with xml in sql server 2005.
I have a query like this (based on <Table> with neccessary data):
SELECT TAG, PARENT, <columns...> FROM <Table> FOR XML EXPLICIT
This query creates a xml file exactly as i need it when i execute it in Management Studio. Well, with one exception. It does not write the <xml...> tag at the beginning of the xml file. But i'm sure i get that in there somewho else. What i need to do now is get that output to a file on disk. And that's where my problem starts.
I tried SQLCMD within Management Studio, but that doesn't accept the ':XML ON' tag and ignores it. the resulting file written is not usable, as it also contains query summary information.
I have a header row and a footer row and a bunch of detail data I have managed to split up into temp db tables, know i need to know what would I need to do to write the header , detail data and footer to the same file after all my validations have completed , this would be a different file then the one I originally imported all the data from (append to text delimited file). Idealy I would only like to change the header and footer from the original file.
Any ideas - I am thinking of writing a application that does this for me and just executing it from SSIS but I would really like to stick with standard SSIS components first before starting to write my own stuff.
Is it possible to send the output of a query to a text file in a stored procedure? When I run stored procedure in Query Analyzer I am able to do that and I am wondering if this is possible in a automated way?
Hi, Is it the way use T-SQL to select text data from table and add them to the file on a HD, but save the information in the file without changes anything that was in the file before, another words without rewriting, just add?
I have a query something like this: select "bcp EISAT_08_18.."+name +" OUT C:"+ name+".TXT -c -t -SCJACOBI" from sysobjects where type = 'U' ORDER BY NAME When I run the above query I want to output the result of the query to a file. Can someone help me on that?
Hi all, When I run a query in the sql query analyzer I need to write the output of that query in to another file. In Oracle its spool. Can someone help me on this please. Thank you!!!
I am doing a ISQL join on 4 tables that creates a few million record output. This causes some memory grief on my laptop. How do I have my query output to my c: drive??
I have a DTS package that outputs the contents of a view into a CSV file, however when the view has no records, an empty file is still created, is there any way to stop this.
I dont want the file to be created if the view has no records.
In case i have a script file containt tables, functions, ... when i use Query Analyzer to run this file, the result output in a window. Now i want this result output to a file named logfile.txt. How can i do that?