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…
Tag: sql
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…
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…
Can’t alter column type to a shorter VARCHAR in Redshift. Getting “target column size should be greater or equal to current maximum column size”
I’m trying to run in Amazon Redshift, but I’m getting this error: SQL Error [500310] [0A000]: Amazon Invalid operation: cannot alter column “column_name” of relation “table_name”, target column size 256 should be greater or equal to current maximum column size 879; I’…
How to drop duplicate rows from postgresql sql table
I have the following dataset in a postgresql table called testtable in testdb. I have accidentally copied over the database and duplicated rows. How can I delete the duplicates? Row 1 and row 5 are copies in this frame and row 2 and row 4 are copies too. I have never used sql before to drop duplicates I have …
Delete record from table if certain fields are empty upon closing a Form
I am trying to get a button to close a Form and at the same time delete records on a table where certain fields are empty. I have this on the Form: AlimentoporTanque is the Table’s name and Tanques and Alimento the fields that should not be empty. When I click on the button I get following MsbBox poppin…