How to add constraints with a large amount of objects in SQL query? - sql

I want to get output from a SQL query by adding
WHERE ID IN (
15325335122,
85962128962,
12354789522,
64125335125,
64523578945,
12354784589,
......
........)
This list contains over 9000 rows, I'm wondering if there's an easy way to add them in the where statement since I don't want to copy and paste and add comma one by one. I'm new to SQL, can someone help me? Thanks in advance.

I've figured out the solution by following this instruction
In excel, select the cell next the first cell next to the first item on the right, then enter =A1&","

Related

Top/Bottom 10 Entries from Each Group/Category Excel?

anybody knows how to find top/bottom 10 entries from each category? I found a partial solution for my problem from this StackExchange question , and it works great, except that it only shows the TOP values, not the BOTTOM values.
Anyone can tell me how to do the same for bottom values? I know it requires me to change some of the syntax, but I tried for hours but didn't find any.
Any help is greatly appreciated.
Thanks!
If your data is in excel's table try the following:
Create a Rank Column which will rank each value through your category
=COUNTIFS([Category],[#Category],[value],">"&[#value])+1
Create another column which calculates max value for the category, it is an array formula so, hit ctrl+shift+enter to execute it:
=MAX(IF([Category]=[#Category],[RANK]))
Create third column to decide top and bottom values based on previous 2 columns, in my example the column is either 1 or 0 to indicate relevant rows:
=IF([Category]=[#Category],IF(OR([#RANK]<=10,[#RANK]>=[#Мах]-10),1,0))
You'll end up with something like that:
Hope that helped

Excel SQL Table Formula's clearing

Apologies if asked elsewhere, having checked couldn't find anything. I've got a SQL driven table in Excel. When my table refreshes, resulting in no data, it completely clears out a series of none-SQL driven columns on the far right of the table. Is there any way at all I can force Excel to store the formula on the cell, regardless of whether the row has cleared?
To ellaborate on my comment:
Below shows a simple query returning 10 dates from a database. The right column is a simple formula in excel adding 10 to the date:
If I update the query to return the top 0, you find the formula disappears because there are no values to assign the formula to:
But, I then update the query to bring back the original 10 dates again, and hey-presto, the formula re-appears!:
So I wouldn't think that you need to worry that it has gone. I would expect that they would come back once you return some values from your query.
FYI - More help on calculated columns can be found here from Microsoft support.
Thanks! I think I had 'preserve column sort/filter/layout' unticked - which was causing the formula to be lost when the data refreshed! Schoolboy error, thanks again

Identify Pivot Field using VBA

I am trying to write a macro which automatically identifies which field is the data taken from in a pivot.
I have some columns with different level of org information dragged under one another in "Row Labels" to create a structure. Now I need to identify which row in the pivot is linked to which field.
I am a self-taught coder and am very new to advanced vba so need some help.
How my pivots look
I am trying to get the name of the field in the blue circle
Thank you!
Nevermind guys, It was simpler than I thought. I am just an idiot for not figuring it out earlier.
Anyhow, the solution is that "ActiveCell.PivotField" returns the Pivot row's field.

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]+$');

Query to select items from a list and update table

I've got a query that I ran against a table of stock items to change a field from false to true so that a label would be printed out as per the below.
UPDATE [StockDB].[dbo].[StockItem]
SET [UseDescriptionOnDocs] = 0
Where [UseDescriptionOnDocs] = 1
I have since been told that all of the items do not need this and to only do it for the ones in a list of 1150. From that I need to modify the query, something which I am really struggling with!, so it can only do it per item which are in the format of R368/WASHER/M4/ZINC/PL etc. I thought I may be able to do it using LIKE but it will only do one line? If I could get it to query a list from Excel or CSV that would be great.
Any pointers would be good as I'm an absolute novice with this once you get past the simple stuff like the above!
Thank you.
With MySQL (and others) you can load data from a file to a table. See http://dev.mysql.com/doc/refman/5.1/en/load-data.html to understand and for exemple.
Once you have your items loaded into a SQL table, you just have to do an update + join query. See http://dev.mysql.com/doc/refman/5.1/en/update.html to understand and How can I do an UPDATE statement with JOIN in SQL? for exemples.