# Can't seem to Compare MySQL Statement

**URL:** <https://www.ruby-forum.com/t/cant-seem-to-compare-mysql-statement/131866>\
**Category:** Rails\
**Created:** [March 13, 2008, 11:31pm UTC](https://www.ruby-forum.com/t/cant-seem-to-compare-mysql-statement/131866 "2008-03-13T23:31:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [March 13, 2008, 11:31pm UTC](https://www.ruby-forum.com/t/cant-seem-to-compare-mysql-statement/131866/1 "2008-03-13T23:31:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [March 13, 2008, 11:44pm UTC](https://www.ruby-forum.com/t/cant-seem-to-compare-mysql-statement/131866/2 "2008-03-13T23:44:29Z")

</div>

Have you tried:

if @compare\_bes.empty?

On Mar 13, 3:31 pm, Jeff M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [March 13, 2008, 11:46pm UTC](https://www.ruby-forum.com/t/cant-seem-to-compare-mysql-statement/131866/3 "2008-03-13T23:46:51Z")

</div>

Have you tried:

@compare\_bes.empty?

On Mar 13, 5:31 pm, Jeff M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [March 14, 2008, 12:11am UTC](https://www.ruby-forum.com/t/cant-seem-to-compare-mysql-statement/131866/4 "2008-03-14T00:11:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [March 14, 2008, 12:16am UTC](https://www.ruby-forum.com/t/cant-seem-to-compare-mysql-statement/131866/5 "2008-03-14T00:16:49Z")

</div>

No problem!

On Mar 13, 4:11 pm, Jeff M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
