I’m trying to write a simple query with an in clause like so: I need to be able to pass the values in the in clause as a parameter, the number of values in the in clause are variable and could be one or thousands depending on the user input. In other sql databases I have solved this problem by
Replace and squeeze boolean feedback columns to single score column in BigQuery
I have data that looks like this (note one TRUE per row): I want to replace each TRUE with a number that depends on the column that it is in (5-1), so a score with very_good being 5 and very_poor being 1, and then squeeze it into one column. So it looks like this: So far I’ve tried this: But
How do I use a variable to create a randomized date for every row in a column?
I’m currently trying to randomize every date inside a column! Will this create a single random date for the variable and assign it to every row, or will this generate a unique randomized date for every row? (I’m using a variable here instead of just doing it right in the update statement because I…
SQL Server: Drop all Not Null constraints in all DB tables
How do I drop all Not Null Constraints in All Columns in every table using SQL Server ? Would like to loop run this query in all tables and columns, How to remove not null constraint in sql server using query Note: requirement is for all non-primary key columns. Similar Question: How to drop all Foreign Key c…
Replacing case with IIF in SQL Server
So for my above query, I want to use IIF instead of CASE, because I want to show only uninsured patients, would something be correct? Because if I only use one case in my case scenario, the null will should up in my insurancestatus column instead of uninsured. Basically I just want the result for null showing…
Split array(bigint) to multiple rows of bigint
I’m querying some data (SQL, presto), each item can be the parent or child of another. The parent IDs and the child IDs are stored in the row for that primary ID as an array(bigint). Each task could be the child of multiple parents. It looks something like: I want a list of all of the parent Ids and eac…
Both columns can’t have nulls at the same time, only one per time, how to define this constraint?
I have a table: If clients feedback than 1 otherwise Barbers feedback 1, how to make a constraint for this situation? ClientFeedback bit null, BarberFeedback bit null, Sorry for English Answer You use a check constraint. For instance, if you want exactly one value to be 1: I am guessing that might be what you…
How to split a sentence and get only left 15 or less (Not greater than 15) characters on one column but at the end it could be a complete word
How to split a sentence and get only left 15 or less (Not greater than 15) characters on one column but it could be a complete word. Example: Ali, House Number ABC/123, Sattelite Town, Lahore. Need support here. Answer You can try something like this:
How can I use ORDER BY column_string like column_int when my column_string have letters?
I have a table like: —————— | ID | Animal | —————— | 1 | B1 | —————— | 2 | B2 | —————— | 3 | B3 | —————— | 4 | …
Psql query : Union is not preserving the order of rows coming from cte
I have this query: cte1 is ordered by salary column but cte2 is not. I want the results of cte2 to get appended to the results of cte1 while preserving the order of results from cte1. But it’s not happening. If I run the above query without union with the second cte, the results are displayed in the exp…