Fix Select in stored proc

Fixes #762