Help me create sql command to force profile

I need help forcing logged in users without a profile to only be able to view the create profile form until their profile is created

The commands will measure values in the rsdirectory tables comparing the number of entries to the userid. It will also make sure that the entry is published, which i think is a 0 or 1 value.

Can we start with a basic template and then build a workable code together?