![]() |
| |||||||
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
| ||||
| I thought I'd try adding some stored procedures to my MySQL db, to see if it improves performance. I have a list of clients with a number of options to filter the list. At the moment I build the query as a string in .NET and then execute it on the db. What I am trying to do is pass the various filter options to the SP and build the query in the SP. How would you go about doing this in an SP? And, how do you pass parameters to the query inside the SP? Is it the same as you'd pass them to a query? I tried this simplified version from an example on the MySQL site, but it just returned "Number of rows affected:-1", which I believe means there's an error somewhere. Code: CREATE PROCEDURE clientlist
(pcuser INT, istatus INT)
BEGIN
DECLARE _status VARCHAR (50);
IF istatus = 5 THEN
SET _status = ' AND visitors.status<>5';
ELSE
SET _status = ' AND visitors.status=1';
END IF
SET @strsql = CONCAT('SELECT visitorref,forename,surname,clientstatus.status FROM visitors,clientstatus WHERE visitors.status=clientstatus.statusref',_status);
PREPARE stmt FROM @strsql;
EXECUTE stmt;
END;
Thanks |
| Sponsored Links |
| The Following User Says Thank You to Wolffy For This Useful Post: | ||
richyrich (June 9th, 2008) | ||
| ||||
| i don't see anything different in what you're doing, then what i'm finding. Code: DELIMITER \\
CREATE PROCEDURE clientlist (
pcuser INT,
istatus INT
)
BEGIN
DECLARE _status VARCHAR (50);
IF istatus = 5 THEN
SET _status = 'AND visitors.status<>5';
ELSE
SET _status = 'AND visitors.status=1';
END IF
SET @strSQL = CONCAT('SELECT visitorref,forename,surname,clientstatus.status FROM visitors,clientstatus WHERE visitors.status=clientstatus.statusref ',_status);
PREPARE stmt1 FROM @strSQL;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
END \\
DELIMITER ;
Code: CALL clientlist('pc_user',5)
__________________ Quote of the Month: Strife: As long as we have each other, we'll never run out of problems. Questions to Ponder: Should vegetarians eat animal crackers? iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm") copyright © 2008 sbenj69 |
| ||||
| Yeah, I know. I've tried all sorts of things. It creates the procedure fine, but just won't run it. I've even tried something really basic:- Code: CREATE PROCEDURE p4 () SELECT 'Hello, world'; And Code: CREATE PROCEDURE p4 () BEGIN SELECT 'Hello, world'; END; I've posted on the MySQL forum to see if they can suggest anything. Very frustrating... ![]() |
| ||||
| I think that delimiter is just if you are entering the sproc from the console line by line (the equivalent of iSQL) since the semicolon is required sytanx in the sproc itself. |
| ||||
| OK. I think I may have sorted it. I downloaded the most recent MySQL Query browser, typed it into that and it executed with no problem. Called the SProc and it worked fine. Must be related to the software I was using. I found a post about a similar problem on the MySQL forum and thought I'd give it a go.. ![]() Strange how the software you're using can affect what gets saved but there you go!! ![]() Shame I've wasted a whole day finding that out... ![]() |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| If statement stored procedure | peebman2000 | SQL Development | 32 | May 23rd, 2008 03:54 PM |
| Dynamic Stored Procedure | jmurrayhead | Microsoft SQL Server | 16 | March 26th, 2008 11:19 AM |
| Permissions on Tables, Stored Procedures, etc. | theChris | Microsoft SQL Server | 2 | March 24th, 2008 11:49 AM |
| Sponsored Links |
| ASP.NET Resource Index a directory of ASP.NET tutorials, applications, scripts, assemblies and articles for the novice to professional developer. Free Web Directory Including Chats and Forums Resources, Offer automatic, instant and free directory submissions. | URLZ Web Directory URLZ Web Directory Free Web Directory - Add Your Link The Little Web Directory | Free Web Directory Pegasus free web directory is a free directory organised by categories. Web Directory & SEO Services dirroot web directory |