Type casting sql insertions

Fiddly. But Sql is close to kicking arse.