>>Hi,
>>
>>I know I should not be admitting to writing some stupid code. But I was refactoring code in one method where I have the following, in a long SQL Select.
>>
>>isnul( table1.table_pk,11) as table1_pk
>>
>>Since this is a PK value of a table, it should never be NULL.
>>But suppose I was being extra cautious, why "11"?
>>
>>Please no name calling :)
>
>Maybe this is from LEFT join to table1.
>If it is so you can have NULL values in the query.
>
>WHY 11? Only you can tell :-)
>Maybe 11 is impossible value and that way you recognize these records?
>
>The example is from VFP but it is valid to TSQL too
>
>CREATE CURSOR Tbl1 (Fld1 int, Fld2 char(2))
>INSERT INTO Tbl1 (Fld1, Fld2) VALUES (1, [aa])
>INSERT INTO Tbl1 (Fld1, Fld2) VALUES (2, [bb])
>
>CREATE CURSOR Tbl2 (Fld1 int, Fld2 char(2))
>INSERT INTO Tbl2 (Fld1, Fld2) VALUES (1, [cc])
>INSERT INTO Tbl2 (Fld1, Fld2) VALUES (2, [dd])
>INSERT INTO Tbl2 (Fld1, Fld2) VALUES (3, [ee])
>
>SELECT Tbl2.*,;
> NVL(Tbl1.Fld1, 11) AS Tbl1Fld1;
>FROM Tbl2;
>LEFT JOIN Tbl1 ON Tbl2.Fld1 = Tbl1.Fld1
>
Your point about the LEFT join makes sense. The SQL Select does have a LEFT joint of the same table. Which I am trying to eliminate. And I will check the code, down from this SQL Select, if the value 11 is being considered anywhere (as possible).
Thank you!
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham