I have an Execl file. I want to convert it into a text file. Is it possible in SQL Server?
As you said, you get the excels on daily basis; why don't you create an SSIS task which will take all the files from a particular location where all these excels are dumped and convert it through a DFT. You can then schedule this package on SQL server agent to run on regular basis.
P.S. I am assuming you're familiar with SSIS.
Related
I have an SSIS package created using SSDT and running as a job on SQL Server 2014.
This SSIS package retrieves an Excel file (.xlsx) from a specific folder and exports its content into a specific table on my SQL Server database. The package runs fine.
My Data Flow is in the following sequence:
Import Excel file from folder
Apply a Conditional Split to split data with today's date
Export the data into the SQL Server table in the database
Here is my problem:
I will now have 4 additional Excel files into that folder and they will need to be exported into that same SQL Server table.
So what is the best way forward to achieve this (assuming all of them are possible solutions):
Rewrite 4 additional SSIS packages from scratch?
Use “Save As” existing package with a new name (4 times) and modify the file name to be retrieved?
Modify my existing SSIS package to accommodate for the additional 4 Excel files?
Any help would appreciated.
Assuming the 4 excel files are the same structure and going to the same table, you'll want to use the ForEach loop for each file in the folder.
SentryOne has a good example of looping through each file in a folder and archiving. I imagine it can be adjusted for your use case.
I have a table in SQL Server where I need to insert data on regular base. Each day I perform same task importing data manually, it makes me feel tedious so I need your help. Is it possible to send data from CSV file to SQL Server's existing table without doing manual procedure.
Or using python to create a scrip that send data from CSV file to SQL Server at fixed time automatically.
First you have to create a python script that inserts data into SQL server after reading CSV file. Then you should create a CRON job on your server that runs this script regularly. This might be a possible solution for your problem.
I am exporting data using the Task, Export Data menu in SSMS. I want to save the export as an SSIS package. My only issue is I need today's date in the filename. I know in SSIS you can do this in an expression.
But when typing filename in the box how can I write this out?
PtSurveyList_'getdate()'?
what would be the correct syntax for the system to know I want the getdate() function not the actual word?
The import/export wizard is a streamlined editor that creates an SSIS package. It's no different than using BIDS/SSDT to create a package (unless you're using SQL Server Express Edition wherein you are not licensed to save the resultant SSIS package, only execute it).
To answer your question, you cannot accomplish what you are asking for by directly using the import/export wizard.
Option 1
Use the import export wizard, save your SSIS package and then edit it with BIDS/SSDT. Unless you're on 2005/2008, you should be able to download the correct version of SSDT from the Microsoft website and edit your package locally. In the screenshot provided, that is not where you would apply the logic, you'd need to apply an Expression to the Flat File Connection Manager's ConnectionString property.
An even better approach is to not build out the date logic within the expression. This becomes brittle in situations where the server was down for a day due to patching, file was late being delivered, etc and now you have two files to process and what you built only looks for "today's" file. Now what - change the file name; change server time, edit your package? Instead, use a Foreach (file) Enumerator to pick up the file for processing. You can use a wildcard in the File Specification for it to restrict to only the PTSurveyList files. And then, obviously, use a File System Task to archive/move the processed file out of the source folder so you don't double process.
Option 2
Use the import/export wizard as is. It always looks for a file called PTSurveyList.csv. If you need today's date attached to the data you import, add a column to the target table with a default constraint of GETDATE(). That will ensure you have the processed/today's date in the table.
You then need to use OS level tooling/scripting/SQL Agent to handle identifying the current days file and any file manipulation from there. I'd go PowerShell but you can accomplish this with DOS batch scripting although it'll be uglier.
Pseudologic
Find most recent PTSurveyList_yyyymmdd.csv
Copy with overwrite to PTSurveyList.csv
Run SSIS package
Move to Archive/PTSurveyList_yyyymmdd.csv
Delete PTSurveyList.csv
A "trick" to solving the dynamic date via xp_cmdshell is to dynamically build the execution string. Approximately
DECLARE #Command nvarchar(4000);
SELECT #Command = N'EXEC master.dbo.xp_cmdshell ''rename "C:\CentOS_Share\PTSurveyList_.csv" "PTSurveyList_' + CONVERT(char(10), CURRENT_TIMESTAMP, 121) + '.csv"''';
EXEC(#command);
Of course, then you can run into the double quote issue with xp_cmdshell
I need to export the data from a particular table in my database to Excel files (.xls/.xlsx) that will be located into a shared folder into my network. Now the situation is like this -
I need to use SQL SERVER Agent Jobs.
2.I need to generate a new excel file in every 2 minutes that will contain the refreshed data.
I am using sql server 2008 that doesn't include BI development studio. I'm clueless how to solve this situation. First, I'm not sure how to export the data using jobs because every possible ways I tried had some issues with the OLEDB connection. The 'sp_makewebtask' is also not available in SQL 2008. And I'm also confused how to dynamically generate the names of the files.
Any reference or solution will be helpful.
Follow the steps given below :
1) Make a stored procedure that creates a temporary table and insert records to it.
2) Make a stored procedure that read records from that temporary table and writes to file. You can use this link : clickhere
3) Create an SQL-job that execute step 1 and step 2 sequentially.
I found a better way out. I have created a SSIS(SQL Server Integration Services) package to automate the whole Export to Excel task. Then I deployed that package using SQL Server Agent Jobs. This is a more neat and clean solution as I found.
I have an SQL query that generates a result regarding the daily data from the database. I want a csv formatted file to be generated everyday with this query and saved in a folder. Is there any way I can do this?
NOTE: I am using SQL Server Management Studio 2008 with regards to the DB.
This is a question about bulk export which well documented in MSDN - Importing and Exporting Bulk Data