Home > Archive > PHP SQL > September 2005 > How to use a value in table in query?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to use a value in table in query?
|
|
| Mick White 2005-09-23, 6:58 pm |
| mysql> select * from G;
+------------+-----------+----------------+--------+
| first_name | last_name | modified | offset |
+------------+-----------+----------------+--------+
| Mick | White | 20050923102539 | -5 |
+------------+-----------+----------------+--------+
1 row in set (0.00 sec)
mysql> select ADDDATE(modified,INTERVAL -5 HOUR) from G;
+------------------------------------+
| ADDDATE(modified,INTERVAL -5 HOUR) |
+------------------------------------+
| 2005-09-23 05:25:39 |
+------------------------------------+
1 row in set (0.02 sec)
How could I substitute `offset` value for -5 ?
mysql> select ADDDATE(modified,INTERVAL,offset HOUR) from G;
This produces an error (server version: 4.0.25-standard)
Mick
| |
| Stefan Rybacki 2005-09-23, 6:58 pm |
| Mick White wrote:
> mysql> select * from G;
> +------------+-----------+----------------+--------+
> | first_name | last_name | modified | offset |
> +------------+-----------+----------------+--------+
> | Mick | White | 20050923102539 | -5 |
> +------------+-----------+----------------+--------+
> 1 row in set (0.00 sec)
>
> mysql> select ADDDATE(modified,INTERVAL -5 HOUR) from G;
> +------------------------------------+
> | ADDDATE(modified,INTERVAL -5 HOUR) |
> +------------------------------------+
> | 2005-09-23 05:25:39 |
> +------------------------------------+
> 1 row in set (0.02 sec)
>
> How could I substitute `offset` value for -5 ?
>
> mysql> select ADDDATE(modified,INTERVAL,offset HOUR) from G;
>
> This produces an error (server version: 4.0.25-standard)
> Mick
>
What is the error you get? Did you try to enclose offset in `?
| |
| Mick White 2005-09-23, 9:56 pm |
| Stefan Rybacki wrote:
> Mick White wrote:
>
>
> What is the error you get? Did you try to enclose offset in `?
I found the problem:
mysql> select ADDDATE(NOW(),INTERVAL offset HOUR) as minus_5 from G;
+---------------------+
| minus_5 |
+---------------------+
| 2005-09-23 15:19:41 |
+---------------------+
1 row in set (0.00 sec)
I had a comma after`INTERVAL`
|
|
|
|
|