I wanted to use if statement in Oracle update. Below is the condition that i wanted to achieve and i will not be able to use PL/SQL. I wanted to achieve the below result using update statement. if …
Tag: sql
SQL: How to write multiple interactive scripts in one query (insert rows)
Simple question- I just want to learn how to write a query that will insert 2 rows into my table by writing one query, instead of 2 separate ones. My queries work completely fine, I just want to know …
T-SQL – Count unique characters in a variable
Goal: To count # of distinct characters in a variable the fastest way possible. DECLARE @String1 NVARCHAR(4000) = N’1A^’ ; –> output = 3 DECLARE @String2 NVARCHAR(4000) = N’11’ ; –> output = …
Incorrect syntax near the keyword ‘right’
i am very new to SQL, spent hours searching but all the articles point to more or less same Bellow is my code, but honestly not sure what am i doing wrong here. I want to join both tables via ID, keep the id from left and take other parameters from right table user_private_store_items i get Incorrect syntax near the
Assertions in Snowflake
Is there a way to perform assertions in Snowflake? Basically, I’m trying to do a bit of testing/TDD, and I’d like a mechanism similar to assertions in every other language: If the assertion succeeds, it returns true (and/or prints a success message). If the assertion fails, an exception is raised. Answer I couldn’t find any way to perform assertions in
Finding Duplicate Rows in a Table
I am trying to find out how many duplicate records I have in a table. I can use count, but I’m not sure how best to eliminate records where the count is only 1. I can try to order by the count, but I am still not eliminating those with a count of one. Answer you can use having clause
Parse String and Insert Results Into 3 Fields
I have a field in a SQL table that looks like this. It’s literally a file name. I’d need to create 3 new fields and split the string shown above into this. How can I do that? I have this basic SQL that does the select and parsing, but I’m not sure how to do the insert into. I am
How to update columns only if argument is equal to specific value?
I have query that should update columns only if argument is equal 1. Here is example: I would like to move this SQL query to stored procedure. How I can achive the same process with SQL code only? Instead of <cfif form.status eq 1> title = @title,</cfif> how that can be replaced with SQL code? I use Sybase database and
SQL how to do a LIKE search on each value of a declared variable
I have a query where I am trying to do a LIKE search on each value of a declared variable, instead of doing a like search on the entire field value/string. Example: The record I am looking for is “John and Jane Smith”. The query above returns NO result. If the user searches just ‘John’ OR just ‘Smith’ there are
How to use expression as LAG() second parameter on MySQL 8 (like MSSQL)?
I am trying to migrate this SQL SERVER query: dbfiddle link To MySQL 8 (same query): dbfiddle link Unfortunately I got this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘*(SELECT MIN(sales) FROM product_sales), sales/2.0 ) OVER (ORDER BY year) AS no_’