Skip to content
Advertisement

Tag: sql-null

SQL CASE that matches value or uses LIKE ‘%’

I’m trying to do a wildcard retrieve if a defined variable is blank. But I can’t figure out the correct syntax. Answer It is as simple as this: The expression NULLIF(x, ”) will convert ” to null. Then we take advantage of how null comparison works: If @customerID is not null then first condition will be true only for exact

How to copy data from one column to another?

I am trying to add Property Address in columns that have a missing value. I use the below to identify common parcel IDs with corresponding property address since the same parcelIDs have the same PropertyAddress as well. I get this result: Now I want to add the data in column IFNULL(n.PropertyAddress,n2.PropertyAddress) to the missing PropertyAddress cells using the below: However,

Getting values based on other column

I have the following data in SQL. Is there a way using SELECT QUERY that we can replace the NULL values in DATE column based on the REF values? Like replace the NULL values with the first available date for matching REF value, without making any change to the database. Expected Result Answer You can do it with MAX() window

SQL Server – current inventory with physical count

I feel as though I’m missing something extremely fundamental that should be obvious. I’m basically trying to take the below data and calculate a fifth column: Inventory_Current. Example data: DateStamp ProductID Inventory_Change Inventory_Count 2021-07-01 100 -300 100000 2021-07-01 200 -700 50000 2021-07-02 100 200 null 2021-07-02 200 -100 null 2021-07-03 100 500 null 2021-07-03 200 300 null 2021-07-04 100 -1000

Postgresql – Compare a string with a null value

I’m a bit puzzled because I believe the answer to this question is fairly simple but I’ve searched and tried several options and couldn’t find the right answer. The database is a PostgreSQL 13.1 I am using an API which sends a JSON object to a stored function in the database as follows: The function queries a table with the

select conditionally with conditional joins in mysql

I am trying to join two tables, people and sales, and displaying results based on a where condition which should be used to join the tables. My current attempt is showing only one result but I want all the rows in the people to be shown regardless of whether they have a record in the sales table, if they have

Query not returning expected data

I’m looking for an explanation for why 1 of the following 3 queries aren’t returning what I am expecting. Assume the following: Anmodning with ANNo=1, ANCpr=1111112222 And the Person table doesn’t have a row with PSCpr=111111-2222 Queries are executed in Management Studio against a SQL Server 2017. Queries 2 and 3 returns the Anmodning row as expected but query 1

Advertisement