This actually does something rather useful (maybe a first for my blog!), well to me anyway. It returns the distance modulus (the logarithm of the ratios of apparent to absolute brightnesses, equal to the difference of absolute magnitude to apparent magnitude) using an approximate method for calculating the luminosity distance (the distance at which an astronomical body would lie based on its observed luminosity in the absence of any unanticipated attenuation) so that numerical integration is avoided. The approximate method essentially is to use a CDM Universe. Since I don't need this to be the most accurate this method should be fine however if I find this isn't suitable I will have to go back to the lambda CDM and do the numerical integration. Anyway here is the SQL code I have used for this task (the useful line begins with a CAST):
SELECT
objID AS objID, plate AS plate, mjd AS mjd, fiberid AS fiberid, z AS Z,
CAST ( -5.0000000 * LOG10(8450700000 * ((1 + z) - (SQRT(1 + z))) / 10 ) as float) as D_MOd
INTO mydb.z_2
FROM mydb.z_1
Terms confusing?? Take a look at these links for more:
Distance Modulus - [Wolfram]
Luminosity Distance - [Wolfram]
Numerical Integration - [Wikipedia]
Dark Matter - [Martin White]







