SQL any bods on here?

Ha! I was doing the same, but got this response:

Certainly! Let's break down your requirement:

You want to retrieve results where:

1. 'Column1' is null or blank in all instances.

2. 'Column2' is null or blank, except when the status of 'Column1' is either "abc" or "123".

Based on your provided code snippet, it seems like you're on the right track, but there might be a syntax issue. Here's the corrected version:

OR (

(COLUMN1 IS NULL OR COLUMN1 = '')

OR

(

(COLUMN2 IS NULL OR COLUMN2 = '')

AND

COLUMN1 NOT IN ('ABC', '123')

)

)

Nee idea which is right. But I’ve become reliant on ChatGPT now. It does help a lot.

It’s class like! A lazy person’s dream! 😂
 


ChatGPT mate! Whack your code in and tweak as needed.

For yours it states:

Your query looks mostly correct, but there are a couple of adjustments needed for your second condition.

Try this:

OR ( COLUMN2 IS NULL AND COLUMN1 NOT IN ('ABC', '123') ) OR ( COLUMN2 = ' ' AND COLUMN1 NOT IN ('ABC', '123') )

This should properly handle the case where 'column2' is null or blank except when 'column1' status is either "abc" or "123".
Ha! I was doing the same, but got this response:

Certainly! Let's break down your requirement:

You want to retrieve results where:

1. 'Column1' is null or blank in all instances.

2. 'Column2' is null or blank, except when the status of 'Column1' is either "abc" or "123".

Based on your provided code snippet, it seems like you're on the right track, but there might be a syntax issue. Here's the corrected version:

OR (

(COLUMN1 IS NULL OR COLUMN1 = '')

OR

(

(COLUMN2 IS NULL OR COLUMN2 = '')

AND

COLUMN1 NOT IN ('ABC', '123')

)

)

Nee idea which is right. But I’ve become reliant on ChatGPT now. It does help a lot.
Cheers gents, will try, I was using copilot but asking for examples rather than sticking the code in. never used chatGPT before :D will have a butchers.
 
Any SQL legends able to help me get to grips with this.

im trying to find results where 'column1' is null or blank in all instances OR where 'column 2' is null or blank EXCEPT where the 'column 1' status is either "abc" or "123"

as part of a bigger code i've got;

OR (COLUMN1 IS NULL
OR COLUMN1 = ' ')

OR (COLUMN2 IS NULL AND COLUMN1 NOT IN ANY ('ABC','123')
OR (COLUMN2= ' ' AND COLUMN1 NOT IN ANY ('ABC','123')
do you need to use nulls and blank values, aren't they same thing and it would simplify your query if you stuck to one? Instead of setting it to ' ' can you not just null it?

On the other hand, there's a whole school of thought that you should avoid using nulls all together because they can cause logic issues but thats a whole can of worms and is rarely achievable.
 

Back
Top