MD5
MD5

Reputation: 1

stored procedure variable

I would like to set up a query in a stored procedure like:

select * from table where xx between '2010' and '2011' 

To use some variable (time) instead of the static timestamp. However once I set up the variable and query like

"select * from table where xx between time and time" or

"select * from table where xx between 'time' and 'time'", 

it doesn't work, could you help me

thx in advance

Upvotes: 0

Views: 144

Answers (1)

Alain Collins
Alain Collins

Reputation: 16362

It would probably be easier if we had real code, but, based on what you've provided, I'd say:

  1. "time" is a function name in mysql. While it's not listed as a reserved word, it would still scare me to use it as such.
  2. I don't believe that "between" can be parameterized with variables. Not 100% on this, though.
  3. I'd try "where my_time > start_time and my_time < end_time"

Hope that helps.

Upvotes: 1

Related Questions