SQL for Smarties | SQL Programming Style | Trees and Hierarchies in SQL | SQL Puzzles and Answers | Data and Databases


Monday, June 12, 2006

Concat Null Yields Null Woes..

SQL Apprentice Question
I have a bunch of views that concat fileds, some of which allow nulls
so I am using the isNull function when joining them. I dont want to
have to do this, I want to set the database so that concat null does
not yield null for all views and procedures.

How do I do this this in EM ?
I read and tried a bunch of stuff on this but nothings worked so far.


Please dont reply telling me to use the concat null yields null
setting - I think I know what needs doing - but I dont know "How" to do
it!


Celko Answers
>> I have a bunch of views that concat fields [sic], some of which allow NULLs so I am using the ISNULL() function when joining them. I dont want to have to do this, I want to set the database so that concat NULL does not yield NULL for all views and procedures. <<


Oh, you want to write your own language and not bother with SQL! This
behavior is one of many reasons that columns are not anything like
fields and why I jump on newbies to actually read a book about the
language before they start coding.


>> Please dont reply telling me to use the concat null yields null setting - I think I know what needs doing - but I dont know "How" to do <<


Nobody should be so irresponsible as to give you that advice. Your
code would not port, would not work properly, etc. what needs doing
is a bit more education on your part instead of looking for kludges to
save yourself some typing. Also, why aren't you using QA or a code
editor instead of EM?

SQL programmers think of the schema as a whole. The first place to
look is the DDL and the Data Dictionary (which you probably do not
have, if you have that many NULLs). Which of these columns really
should be blanks, empty strings or other defaults and not NULL-able at
all? I will bet most of them, based on two decades of cleaning up
SQL.


You will find that most bad DML are kludges made in response to bad
DDL.

No comments: