June 23, 2017 at 12:34 pm
Hello experts,
Im having difficulty to write these query with both options, these is what I have so far and is working in a SQL query:
case when sola.ECCN is null then icd.ECCN else sola.ECCN end AS TESTVALUEECCN
but how can I add the doesn't exist option??
I need to show this value icd.ECCN when this value sola.ECCN is null or doesnt exist.
Any help will be much much appreciate it
June 23, 2017 at 12:44 pm
montserrat.deza - Friday, June 23, 2017 12:34 PMHello experts,Im having difficulty to write these query with both options, these is what I have so far and is working in a SQL query:
case when sola.ECCN is null then icd.ECCN else sola.ECCN end AS TESTVALUEECCN
but how can I add the doesn't exist option??
I need to show this value icd.ECCN when this value sola.ECCN is null or doesnt exist.
Any help will be much much appreciate it
It looks like you can replace your CASE statement with:
ISNULL(sola.ECCN, icd.ECCN) TestValueCCN
From your description of sola.ECCN not existing, I'm guessing you're OUTER JOINing sola to icd. This is only a guess. In that case, if the row in sola doesn't exist, it'll return NULL in the result set, so the NULL check (either CASE or ISNULL) will handle it.
If my guess is wrong, please post DDL and your full query so I can better see what you're working with.
June 23, 2017 at 12:47 pm
can't you just add another WHEN THEN?
case
when icd.ECCN is not null
then icd.ECCN
when sola.ECCN is not null
then sola.ECCN
else 'missing' end
AS TESTVALUEECCN
that could also be written with a COALESCE, whihc is easier to read, but is still converted to the exact same caseCOALESCE(icd.ECCN,sola.ECCN,'missing')
Lowell
June 23, 2017 at 1:02 pm
Thank you!!! that is easy lol!!! Thank you so much will work...
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply