SQL Server - Insert Blank Rows after row - sql

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]

Related

Postgres - split number and letter doesnt fill column

I have received help for splitting a column wit nr and letter.
In the SQL script it all works perfect. It runs complete, with no errors.
But the columns itself doesn't get filled.
I have tried to create te columns in advance as text or as integer. But it doesn't get filled. The SQL query it self turn out ok. But in reality it stay empty. What is wrong?
Your question is not completely clear, but it sounds like what you are trying to do is take a value from one column of a table, split it and use the result to update two other columns in the same table.
If that is the case, you would want to be using the SQL UPDATE command instead of SELECT.
UPDATE d1_plz_whatever
SET nr=SUBSTRING(hn FROM '^[0-9]+'),
zusatz =SUBSTRING(hn FROM '[a-zA-Z]+$');

row header in mdx queries

Can anyone explain how to add row headers to the following query? I'm sure there is a way, surprised that the column headers appear but the row headers are null.
By row headers I mean the top of the returned data, in gray that actually shows the name of the row returned.enter image description here
That is SSMS and the way it displays the data.
In MDX Studio we get this:
...but SSMS and MDXStudio are not front end clients so this is just the way they have been designed.
If you are using say Excel as a front-end then you will maybe use a pivot-table to display the data - column headers will be the same as any other pivot table
If you are using SSRS then you can name the columns in your Datasets.
Other front-end clients will deal with this differently.

MS Access - Query bringing in "new record" row

I have a query that will be populating a form and then the form will allow the data set to be edited. The issue I am having is that the query is pulling the last row that is normally used to add a new record. This results in having a row that looks shows all fields as blank, but leaves one field with "null".
I played around with the query and was able to find a workaround by selecting "distinct" records, problem is that when you select with distinct, you cannot edit the data set. Is there any other way around this?
I can upload an example of the database if needed.
Thanks!
edit: picture to show the issue: https://imgbomb.com/i/?rO1sp

SQLbase data not numeric

I have a query that runs in Excel, that will need to show data from an SQLbase database where I only have read-access. I cannot modify the database in any way. The column I need to be able to filter on is a varchar column, but it's values are only numbers. I need to be able to filter with between in Excel, so I've tried to do column + 0 so Excel picks it up as a number. This worked before, but now it fails on some numbers.
The number 704977990024 works, but 991098000265 doesn't. With the second one I get Data is not numeric.
This is the query:
SELECT (TABLE1.COLUMN + 0) AS "Artikelnummer"
FROM DB.TABLE TABLE1
LEFT JOIN DB.OTHERTABLE TABLE2
ON TABLE1.COLUMN = TABLE2.COLUMN
How can I make sure I get it as a number in Excel? If not in the query, then how in Excel itself? When I set the column to number in excel, it still displays as text and will not be numeric unless I try to edit the cell.
It's probably overflowing. An alternate way to get what you need Is to pad the numbers with leading zeroes. This will avoid the overflow and let you use a range. I don't know the syntax... something like where Right('000000000000000' + nu, 17) between ....
I have not found a solution to this, but I did find a manual workaround.
You select the whole column and cut&paste is somewhere else. You cut it because the colum needs to be empty when putting the data back. After that, you select your newly created column, and copy or cut it. Then you select the column where the data needs to be (the one you just emptied), and press paste > paste special. Then you select multiply (or any other) and press ok. That way the columns will be numeric.
It might be a manual thing, but it was the one solution I've found to this problem.

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