I'm attempting to copy a query result from SSMS to excel. I selected "copy with headers" and pasted it into Excel. My data set has 9 columns. When I paste the data into excel, information from column 9 ends spread across columns 9, 10 and 1 It looks like this:
A B C D E F G H I -Column Heading
A B C D E F G H I I -Data
I
(blank row)
I've reviewed the query results in SSMS and this is not occurring in the original data. When the value in column F is NULL the additional row and information in column 10 do not occur. Thus far I have tried the following:
-When I remove column 9 from the query then copy & paste, column 8 is spread across 8, 9, and 1.
-I've also created a brand new spreadsheet, made sure to clear any formatting and tried the copy & paste.
-I saved the query results as a .csv file and imported it into Excel. I still got the same result.
-I copied the columns individually one at a time. The the information in the 8th column ends up on two lines paired with the other columns of the next row. So each item in column 8 becomes another row offset downwards until there are many more values in column 8 than other columns. Where the value in column 8 is NULL, this does not occur.
-I removed all the other items from the query result so that only the values of columns 8 and 9 are returned. All information from column 9 ends up in column 8 followed by a blank row.
Returning 8 alone, each item returned ends up on two rows.
Returning 9 alone, the data is pasted correctly.
The headers are always in the right place. From what I can surmise, the data in column 8 is the culprit here. The data type is a varchar(max) which allows nulls. The information included is in the following format,
(TC Date & Time, Last Name, First Name) Comments
Moving SSMS query results into Excel to make tables is something I do frequently. However I have never before encountered this result. Hopefully my explanation is thorough enough so someone can tell me how to correct this error. Thanks!
Replace feed and Carriage returns from your dataset before you can paste into Excel, Try something like this on the columns you are having issues and then try to paste it in excel:
SELECT REPLACE(REPLACE(yourcolumnname, CHAR(13),' '), CHAR(10),' ')
FROM table
This is probably due to using 'Text to columns' recently in Excel. That splits columns using some rule. Columns need to be set back to 'tab delimited'.
For the offending column:
Data → Text to Columns
Original Data Type: Check Delimited
Click Next
Delimiters: check 'Tab', uncheck anything else.
Click Next
Click Finish
SSMS copy-paste does not preserve data types. Excel tries to parse the string and splits it into additional columns or even lines.
I develop SSMSBoost add-in and we have covered this in our video, which explains 3 different ways of exporting the data into Excel without data loss (data type information is preserved): (Copy-Paste in native excel format, XML export, .dqy Query) https://youtu.be/waDCukeXeLU
Related
I have a flat file which doesn't have the header record. The data except the trailing record is like a fixed width flat file with no delimiters.
Data in flat file looks like:
TOM ROLLS
DAVECHILLS
TOTAL2XYZ
Fixed Width data(first 2 lines as shown in the above flat file data)
ColumnName Start position End position
Name 1 4
Last_name 5 9
I want to load the data(till trailing record) in data_table and the trailing record(starting with Total) in another table. The data in the total table should look like
c1 c2
2 XYZ
For the data table, I am currently using "fixed width" and dividing the data into different column and it is working fine. Can you please help to load this last trailing record in a different table(Total table as discussed above)
You have not provided enough data for me to test because I can find several methods to load one row and accomplish what you are asking but those methods not necessarily work with multiple rows depending on the structure of you source data.
On the surface it appears that you simply need to make another flat file connection and define the starting and end position to extract only the data for the second table.
I am working in SSRS 2017. I have 3 sub reports, each with a USERID key that links them. The basic setup now is a master report with 1 tablix, it pulls a list of all USERIDs and then has 3 columns. Each column has sub report, 1 is a tablix and the other 2 are matrixs. When I run the report the USERID is passed to each of the sub reports and every USER ID has 2 rows, 1 for headers and 1 for data, but all 3 reports show correctly. What I am trying to do is make is it so the headers for each subreport only show on the first line or even better if they were in the true header of the Master Tablix. Code wise everything runs and works correctly. I am just trying to get the formatting to not list the headers 200 times. As a side, I am not committed to this architecture and if there is a better way to combine all these things I open. I tried combining all 3 into a single data set (unpivot the tablix and union the matrix) but then I lost all the formatting on the dates/currency etc.. I have also tried some hiding the header in the sub report with expressions, but since technically the report is only 1 line, anyway I hid it, it hides for all or none.
Update: I have been able to combined the 2 matrixes into 1, then add columns with the tables, but each is a lookup so ...50 lookups.
The above image shows the tablix with 1 matrix, as you see the headers are repeated for every group and they grow disproportionate so they cause with hidden rows. The 2nd matrix makes the issues multiple. The picutre below is the desired outcome, + one more matrix.
I'm using the below array formula to count the unique occurrences of text in column C using the agent name in column G as the reference. This is giving me multiple issues.
=SUM( --(FREQUENCY(IF(G3:G100000 = J5,MATCH(C3:C100000,C3:C100000,0)),ROW(C3:C100000) - ROW(C3) + 1) > 0))
Depending on the data set I'm using multiple agents will return a #N/A result and I can't figure out why.
Each dataset I'm using is 20k to 30k lines, so the formulas take a long time to process.
Any ideas how I could do this faster or better? Also any ideas why some agents get bad returns?
I am assuming that you are looking for the number of unique combinations of columns C and G.
Create a pivot table and check the box to add this data to the data model.
Drag both column headers to the Rows section, also drag one (of those same two) into the the values section.
click on the the field in the values section > value field settings > summarize values by > choose Distinct Count. This removes all duplicates.
Click the Row Labels filter and uncheck the blanks.
You can drop in new data then right-click on the pivot and refresh to see the new results. See the image.
I am working on a package that loads data from a text file onto a table on SQL server.
The text file has data in the below format
I am including the flat file connection manager here -
I have created a test table
executed the package and moved data onto the table.
And, then edited one of the column to include more characters (included s in the second column)
and instead of the package erroring out..it ran successfully and moved the extra characters to the next column.
Can someone help me out here ?
Why package is not throwing an exception?
This is normal, you are reading the Flat file Source as a fixed width columns, (Fixed width or Ragged right) with the following specifications.
"Ragged Right", which is exactly the same as "Fixed Width", except that it gives you the option to insert a linefeed character (or CRLF, etc.) at the end of each line of data.
(You can check the Flat File connection manager to see the specifications)
Initial State
Data:
0001aijn fkds jmcl wuj
Specifications and Result :
Col001: From 0 -> 3 '0001'
Col002: From 4 -> 7 'aijn'
Col003: From 8 -> 11 ' fkd'
Col004: From 12 -> 13 's '
Col005: From 14 -> 18 'jmcl '
Col006: From 19 -> end 'wuj'
Second State
So when you added a S character the data looks like:
0001aijns fkds jmcl wuj
Specifications and Result :
Col001: From 0 -> 3 '0001'
Col002: From 4 -> 7 'aijn'
Col003: From 8 -> 11 's fk'
Col004: From 12 -> 13 'ds'
Col005: From 14 -> 18 ' jmcl'
Col006: From 19 -> end ' wuj'
For more informations:
How to import a fixed width flat file into database using SSIS?
SSIS Flat File Export - "Fixed Width" vs "Ragged Right"
Is there any work around...where it can throw error in such case?
In the Flat File Connection manager use the Delimited Format
Go To the Advanced Tab, Delete all Columns Except one column
Change the Datatype to DT_WSTR and the length to 4000
In the Data Flow Task add a Flat File Source, Conditional Split, Script Component, Derived Column Transformation, OLEDB Destination as Shown in the image below
Use the Conditional Split to filter rows based on the length of the column:
LEN([Column0]) == 22
In the Script Component write the Following Code (used to raise error if there is a row of length > 22):
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
Throw New Exception("Length constraint violated")
End Sub
Specify the following Derived Columns
Map the result to the OLEDB Destination
I don't see any difference in the behaviour of the two cases. Both times it is reading 4 characters from the input file and putting them in column 1, reading the next 4 characters into column 2, the next four characters into column 3, then 2 characters into column 4, 5 characters into column 5, and finally 4 characters (if there are that many left) into column 6. Note that it is counting the spaces as characters, so in the first run it is including the space between aijn and fkds at the beginning of the entry in column 3, whereas in the second run the extra s is now the first character in column 3 and the space becomes the second character.
You need to update your SSIS package to accommodate added length.
For this, right click on your target Destination - Show advanced editor:
Check and fix the length of the internal column:
And lastly check the length of external column:
Hope this help :)
My SQL query returns 100 rows. When I copy the result to excel sheet or try to download as CSV, data in one of the columns is getting concatenated and excel shows only 30 rows.
For example my query result shows:
Id Name Expression
1 aa One
2 bb Two
3 cc Three
4 dd Four
The data in excel sheet gets copied as:
Id Name Expression
1 aa One
3 cc Two Three Four
Any help is welcome!
Right click any database on your SQL Server -> Tasks -> Export Data, a wizard will pop up. Select your source SQL Server and Destination as Flat File Destination, you can just put an empty csv file on your drive, select Format, Text qualifier. follow with the wizard. See what you can get.
Since I found out that the problem was created by double quotes, I just separated the rows with double quotes.
So we can separate rows, that is first pick all rows with no quotes and then pick all rows with quotes
or
replace quotes with something else.
Select Id, Name, Case Expression When '"' THEN 'BuggerQuotes' ELSE Expression FROM table1
After copying data to excel sheet, I replaced my BuggerQuotes text with double quotes.