Copy query output data from SQL SERVER 2012 and paste to Excel - sql-server

I have a column that has data type varchar(max). Some rows in that column have long text data. When I copy the SQL result set from that column and paste to excel, the row gets split into multiple rows. I want to past in sunch a way that single cell data from SQL server go to
single cell in excel. I am not sure how to fix that problem. Any suggestion would be appreciated. Thank you

Use Excel Import from SQL Server feature. It should import each row of data into a single row in Excel and each column into a single column.

You can try to select data directly into excel spreadsheet.
Check this for more details
http://blog.waynesheffield.com/wayne/code-library/ad-hoc-querying/#codesyntax_5

Related

SSIS Data Flow OLE DB To Excel Nvarchar Size Issue

Hopefully, this is not an ignorant question as I am still working to build SSIS Skills.
I Have a package that takes an excel sheet and loads it into an SSMS SQL table so that I can run analysis and update statements to the data. I am now looking to load that SQL table back into an Excel sheet. I have made an excel sheet as a template of a replication of the SQL table.
The issue I am now having is I have a field named "Comment" that datatype is Nvarchar(MAX) in my SQL table. This column does contain NULL values as well. When I am trying to load these back to the Excel column I am having an error.
[Excel Destination [28]] Error: An error occurred while setting up a binding for the "Comment" column. The binding status was "DT_NTEXT".
I thought perhaps I could do a Data Conversion to a string with the max character (Which is 757) but it truncates and errors on that size.
This data came from an excel column so I would think I can load it back to a column.
Thanks for the help!!
Previously I thought that Excel does not allow exporting data with longer than 255 characters. After running several experiments, exporting DT_NTEXT values to Excel can be done using SSIS:
You should create an Excel file with one dummy row that contains long text values (> 255) then use this Excel as a destination. If the Excel contains previous data, make sure to add this dummy row directly after the file header and add ;IMEX=1 to the OLE DB connectionstring.

Ignoring column from Excel file while importing to SQL Server

I have multiple Excel files that have the same format. I need to import them into SQL Server.
The issue I currently have is that there are two text columns that I need to ignore completely as they are free text and the character length for some rows exceeds what the server allows me to import which results in a truncation error.
Because I don't need these columns for my analysis, the table I'm importing to doesn't include these columns but for some reason the SSIS packages still picks up those columns and cuts the import job halfway through.
I tried using max character length for those columns which still results in the truncation error.
I need to create an SSIS package that ignores the two columns completely without deleting the columns from Excel.
You can specify which columns you need to ignore from the Edit Mappings dialog.
I have added the image for your reference:
If you just create the SSIS package in SSDT the Excel file can be queried to return only the required columns. In the package, create an Excel Connection Manager using the Excel file. Then on the Control Flow of the package add a Data Flow Task that has an Excel Source component in it. On this source, change the data access mode to SQL command and the file can then be queried similar to SQL. In the following example TabName is the name of the Excel tab containing the data that will be returned. If either the tab or any column names contain spaces they will need to be enclosed in square brackets, i.e. TabName would be [Tab Name].
Import/Export Wizard
Since you mentioned in the comments that you are using SQL Server Import/Export Wizard. You can solve that if you have a fixed columns (range) that you are looking to import (example: first 10 columns).
In Import/Export wizard, after selecting destination options you will be asked if you want to read from tables or query:
Select the query option, then use a simple select query and specify the columns range after the sheet name. As example:
SELECT * FROM [Sheet1$A:C]
The query above will read from the first 3 columns in Sheet1 since A:C represent the range between first column A and third column C.
Now, you can check the columns from the Edit Mappings dialog:
SSIS
You can use the same logic within SSIS package, just write the same SQL command in the Excel Source after changing the Access Mode to SQL Command.
The solution is simple. I needed to write a query that will exclude the columns. So instead of selecting "Copy data from one or more tables" you select "write a query" and exclude the columns you don't need. This one worked 100%

SQL Server Not Recognizing Text in varchar

I'm using Microsoft SQL Server Management Studio. I have a spreadsheet that I'm manually importing into an existing table in an AZURE database using the SQL Server Import and Export Studio.
The column I'm hitting the issue with is a varchar(55). It's coming from a spreadsheet (.xlsx) where all the cells are formatted as "General" and the data can be a string of numbers "1234567" or a string of text then numbers "companyxyz_1234567."
If the first few rows in this column of the spreadsheet are a string of text then numbers (companyxyz_123456) everything works fine.
However, if the first few rows in this column of the spreadsheet are numeric only (1234567), then every entry in the column that contains text returns as NULL instead of the value once imported into the table.
I'm new to this system and have some basic knowledge in SQL and SQL coding but I'm at a loss here.
Any help is appreciated!
There's no Error return's all records are successfully inserted.
Here's the simulation:
insert into table_3 (sampletext) values ('1234567')
Record has been inserted.
insert into table_3 (sampletext) values (1234567)
Also inserted with the following sampletext varchar(55)
My suggestion is:
Kindly check the data of your excel file by:
Copy and paste the specific cell into notepad, maybe it had some
characters include on it.

How to avoid 'number stored as text' error when exporting data from SQL Server to Excel using SSIS DatFlowTask

I am using a SSIS Data Flow Task to export data from SQL Server to an Excel destination, but while exporting it converts int values to "Numbers Stored As Text" Excel cells and every cell gets this error "number stored as text" with a green tag.
Can you please guide me how I can export my int values from SQL Server to a number in Excel?
Thanks
The solution that has worked for me is to add numeric values to the numeric columns so that it knows to format the destination as numeric in your template sheet. You can either hide the values or overwrite them with the new data that you are posting to the file.
So essentially just add a row with template data and formatting and hide that row. When the import occurs, it will copy the first (hidden) row formatting.
as you are importing the values to a excel their should be data conversion, if not you will get an error.
Please see the link below for more details:
Error converting data types when importing from Excel to SQL Server 2008
Warm Regards
Safi

Importing data from MS Excel to SQL Server 2008 R2

I've a Microsoft Excel file with 25 columns and I used the data import wizard on SQL Server 2008 R2 studio to import it to already existing table. But, it only maps 14 columns and ignores the rest. Does it have a column number limit or there is a problem with my data?
Can you give some example of your data?
In the mean time... When you're performing your import, I assume you are reaching the Select Source Tables and Views Page;
At this stage, you can edit your column mappings by pressing the Edit Mappings button. This will show the following screen;
Make sure that all your columns are selected there.
Also, on the following screen, it will warn of any mismatches in data;
Are you seeing any warnings here?
I'm not familiar much with SQL Server, but according to this: Excel file Import to Sql server 2008 - column limit for Excel is 255 which is far beyond your numbers. Most likely problem is in your data, but without having the example it's impossible to say what's wrong.
You can do the other way around.
Step 1. Import sheet in a new table.
Step 2. Use Bulk Query to insert into your prefered table
I think this will solve your Problem.
Try to create the Excel columns and table structure in the same format and structure as ms sql table is. Open the excel select the row (whole row by clicking on row number) select the whole data till end of the data (selected first row to last row). press ctrl+c
edit the ms sql table, go to last row where you can find blank.
Select that row by clicking on row button and press ctrl+v.
Done you're excel data will be inserted into sql table.
I tried it in MS SQL 2008

Resources