![]() |
| |||||||
| Sponsored Links |
![]() |
| | LinkBack | Thread Tools | Display Modes |
|
#11
| ||||
| ||||
| The reason I was looking at the SP was this particular query always seems to take quite a long time to run in .NET, whereas when I tested it in the query browser it was taking less than half a second. I'm sure the delay is DB related as other queries to the same table are much quicker... |
| Sponsored Links |
|
#12
| ||||
| ||||
| RR; I didn't take the time to unravel all the logic in your SP, but it appears in mySQL that you can PREPARE..EXECUTE a query whilst substituting parameters. In you case, consider if you can build your dynamic query in such a way to use parameters in the EXECUTE statement rather than building them into the query. Such as the very simple example: Code: SET @s = 'SELECT * FROM authors WHERE id BETWEEN ? AND ?';
SET @min = _min;
SET @max = _max;
PREPARE stmt1 FROM @s;
EXECUTE stmt1 USING @min, @max;
DEALLOCATE PREPARE stmt1;
__________________ Wolffy ------------------------ Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary. |
| The Following User Says Thank You to Wolffy For This Useful Post: | ||
richyrich (June 11th, 2008) | ||
|
#13
| ||||
| ||||
| Yeah I did see that Wolffy, but wasn't sure if I could get the order of the parameters right. I assume it drops the USING values into the query in the order they are placed. I was wondering if you could do the same but name them. |
|
#14
| ||||
| ||||
| Yeah, now I see what you mean. I was trying to figure out a way to do this while having the same parameters in the same position regardless of query -- but that's going to make for some really inefficient queries. Take the rather simple example of your conveyor predicate: Code: IF iconveyor <> '' AND iconveyor<>'all' THEN SET _conveyor = ' AND visitors.conveyor = ?'; ELSE SET _conveyor = ' AND visitors.conveyor LIKE ?; SET @iconveyor = '%'; END IF; |
|
#15
| ||||
| ||||
| I think I got it sorted. No changes to my SP. In .NET used the following code to add the parameters:- Code: Dim mycommand as new mysqlcommand("clientlist",conn)
Dim isurname as MySqlParameter = mycommand.parameters.Add("isurname",mysqldbtype.varchar)
isurname.value = search.surname
Hope that helps someone... |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Stored Procedures on MySQL | richyrich | MySQL | 7 | June 9th, 2008 11:15 AM |
| Parameterized Dynamic Query | Shem | .Net Development | 4 | June 6th, 2008 10:20 AM |
| 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 |