Ravi Malghan wrote:
> Hi: I have a statement such as follows
>
> SELECT EVENT_DATA.dstport WHERE
> FROM_UNIXTIME(utime,'%Y-%m-%d') = (CURDATE() -
> INTERVAL 1 DAY) ORDER BY EVENT_DATA.utime;
>
> Instead of using a value of 1 for interval, I want to
> pass parameters so it will ask for the value when the
> sql statement is run.
You can put it in a prepared statement
(http://dev.mysql.com/doc/refman/5.1/en/sqlps.html), eg
set @sql = "SELECT EVENT_DATA.dstport
WHEREFROM_UNIXTIME(utime,'%Y-%m-%d') = (CURDATE() -INTERVAL ? DAY) ORDER
BY EVENT_DATA.utime";
PREPARE stmt FROM @sql;
set @x = 7;
EXECUTE stmt USING @x;
DROP PREPARE stmt;
and you can put all that in a stored procedure, passing in the number of
days as a param.
PB
----
> I have tried searching in google
> and www.mysql.org and have not had any luck. Does
> mysql use different definitions? or can someone
> provide some pointers on the web which explains how to
> pass parameters with SQL statement.
>
> Thanks
> Ravi
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com>
>
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.385 / Virus Database: 268.4.0/306 - Release Date: 4/9/2006

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.