I created procedure which count not null rows in the column, but query throws errors: @tableName is not declared and invalid object name tempTable. I don’t know why code throws that errors, because all variables are declared. Also when I make that program in another way, that code throw Msg 1087, Level …
Return from first row if last row reached
Table has an id column with rows 1 to 10. I want: SELECT id FROM `table` WHERE id > 8 ORDER BY id ASC LIMIT 6 to return: 9 10 1 2 3 4 What’s the appropriate query for this?
Partitioning rows into groups by accumulative time interval
I got a search sessions log that looks like this: My task is to partition each row into session groups. Session groups are up to five minutes. For example: Those TOP 3 sessions will form a group session 1 – if we accumulate the minutes between each row, we will get 3 minutes and the 4th would accumulate…
Join tables to display null if right side table doesnt have data
I have a feedback_ques, feedback_ans table as follows: I want to join the tables as follows: This gives me all the fields. I want the query to return null for answers if they arent found in the answers table. For example member_id 20 doesnt have answers, so i would want the table to display null values as bel…
How to multiply all values in one column to make one number?
In SQL Server, I am trying to multiply all values of a calculated column in a table in descending date order, to produce one number. This is so I can calculate a factor that can be applied to a different table / value, i.e. multiplying every value in the “price rate” column to produce a “pri…
How to use nextval() to insert a row containing its own ID in a string
I have a table that contains a column with a string containing its own ID. How can I insert a new line using a single SQL statement? I need something like https://www.db-fiddle.com/f/3NwLNBirN7mHKpDk9NyHSy/1 Answer One option is to select the next serial in a subquery first: You could also use a computed colu…
How do I configure one SQL Server to connect to another, so it appears query data is coming from only one connection?
Somewhere recently I read of a method to connect one SQL Server to another, so clients could connect and run queries that appeared to come only from the first server. I cannot remember the proper …
How to concat all the entries of one column [SQL]
As the title states, with the following SQL query: I get the following result: Question: how to modify the query so that all the names are to be displayed in a row, so that they can be later used an array. What I tried: FOR XML, STUFF – doesn’t work Expected result: Answer If you are using SQL Ser…
SELECT rows with a new DISTINCT from a VARCHAR with CSV in it
I have an Oracle database table with a field called Classification which is VARCHAR. The VARCHAR is a CSV(using semi colons). Example: I want to pull all the rows with ONLY a different value in the CSV from the others. It is ok if a row has a previously found value as long as it has a new different value.
BigQuery SQL conditional IN
I have been trying to construct a conditional IN like below, but this gives me the scalar subquery produced more than one element error. How should I approach this type of query instead? The tables are not related. Answer Try this below- As your other tables are not related, you can try this below logic-