Обсуждение: case statement to cath nulls on joined tables
Hello,
I am doing a left outer join between a polygon table and a data table.
Everything
returns fine from this join as expected. However, there are cases where
there isn?t data for a given polygon and this return as the expected null
in the result set. I would like to utilize something like a case statement
to catch the nulls and return a ?more friendly? message. I have tried
unsuccessfully to use the following logic:
*Select case value_of_interest null then ?more friendly message? else
value_of_interest end*
*From poly_table left outer join data_table one poly_table.common_id =
data_table.common_id*
If someone could let me know where I am going wrong it would be greatly
appreciated.
Cheers,
Derek
Try that:
SELECT address, CASE WHEN value_of_interest IS NULL THEN 'more friendly message' ELSE value_of_interest END value_of_interest
From poly_table left outer join data_table one poly_table.common_id = data_table.common_id
--
Matheus de Oliveira
SELECT address, CASE WHEN value_of_interest IS NULL THEN 'more friendly message' ELSE value_of_interest END value_of_interest
From poly_table left outer join data_table one poly_table.common_id = data_table.common_id
--
Matheus de Oliveira
On Fri, Feb 3, 2012 at 10:45 AM, John Morgan <jdmorgan@unca.edu> wrote:
Hello,I am doing a left outer join between a polygon table and a data table.Everythingreturns fine from this join as expected. However, there are cases wherethere isn?t data for a given polygon and this return as the expected nullin the result set. I would like to utilize something like a case statementto catch the nulls and return a ?more friendly? message. I have triedunsuccessfully to use the following logic:*Select case value_of_interest null then ?more friendly message? elsevalue_of_interest end**From poly_table left outer join data_table one poly_table.common_id =data_table.common_id*If someone could let me know where I am going wrong it would be greatlyappreciated.Cheers,Derek
Even better:
SELECT COALESCE(value_of_interest, 'more friendly message') value_of_interest
From poly_table left outer join data_table one poly_table.common_id = data_table.common_id
--
Matheus de Oliveira
SELECT COALESCE(value_of_interest, 'more friendly message') value_of_interest
From poly_table left outer join data_table one poly_table.common_id = data_table.common_id
--
Matheus de Oliveira
On Fri, Feb 3, 2012 at 1:05 PM, Matheus de Oliveira <matioli.matheus@gmail.com> wrote:
Try that:
SELECT address, CASE WHEN value_of_interest IS NULL THEN 'more friendly message' ELSE value_of_interest END value_of_interest--
From poly_table left outer join data_table one poly_table.common_id = data_table.common_id
Matheus de OliveiraOn Fri, Feb 3, 2012 at 10:45 AM, John Morgan <jdmorgan@unca.edu> wrote:Hello,I am doing a left outer join between a polygon table and a data table.Everythingreturns fine from this join as expected. However, there are cases wherethere isn?t data for a given polygon and this return as the expected nullin the result set. I would like to utilize something like a case statementto catch the nulls and return a ?more friendly? message. I have triedunsuccessfully to use the following logic:*Select case value_of_interest null then ?more friendly message? elsevalue_of_interest end**From poly_table left outer join data_table one poly_table.common_id =data_table.common_id*If someone could let me know where I am going wrong it would be greatlyappreciated.Cheers,Derek
Thanks Matheus. The coalesce method worked like a champ.
Cheers,
Derek
On 2/3/2012 10:09 AM, Matheus de Oliveira wrote:
Cheers,
Derek
On 2/3/2012 10:09 AM, Matheus de Oliveira wrote:
Even better:
SELECT COALESCE(value_of_interest, 'more friendly message') value_of_interest
From poly_table left outer join data_table one poly_table.common_id = data_table.common_id
--
Matheus de OliveiraOn Fri, Feb 3, 2012 at 1:05 PM, Matheus de Oliveira <matioli.matheus@gmail.com> wrote:Try that:
SELECT address, CASE WHEN value_of_interest IS NULL THEN 'more friendly message' ELSE value_of_interest END value_of_interest--
From poly_table left outer join data_table one poly_table.common_id = data_table.common_id
Matheus de OliveiraOn Fri, Feb 3, 2012 at 10:45 AM, John Morgan <jdmorgan@unca.edu> wrote:Hello,I am doing a left outer join between a polygon table and a data table.Everythingreturns fine from this join as expected. However, there are cases wherethere isn?t data for a given polygon and this return as the expected nullin the result set. I would like to utilize something like a case statementto catch the nulls and return a ?more friendly? message. I have triedunsuccessfully to use the following logic:*Select case value_of_interest null then ?more friendly message? elsevalue_of_interest end**From poly_table left outer join data_table one poly_table.common_id =data_table.common_id*If someone could let me know where I am going wrong it would be greatlyappreciated.Cheers,Derek
-- Derek @ NEMAC