Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why did I write this code?
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01682961
Message ID:
01682963
Views:
74
>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))  && Let say you have Primary key based on Fld1
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
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform