I want to dynamically fill a SQL table by detecting duplicate names. So, when I use an insert statement on this table – if the name already exists it adds an entry with the same ID. What I mean by this, for example I’ve got this empty table: Table Domain: DomainID Name URL StatusID ErrorID Date So…
Transpose row to column in SQL Server
I have a table like below: The first row is the header. Now, I would like to transpose table into this I have tried unpivot but the result is not desired table. Thanks in advance, Answer I recommend using cross apply to unpivot and then aggregation: I much, much prefer this over pivot/unpivot. Why? APPLY impl…
Store select query as variable and loop for entire variable
I want to store the result of select query from another table and set it as variable. Then i want to loop through the variable and use it in my loop for. The question is how i can store the result of select query from my table? Answer Why not run a single query? The . . . are for
Check if rows exists in SQL Server using R and then Insert or Update rows
I have a table with the below structure. ID Entity UserName UserRole UserStatus UpdatedDate Clustered key is defined on columns Entity, UserName, UserRole. UserStatus for an Entity-UserName-UserRole …
Google BigQuery – Subtract SUMs of a column basing on values in another column
Hi I need 1 query to get top 10 country which has largest [total(import) – total(export)] for goods_type medicines between 2019 – 2020. The data sample is as below: The returned data should include country, goods_type, and the value of [total(imports) – total(export)]. I have come up with th…
SQL select with case when and join table
I have 2 table in sql (postgresql) tbl1 : dates roomid stok 2021-03-15 A01 3 2021-03-16 A01 3 2021-03-17 A01 3 tbl2 : bookingcode startdate enddate roomid B001 2021-03-15 2021-03-17 A01 My …
How can I get SQL AdmitDate and DischargeDate with specific events?
Hi I have a table for homecare system and I have a series of entry logs for customer. I want to get a specific output. I want to break it down by record type ‘expired’, ‘Discharge’ and ‘Discharge-…
SQL Update record when field is in the past
how can I set all records in the field “published”=0 whose date in field F12 is older than today? Unfortunately, the field F12 is not a DateTime field, but a string. Unfortunately, I can’t …
SELECT statement across multiple tables
First off, I am not an SQL coder. I am trying to select information from 2 different tables in the same database. Table 1 is called trans and has 3 columns: Table 2 is called cust and has multiple columns: The SELECT statement that I’m trying to write will pull data from both tables. I THINK I need to u…
oracle add column with value based on condition
I would like to add a column “tag” based on value of “LEASE_ID_count” with ORACLE. But i get this error : value too large for column “CUSTOM_LIFETIME_VALUE_TAG”.”tag” (actual: 7, maximum: 3) , caused by: OracleDatabaseException: ORA-12899: value too large for co…