If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
Is it possible to return a real value instead of a null value
Using SQL, Is it possible to echo a real value like "Pending" if and when a field is null? I have 5 columns in my result set. 3 of these 5 will have null values for a time until the user updates the table. In my app code, I would have to test for null values and then write the proper code to echo something in its place until the value was available. Is it possible to do this with SQL? It would save me a small headache if this was possible.
In my app code, I would have to test for null values and then write the proper code to echo something in its place until the value was available. Is it possible to do this with SQL? It would save me a small headache if this was possible.
The other option might be to just store the value "Pending" rather than storing NULL and later decoding it.
I often come across databases where each record has a status value of 1,2,3 and perhaps -2 and -5 are then added as error conditions. Then perhaps every year some new developer will add some new codes like 51 and 52 etc. Some of these new codes will invariably be almost identical to some existing forgotten codes. I personally dislike these integer codes for statuses but figure people put them in for various reasons:
Because it saves space - it might be noticeable in a db with billions of records but invariably, in most db's, it hardly makes any saving. The code on the other hand becomes bloated and unreadable - each sproc will be full of code like where status_id in ( 1,3,-5,0 ) which means nothing to man nor beast.
Because it goes faster - I suppose the indexes will be more compact with more more nodes on a given part of the b-tree but to be honest I doubt if you'd notice any difference in real life. Also if you have to join with another table to be able to decode your integer status values then you've probably lost any perceived gain.
Because they can add extra functionality to their codes - ie where status_id < 0. It might work while the original designer is still working there but it quickly degenerates into unreadable code. A better way might be to use flags within the status table.
Because it looks more like a proper database - this is the funniest reason to me but I suspect that's why most designers do it.
There may be a few cases where integer status id's might be better but, for most of the databases I've come across, they'd of been far better making their data readable and the code clearer by avoiding using integer status values.