Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Specify default values for NULL values in target fields..

Status
Not open for further replies.

gunsva

Technical User
Aug 23, 2001
6
US
When I am loading a target table, some fields are being explicitly set to NULL, as per the business requirements. Reporting requires that all target fields with NULL values be set to at least a single space for string fields, 0 for numeric fields.
What is the easiest way to achieve this ? Thanks.
 
To amplify on COALESCE -

Where I'm currently contracting the customer has multiple strings from various sources that represent NULLs of different data types. We can get NULLs, or strings for VARCHAR fields for example.

The direct example that answers your question would be

COALESCE(column, 'NO DATA')

However, frequently the COALESCE needs to be in a CASE to handle both NULLS, and various NULL representations, for
example:
<snip>
CASE
WHEN column = 'BK' THEN 'NO DATA'
WHEN column = 'NK' THEN 'NO DATA'
WHEN column = ' ' THEN 'NO DATA'
WHEN column = 'DX' THEN 'NO DATA'
ELSE COALESCE(column, 'NO DATA')
END
<snip>

The above takes in all the various VARCHAR representations of NULL, plus NULL and replaces them with a consistent NULL representation of 'NO DATA'.

Regards

Randy Volters
Certified Teradata Master
Class of '01
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top