If this works in a PRG and not from the form, then the form may be returning a different variable, perhaps padded on the end with spaces; if your PRG arbitrarily sets CNAME="John", then your variable length is 4, but if you are getting the variable from a text box of length 10, then your variable is actually "John ", which your SELECT statement can't find.