convert text file to Excel sheet using SSDT - sql

I have requirement where I need to convert text file to Excel Sheet using SSDT.
I have idea how to do like I
Step 1. have to upload data to sql server any table
and then Step 2. from Sql Server to Excel Spread sheet.
But I would like to do it in only one step that is Convert Directly from Text file to Excel Sheet without sending it to the table in Sql server using SSDT. Is there any way that I could do in one Step. Thank you in advance.

If i am understanding your question correctly, it is possible to use the import data wizard in SSMS to convert a text file to an excel file. You can save the wizard as an SSIS package also if you need to do the conversion programatically.
right click on any database in your server, hover over 'tasks' and select 'import data...'
in 'data source' drop down, select 'flat file source'. click next.
browse to the file you want to import. you can preview your flat file from here to make sure its rows and columns have been detected correctly. click next.
in 'destination' drop down, select 'microsoft excel'. browse to the destination folder and name your file. click next.
here you can rename columns and preview the end result. click next.
map your data types and determine if you want the package to fail if you encounter an error. click next.
here you can choose to save as an SSIS package or just run one time. you can now click through the rest depending on your choice to finish the sequence.
This is a very brief overview. for more detailed information, you can go here: https://learn.microsoft.com/en-us/sql/integration-services/import-export-data/import-and-export-data-with-the-sql-server-import-and-export-wizard?view=sql-server-2017
I hope this helps.

Related

Question about adding column to data source and destination in SSIS package

I have a data source which is something like
select
patient_id
from patient_table
the destination is a CSV file.
Now I want to add patient_name to both the source and the destination.
I go to the source and I change the query to
select
patient_id,
patient_name
from patient_table
After I add this when I click on columns the patient_name column is not there.
The same thing happens for my destination. I have a flat file destination with the patient_id column so I add the patient_name column to the actual .csv file and that column is not reflected on the flat file connection manager.
The only way that I've been able to get these new columns to show up is to delete the data flow task, connection managers, sources and destinations and to create everything new from scratch.
Is there any other way to do this?
I just created a simple data flow with an OLE DB source and a flat file destination. After adding a second column to the OLE DB source I double clicked my flat file destination which opened the Flat File Destination Editor. Clicking UPDATE added the 2nd column to the flat file connection.
Are you using the latest tooling available to modify SSIS packages?
I don't have an SSDT installation handy right now, so I'll do the best I can without screenshots (and working from memory).
In the Source object, after you add the column to the text of your query, click on Columns, which you already know. Your new column doesn't show up in the list at the bottom yet, which you also know. Up in the top of that window, there's a grid representation of the result set from the query. Find your new column in that grid and check the box to tell the connector you want that column to enter the data flow.
Now go to the connection manager for the .csv file. Add the new column there.
Once it's in the connection manager, now you should be able to map it in the destination object.
There's a possibility that you'll have to click on the arrow or arrows in your data flow task and map the new column in those, too, but it doesn't always happen like that. I haven't taken the time to figure out why that's necessary sometimes and not others, but you'll know right away because the arrows will have red Xs on them.
And that should get you there.

ssms -- how to create table same as table on another server without data

I need to create a table similar to the one on another server.
How can I do this using ssms?
I am able to copy table from one server to another with data using Tasks | Export data but not sure how to create without data.
Right click on the database you want the shell of in the SSMS gui.
Choose Tasks ---> Generate Scripts
There is a glossary of sorts on the left side of the panel
Under Introduction: Choose Next
Under Choose Objects: (1)Check Select Specific Objects. (2) Expand the "Tables" section. (3) Check the table(s) you want to generate.
Under Set Scripting Options: (1)Choose Save to File.
(2) Set the Destination Drive and location.
(3) Click Advanced
There are lots of options under advanced start with these two, you may need to adjust others, but not likely.
(1) Script for Server Version - Set to the server version you will be restoring the empty database, OR the same version as the source database.
(2) Types of data to script - Choose Schema Only
Click OK
Click Next
Click Next
Should get all green icons on success.
Click finish.
Go to Destination database, open your file, execute the query.

How to connect an Excel file to an Access Database

I have created a query in an Access database and exported the query result into an Excel file. Now, I want to connect that Excel file to the Access database (or to that query) so that whenever some fields are updated in database, those changes would be automatically updated in the exported Excel file (report). What would be the best way to do it?
Thanks
You can create a link between Excel and an Access table or query by going to the Data tab on Excel and clicking the "From Access" icon.
Alternatively if there is a trigger inside access that you can use to update data (or if you don't need real time updates just hourly or daily ones), you could have access programmatically re-export.
If you want to work with data in Access, but still maintain the data in Excel, you need to link to the data rather than import it. Follow these steps:
Create a blank database or open an existing file in Access.
Select File, Get External Data, Link Tables.
Select Microsoft Excel as the file type.
Select a worksheet or named range to import, and then
click Next. You can import only one worksheet or named range at a
time, and each one will become an Access table.
In the next dialog box, select or deselect the check box First Row
Contains Column Headings, depending on whether your worksheet has
headings. Then click Next.
Enter a name for the table (or accept the default name that Access
suggests), click Finish, and click OK.
Now you have an Access table that looks almost exactly like the imported table. The advantage is that it maintains a live link to the Excel worksheet and can be edited in either application.

I can't import a text data file into SQL Server 2008 with the import wizard

I have a problem while importing a text data file into a SQL Server 2008 database, the text file structure like this:
First Line
Second Line
Third Line
Every time I try to import the text file, it creates an error
in management studios, rightclick on database, go task --> select import data. following the wizard steps by clicking next. In choose data source, select flat file source. Click on the browse button to point to the location of the text file. Click on next, in the "choose a destination" make sure ur sql server is selected. click next again. The important part in the "select table source", if you have a table existing that you want to import to, select the table from destination. Else sql server will create a table with the same name as your text file name. Click next and finish.

SSIS 2005: "Append rows to the destination table" is greyed out. Why?

In SQL Server 2005, Import Data (SSIS), my desire is to import a text file and have it append to an existing table. The first time through the wizard on the Column Mappings step I swear the Append rows to the destination table radio button was enabled. But, now, it's disabled (grey) and even re-starting the wizard won't cause it to re-enable.
Is there some secret/magic I don't know about? How do I get that option to re-enable so that I can append (rather than Create destination table)?
I know what you're missing... because I once missed it too!
From the screen, "Select Source Tables and Views",
there is a "destination" drop-down menu on the right side.
Select your table from this drop-down,
then click on the "Edit Mappings" button.
Now the append option will be enabled!
In my experience, if the table you're importing into doesn't exist at the time you're going through the "SSIS Import and Export Wizard", you won't have the option to Append; if the table does exist at the time you're going through the wizard, the option is available.
If you do choose the "Create table" option, the wizard just builds the SSIS package with an Execute SQL task that builds the table prior to the data flow that loads the data. So, you can always just remove the task in the resulting package and you'll get "Append" by default.
The name of the table must be preceded with schema name ("dbo."). Otherwise the wizard didn't find it in my case.