Copying output from Snowflake to Excel or notepad showing additional row - sql

I was trying to copy the output from Snowflake to Excel. For example, there are only 4 rows in Snowflake, but it becomes 5 rows with one additional row when I copied it to Excel or Notepad.
I used trim and replace statement to clean up spaces, but the extra row is still there.

So it "works for me" the SQL come from this Answer
Do you have better words, or a cut down example?

Related

What is the best way to approach transferring an 'empty row delimited' excel spreadsheet into two tables in an SQL database?

I have a collection of excel spreadsheets that are formatted... less than ideally.
I'm testing out some solutions involving SQLBulkCopy and OleDB, but I'm a bit concerned about how to handle the format of this sheet.
I was considering writing a custom Insert statement, but would like to see if there may be some easier way to implement a heuristic.
Below is a sample of the data I will be parsing:
The highlighted columns are the ones I'll be loading into the two tables. One table will hold order #s, and the other table will hold all the lines below that order number.
Any suggestions on tackling this would be lovely. The excel sheets are hand entered, so some weird cases exist (one order number with multiple carriers, which imposes the question of whether I should treat the first row with the order number as a line in the database structure I designed.
I'm implementing this importer within VB.net, to my dismay, to avoid being looked at funny by my coworkers :).
One approach would be to save the worksheet to a text file (e.g., CSV) and then use AWK to split it at the empty row. Some examples are in this SO answer: Bash how to split file on empty line with awk
You could then import the CSV files directly into the database.
Amusingly , if I wrote anything in VB.NET I'd definitely get looked at funny by my coworkers
So I'd use a library called EPPlus to read the excel and not have to worry about converting it. How you do the blank line detection is an open question- checking that the Value of ten cells on the row is Nothing or Empty would suffice. Then take the next row as your parent, and proceed with subsequent rows as children until the next blank
Take a look at this answer for more info on how to detect blank rows in Excel- if you get stuck turning any of the c# into vb shoot us a question. Online converters exist because the two languages are the same thing under the hood

Teradata SQL Concatenates Columns when Pasting to Excel

I have my SQL output as five columns. When I paste the SQL output to Excel it seems to concatenate everything that is a string into one column until a number appears.
In this case, my first 4 columns are text and Excel they are concatenated to one column. My fifth column is a number and that's in the 2nd column in Excel. My column headers are all concatenated to a single cell.
When I paste to NotePad it looks fine. And even when I paste to a text box inside of Excel it looks fine. But when I go to paste the data from NotePad and the text box I get the same thing.
Does anyone know a solution for this? And is this an Excel or SQL issue?
Somehow the Text to Columns in my Excel settings got switched to comma instead of tab. Go to Data > Text to Columns > choose delimited and then choose tab.

SQL Server - Insert Blank Rows after row

I have a query for SQL server (2014). This query is then processed by my application that exports the result set to excel.
I have been asked if I can add space underneath each row, as the spreadsheet will be printed and they would like to make notes on it.
I have tried adding carriage returns to my query to try and stretch out the height of the column so
(CHAR(13)+CHAR(13)+CHAR(13)) as 'Blank Column'
But excel didn't pick up the returns.
The only other thing I can think of is to add 4-5 blank rows after each row with data, I'm just not sure how to do that, or even if it's possible
Try something like this:
SELECT REPLICATE(CHAR(10),5) AS [Blank Column]

collecting SQL statements using Excel

in my everyday work, I am receiving data in Excel spreadsheets, which I need to insert into relational database.
To accomplish this, I prepare formulas which generate "insert" statement (I am using both insert and select statement for example to choose ID of all elements with specific label).
Because those spreadsheets are complex, they contain SQL commands in more than one column.
This is the point where problems begin - I cannot simply select all cells, copy them and paste into SQL Server (it will concatenate information from cells in the same row).
In most cases I'm preparing additional sheet where I'm collecting all statements in one column
(using simply formula which rewrite text from other cells). Unfortunately preparing such sheet is time consuming and might causing an error (for example if I forgot about column or I add rows).
Is there any more convenient way to do it?
I thought about writing a macro which collect all values from selected range.
Is it good idea or can I use something better?
You can do all that using VBA.
You know what are the rules so you have the business logic in your head. Now, just type the code to do it :)
If you want you can do the insert in the Excel using something like this.

SQL query in excel returning one value uses two rows or columns?

I'm running a query from excel to sql server that returns a single value. It seems as if this uses two cells in excel. Is this correct? Is there a way to prevent this? Is there a way to predict whether excel will use an extra row or an extra column (I've seen both happening)?
If, in excel, I use "import external data -> new database query", and then do a count() on an sql server table, excel usually puts the result in the cell underneath the cell which I had selected when starting to do the new query (not adding an extra row, but putting the value there). Sometimes, it will instead insert an extra column before the column of the cell I had selected and put the result in the new column in the same row as the cell I had selected.
Is there a way to have excel return the value in the same cell as the one selected when starting the query? If not, is there a way to predict which of the two scenarios above will happen?
Thanks,
Ernst
I finally found the answer:
uncheck preserve column sort/filter/layout