Skip to content

Tag: sql

SQL CASE with CASE

I have a CASE stmt within CASE and the code is something like below: I need to achieve below condition But below code is not working. Can anyone correct this code? Here If mgmt.id IS NOT NULL then status_fl should be set as ‘Y’, and If mgmt.id IS NULL then we need to check the condition If staff.N…

SQL row value expression with null failing in where-in query

I am struggling to understand why this where-in query is failing when there are nulls in the row value expression. The query is not returning a single record from the below table. I expected each row value expression to match exactly one record. I appears the null spoils the fun and I don’t understand w…

Define enum as the column names of table PostgreSQL

Is there a way to define an enum using a table’s column names? I have a users table defined as follows: And then I want to define a required_profile_fields column in another table to be an enum containing only the column names in that public.users table: Is there a way that I can define that profile_fie…

MS Access SQL query – Count records until value is met

I have an Access query (qr1) that returns the following data: dateField stringField1 stringField2 booleanField 11/09/20 17:15 John Nick 0 12/09/20 17:00 John Mary -1 13/09/20 17:30 Ann John 0 13/09/20 19:30 Kate Alan 0 19/09/20 19:30 Ann Missy 0 20/09/20 17:15 Jim George 0 20/09/20 19:30 John Nick 0 27/09/20 …