Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
create procedure StudentTimeLineByUserCode( _userCode varchar(20), _startDate datetime, _endDate datetime)
 
Begin

SET @strTblQuery = concat("select * from ", _userCode, "_", "Timeline" where dateCreated>=_startDate AND dateCreated<=_endDate);

    SELECT @strTblQuery;

        PREPARE stmt1 FROM @strTblQuery;
        EXECUTE stmt1;
        DEALLOCATE PREPARE stmt1;

 end
Posted
Updated 29-Jan-14 23:01pm
v2
Comments
thatraja 30-Jan-14 5:01am    
what's the error? always include those details in your question
[no name] 30-Jan-14 5:03am    
Execution Error
thatraja 30-Jan-14 5:04am    
We need complete error message. Always include complete details in your question
[no name] 30-Jan-14 5:08am    
Error is near WHERE clause
[no name] 30-Jan-14 5:05am    
execution Error near where clause

1 solution

This line has wrong quote-pairs...
SET @strTblQuery = concat("select * from ", _userCode, "_", "Timeline" where dateCreated>=_startDate AND dateCreated<=_endDate);

Try this...
SET @strTblQuery = concat("select * from ", _userCode, "_Timeline where dateCreated>='",_startDate, "' AND dateCreated<='",_endDate,"'");
 
Share this answer
 
v2
Comments
[no name] 30-Jan-14 5:16am    
after using u r solution, sp got created but ERROR in calling sp

call StudentTimeLineByUserCode ('UA14', '2013-07-12 02:50:20', '2014-01-25 08:44:03')
thatraja 30-Jan-14 5:21am    
Again you're doing the same mistake. You should include the error message too in your reply. Without those details we can't help you.
[no name] 30-Jan-14 5:29am    
When i am calling the sp

call StudentTimeLineByUserCode ('UA14', '2013-07-12 02:50:20', '2014-01-25 08:44:03')

ERROR IS:

SQL Execution Error #1064. Response from the database
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 '02:50:20 AND dateCreated <=2014-01-25 08:44:03' at line 1
Kornfeld Eliyahu Peter 30-Jan-14 5:37am    
You have to enclose your date values with quotes...
See update
[no name] 30-Jan-14 5:40am    
I have enclosed with quotes

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900