Can't seem to Compare MySQL Statement

Hello,
I am having a problem seeing if a SQL statement worked or not… I know
I’m not really doing my SQL statement the proper ‘RoR’ way, but I don’t
think that is the problem. My code is supposed to query the database
where the displayname = the posted legalname. If no results are
returned, then do the same query, but where displayname = the posted
othername. The problem is when it evaluates if @compare_bes == nil…
even if it doesn’t return results, it won’t execute the stuff within the
IF statement.

@compare_bes = Bes.connection.select_all("
SELECT *
FROM bes
WHERE
bes.bes_displayname = ‘#{params[:legalname]}’")

if @compare_bes == nil <— THIS IS THE PROBLEM
@compare_bes = Bes.connection.select_all("
SELECT *
FROM bes
WHERE
bes.bes_displayname = ‘#{params[:othername]}’")

end

So I am not sure what do use to evaluate if the first query is empty. I
tried @compare_bes == ‘’, == “”, unless @compare_bes, unless
@compare_bes != nil, etc…

Does anybody know how to do this?

Any help is appreciated!

Thanks,

  • Jeff M.

Have you tried:

if @compare_bes.empty?

On Mar 13, 3:31 pm, Jeff M. [email protected]

Have you tried:

@compare_bes.empty?

On Mar 13, 5:31 pm, Jeff M. [email protected]

that worked perfectly! I have to remember that. Thanks!!

No problem!

On Mar 13, 4:11 pm, Jeff M. [email protected]