SQL Server Management Studio Results Scrolling - ssms

I find myself doing a lot of scrolling through thru hundreds of results within the SSMS which is pretty painful. Does anyone know a faster way to scroll through a large number of Results in SSMS? Page down doesn't seem to be supported. Even if there was an option to go to a specific row within the results would be a big help.

Not directly achievable through SSMS interface but you can try something like the following.
First, determine which row number you'd like to jump to (index starts at one) and execute your query with the OFFSET and FETCH NEXT statements
SELECT * FROM Expense ORDER BY Id ASC OFFSET 4 ROWS FETCH NEXT 1 ROWS ONLY
OFFSET means how many rows you'd like to skip from the top, FETCH NEXT determines how many rows to display after the offset.
You can select the first row after skipping 20 rows (in other words, obtaining row 21), do the following
SELECT * FROM Expense ORDER BY Id ASC OFFSET 20 ROWS FETCH NEXT 1 ROWS ONLY
Not the best way of doing it, did not consider performance of such approach. But the easiest to achieve what you are looking for.
Another way could be executing the full query in Excel and use Ctrl + G to go to specific row number.

There is no direct option for easy scrolling. You need to filter the result or export/copy the result to excel.
Usually I will copy the result to excel. This will give a clean look and also we can filter the result if needed in excel. :)

Related

DataGrip sort more rows than page size

In JetBrains DataGrip, when I try to sort a column (descending for example), it only shows and sorts loaded rows - that means 500 (it's the set page size). Is it possible that it can sort all rows (in my table like 25 000)?
I don't want to manually type order by column_name desc everytime I want to sort something.
In DBeaver this kind of sorting works.
You need to turn Sort via ORDER BY option on. So it will concat the ORDER BY for you.
Alternatively, you can always fetch all rows (use the corresponding setting) and client-based sorting will also sort all rows :)

How to delete rows by calling its row number

I have this data stored in the SQL Server
How can I delete the first three rows by calling the row number found in the left (1,2,3)?
You can't. That row number is not tangible and is nothing more than the order the results were returned in. SQL does not guarantee order of data, so there is no rule that says if you run the same query 20 times, you'll get the same results at 1,2, and 3 each time. That's not to say you won't get them same results, they're just not guaranteed. You need to delete using a column that actually exists as part of the table definition, such as F1, F2, etc...
As others have suggested in the comments, try to clean up the data before you import it into SQL Sever. You have a few options.
Delete the rows from the file before importing.
Configure the Import Wizard correctly to exclude those rows.
Helpful link
https://learn.microsoft.com/en-us/sql/relational-databases/import-export/import-data-from-excel-to-sql?view=sql-server-ver15

pentaho process selected rows

Objective
I have an excel sheet that has 10 rows. Now, I want to select rows 5 and 6 only.
What I tried
I am getting the rows to set limit in the Excel Input -> Container, but using limit I am only getting rows smaller than input limit. So please anyone tell me how can I get the above condition.
Updated
specified start row = 5 in Sheets Tab
Without specified start row
First of all in content section you can specify the filter and it is working perfectly fine, I have checked.
For achieving your output you can simply use filter rows step, specify the values you want to in values condition.
With the Excel input step, on the Sheet tab you can specify a range. Tell you want to start on row 5, col 1. Tell also on the Content tab, that you do not want a header, and a limit 2.
This should work. However, the answer is a bit academic, and I would suggest #Working Hard's answer. Read every thing, then use a Filter step. In this step you can put more than conditions, like row=5 or row=6, or like row>=5 and row<=6. To do this, put the first condition, then click on the small green + on top right and put the second condition. Afterwards, you can click on the AND to change it in OR (among others).

Change Column location of SQL statement in Excel

Within excel I have connected my Microsoft SQL Server database to it, to display results. The system I have set in place is built off of a form. If a user chooses option 1, the query results will show:
Select person, car, house from mytable1
If the user chooses option 2, the query result will show:
Select job, person, land, truck from mytable2
The very first select statement will give me a table in the column order in which I would like it. However, as a user uses the form again, it will re-query it to use which ever select statement is requested. When the re-query happens the column order which items are shown are in different areas. Even if the select statment is stated within the same order. Is there a way in which I could order the columns in a specific order?
I've attempted to unchecked "Preserve Column Sort" within the Data Range Properties, but ends up leaving empty columns. I.E. : Column1, Column2, Column3, etc.
You may already know this, but since Excel allows you to move the columns in a table / ListObject around, it seeks to preserve any changes you make. So, if you run a query:
select one, two, three
And then move the column "three" in front of "one," when you re-run your query, it will keep them in that order in the ListObject, even though the query said otherwise.
This also means if you add a column, no matter where you add it, it will go to the end when MS Query renders the output.
select four, one, two three
("four" goes to the end in Excel, even though it was listed first in SQL)
In your example, the column "person" was common across the two queries, so Excel (MS Query) would move it to the first position and put all other columns after that.
When Excel deletes the old columns, it leaves a tracer behind -- you may notice the columns that follow your table aren't the normal size; they are the size of the fields that were deleted. I call them "ghosts."
This is a serious hack, but the only way I know of to alleviate this problem is to run a bogus query (ie select 1), delete the ghosts -- remove the entire columns, and then run your second query. Here is some ugly code I use in VBA to do this:
Dim lo As ListObject
Set lo = Sheets("Sheet1").ListObjects("Table_ExternalData_1")
Range(lo.HeaderRowRange.Offset(0, lo.HeaderRowRange.Columns.Count), _
Range("XFD1")).EntireColumn.Delete
Yes, this deletes every column after the table, which means if there is useful data above or below the table in columns after the table, those are wiped out.
Maybe there is a better way -- I'm curious to see if you get any other solutions.

best aproach to distinct query result before importing it into Excel cells

I have a query which grabs data from Access with contents:
A,1,z
A,2,z
B,1,y
A,1,i
I created 3 dropdowns in excel and I want to populate them with rows from these columns. The problem is that in each column there are duplicates and I want to get rid of them. I am looking for a solution to get rid of these duplicates.
Current process is following:
run a query. I use VBA in Excel. Access is being queried.
paste results into a separate sheet (it takes A LOT of time because there are 20k reocrds)
assign a range for my dropdows
As you can see my second step is very resource hog and the proccess time should drop drastically by removing duplicates from each column.
What is the best approach to populate dropdowns with unique values from query?
My ideas
create a query which will output me:
A,1,z
B,2,y
, ,i
In that case i will not have to distinct values manually in excel. Not possible to do, as I understand...
Add values from each columns to List, remove doubles, paste result into excel. This is my personal favorite because I see no other ways to fix the issue.
create multiple queries to DISTINCT each table_column separately.. Not very fast solution, I suppose
some other approach
Run three SELECT DISTINCT Colx FROM table queries to get the values for the three dropdowns. Your option two. The work has to be done sometime so you might as well use the tools designed to do the work instead of reinventing that wheel.
If you use select distinct columna, columnb... instead of select columna, columnb... you will get what you want. The SQL will take longer to run, though.