Hi, I've been trying to find what is causing my problem here but I couldn't find any. I had a similar code and it works just fine.. This code always gives me a failed result.. The problem starts in IF - IF v_start_date > v_dateNow THEN
-
INSERT INTO playlist_summary(playlist_name,playlist_id,playlist_status,plate_number,exposure) SELECT playlists.playlist_name,playlists.playlist_id,playlists.playlist_status,taxi.plate_number FROM playlists
-
JOIN playlist_terminal
-
ON playlist_terminal.userid = i_userid
-
JOIN taxi
-
ON taxi.terminal_id = playlist_terminal.terminal_id
-
WHERE playlists.userid = i_userid AND playlists.playlist_id = i_playlistid;
-
-
ELSE IF v_end_date = '0000-00-00 00:00:00' THEN
-
-
INSERT INTO playlist_summary(playlist_name,playlist_id,playlist_status,plate_number,exposure) SELECT playlists.playlist_name,playlists.playlist_id,playlists.playlist_status,taxi.plate_number,
-
((((SUM(total_uptime.total_on_hours)) + total_uptime_perday.total_on_hours)*(60*60))/10)/(taxi.slots_taken + 3) AS exposure FROM playlists
-
JOIN playlist_terminal
-
ON playlist_terminal.userid = i_userid
-
JOIN taxi
-
ON taxi.terminal_id = playlist_terminal.terminal_id
-
JOIN total_uptime
-
ON total_uptime.terminal_id = playlist_terminal.terminal_id
-
JOIN total_uptime_perday
-
ON total_uptime_perday.terminal_id = playlist_terminal.terminal_id
-
WHERE playlists.userid = i_userid AND playlists.playlist_id = i_playlistid AND total_uptime.start_time BETWEEN playlists.start_date AND (subdate(end_date,-1))
-
GROUP BY playlist_terminal.ref_number;
-
-
ELSE
-
-
INSERT INTO playlist_summary(playlist_name,playlist_id,playlist_status,plate_number,exposure) SELECT playlists.playlist_name,playlists.playlist_id,playlists.playlist_status,taxi.plate_number,
-
(((SUM(total_uptime.total_on_hours))*(60*60))/10)/(taxi.slots_taken + 3) AS exposure FROM playlists
-
JOIN playlist_terminal
-
ON playlist_terminal.userid = i_userid
-
JOIN taxi
-
ON taxi.terminal_id = playlist_terminal.terminal_id
-
JOIN total_uptime
-
ON total_uptime.terminal_id = playlist_terminal.terminal_id
-
JOIN total_uptime_perday
-
ON total_uptime_perday.terminal_id = playlist_terminal.terminal_id
-
WHERE playlists.userid = i_userid AND playlists.playlist_id = i_playlsitid AND total_uptime.start_time BETWEEN playlists.start_date AND (subdate(end_date,-1))
-
GROUP BY playlist_terminal.ref_number;
-
-
END IF;
-
END IF;
6 1178 Luuk 1,047
Expert 1GB
"The problem starts in IF", and what is the exact error message?
Luuk 1,047
Expert 1GB
IF it's this one: - ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IF ........
Then the SQL syntax is wrong.
This is the error I am getting -- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF.... at line 1
Luuk 1,047
Expert 1GB
a SQL statement can not start with 'IF'.
i do not see any reference to 'v_start_date', 'v_dateNow' or 'v_end_date' in your SQL-statements.
Can you explain what you want to achieve?
(It would be of help if the table structure is given for the tables used, and possible some sample data)
I'm sorry not being clear. Here's my complete code - CREATE DEFINER=`root`@`localhost` PROCEDURE `playlist_summary_exposure`(
-
IN i_userid INT(11),
-
IN i_playlistid INT(11)
-
-
)
-
BEGIN
-
-
DECLARE v_start_date DATE;
-
DECLARE v_dateNow DATE;
-
DECLARE v_end_date DATE;
-
-
DECLARE o_success BOOLEAN;
-
DECLARE o_message VARCHAR(255);
-
-
SELECT start_date FROM playlists WHERE userid = i_userid INTO v_start_date;
-
SELECT DATE(NOW()) INTO v_dateNow;
-
SELECT end_date FROM playlists WHERE userid = i_userid INTO v_end_date;
-
-
DELETE FROM playlist_summary;
-
-
IF v_start_date > v_dateNow THEN
-
INSERT INTO playlist_summary(playlist_name,playlist_id,playlist_status,plate_number,exposure) SELECT playlists.playlist_name,playlists.playlist_id,playlists.playlist_status,taxi.plate_number FROM playlists
-
JOIN playlist_terminal
-
ON playlist_terminal.userid = i_userid
-
JOIN taxi
-
ON taxi.terminal_id = playlist_terminal.terminal_id
-
WHERE playlists.userid = i_userid AND playlists.playlist_id = i_playlistid;
-
-
ELSE IF v_end_date = '0000-00-00 00:00:00' THEN
-
-
INSERT INTO playlist_summary(playlist_name,playlist_id,playlist_status,plate_number,exposure) SELECT playlists.playlist_name,playlists.playlist_id,playlists.playlist_status,taxi.plate_number,
-
((((SUM(total_uptime.total_on_hours)) + total_uptime_perday.total_on_hours)*(60*60))/10)/(taxi.slots_taken + 3) AS exposure FROM playlists
-
JOIN playlist_terminal
-
ON playlist_terminal.userid = i_userid
-
JOIN taxi
-
ON taxi.terminal_id = playlist_terminal.terminal_id
-
JOIN total_uptime
-
ON total_uptime.terminal_id = playlist_terminal.terminal_id
-
JOIN total_uptime_perday
-
ON total_uptime_perday.terminal_id = playlist_terminal.terminal_id
-
WHERE playlists.userid = i_userid AND playlists.playlist_id = i_playlistid AND total_uptime.start_time BETWEEN playlists.start_date AND (subdate(end_date,-1))
-
GROUP BY playlist_terminal.ref_number;
-
-
ELSE
-
-
INSERT INTO playlist_summary(playlist_name,playlist_id,playlist_status,plate_number,exposure) SELECT playlists.playlist_name,playlists.playlist_id,playlists.playlist_status,taxi.plate_number,
-
(((SUM(total_uptime.total_on_hours))*(60*60))/10)/(taxi.slots_taken + 3) AS exposure FROM playlists
-
JOIN playlist_terminal
-
ON playlist_terminal.userid = i_userid
-
JOIN taxi
-
ON taxi.terminal_id = playlist_terminal.terminal_id
-
JOIN total_uptime
-
ON total_uptime.terminal_id = playlist_terminal.terminal_id
-
JOIN total_uptime_perday
-
ON total_uptime_perday.terminal_id = playlist_terminal.terminal_id
-
WHERE playlists.userid = i_userid AND playlists.playlist_id = i_playlsitid AND total_uptime.start_time BETWEEN playlists.start_date AND (subdate(end_date,-1))
-
GROUP BY playlist_terminal.ref_number;
-
-
END IF;
-
END IF;
-
-
-
COMMIT;
-
-
-
SELECT o_success AS success,o_message AS message;
-
END
It's a stored procedure.
Luuk 1,047
Expert 1GB
I do not see anything wrong. If you get errors it might have something to do with the data.
some tips
Line 15 and 17 can be combined to: -
SELECT start_date, end_date FROM playlists WHERE userid = i_userid INTO v_start_date, v_end_date;
-
Be sure there is a space on line 29 after 'ELSE', because if there i no space, the second 'END IF' (line 60) is wrong
(see: http://dev.mysql.com/doc/refman/5.6/en/if.html)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: mike |
last post by:
Ok, I have a page that queries a database and retrieves values to
create a custom report in ms excel format on the fly so that it can be
downloaded. I can use the following sub to generate the...
|
by: craig |
last post by:
RH 9.0
user mysql
command /usr/sbin/mysqld
mysql is being loaded at boot. the previous is listed when I check
what process are running with < ps -aux >
however:
$ ./bin/mysqladmin version
|
by: josys64 |
last post by:
i have a strange problem :
MySQL 4.0.21 innodb and php 4.3.9-1
all tables are in innodb type.
For a simple select statement sometimes i get result and sometimes
nothing (i.e mysql_num_rows()>0...
|
by: Randy Foster |
last post by:
We have a stored procedure (on DB2 8.1 FP5) that returns multiple
result sets which we are calling from Java (WebSphere 5.0.2.8).
We can call the stored procedure from the DB2 command line...
|
by: Felix_Jiang |
last post by:
The following code returns different result when running on dotnetFramework
1.1 and 2.0. For 1.1, it returns "Object". For 2.0, it returns "String". Can
anyone explain to me why? Thanks!
...
|
by: priya19 |
last post by:
Warning: open(/tmp\sess_b609ea08fa1da72b0daef1233c822e7b, O_RDWR) failed: m (2) in C:\apache\htdocs\cmi\quick_find.php on line 2
Warning: MySQL Connection Failed: Can't connect to MySQL server on...
|
by: Akino877 |
last post by:
Hello,
I have a small Perl program :
#!/usr/bin/perl -w
use DBI;
use Mysql;
$host = "";
$database = "";
$user = "root";
|
by: javakid |
last post by:
Hi MySQL Gurus,
I have a query as in following format:
update tbl1, ( subquery )as tbl2
set tbl1.col1 = IFNULL(tbl2.col1,0)
where tbl1.col2 = tbl2.col2Here, Actually i am returning a...
|
by: unpresedented |
last post by:
I have this query (that runs on Oracle 10g database):
SELECT
ge.*, ge.concept AS glossarypivot FROM s_glossary_entries ge WHERE (ge.glossaryid = '161' OR ge.sourceglossaryid = '161')
AND...
|
by: mike j |
last post by:
Hi everyone,
If anyone could help me with this problem I'd appreciate it greatly. Basically I have a simple table on my database. It is linked with a php form that I created on my site. The php...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |