Forums

This topic is locked

stored procedure

Posted 11 Feb 2005 20:28:19
1
has voted
11 Feb 2005 20:28:19 Jaime Romo posted:
hello there..... i need hepl with this.......
i have a page that send variables and in the result page i whant to use a stored procedure insted of a recordset how do i do the sotored procedure sending the varaible 'anuncio' and returning all the data from the table.....

thanks


Visit my home page
www.cancuncoral.com

Replies

Replied 16 Feb 2005 23:03:25
16 Feb 2005 23:03:25 Daniel Severns replied:
Jaime,
Im not sure what you mean by stored procedure or what you want to do with it. Im assuming that your using SQL and I think an easy way to accomplish a stored "query" if you will, is to create a "view". A view will re-use a query that you define once. If you need help with creating the view, please post it here.
Also, please provide what languages you are using, ASP, PHP, VBScript.... and are you sending data from a form to another page or from a recordset?

Daniel
Replied 17 Feb 2005 11:25:33
17 Feb 2005 11:25:33 Lee Diggins replied:
Hi Jaime

Following on from Daniel's comments, here's quick example of a stored procedure and as Daniel says, stored procedures are SQL and not Access.

CREATE PROCEDURE sp_myStoredProcedure(@anuncio(varchar(50))

AS

SELECT myColumn1, myColumn2

FROM myTable

WHERE myColumn1 = @anuncio

ORDER BY myColumn1

All SQL variables use the @ symbol, this can be called anything you like and doesn't have to be the same name as the variable being used in your web page. You must declare what datatype the variable will be - varchar(50) - this usually matches the datatype of the column that variable is going to be used against.

On your web page you would need to create a command with the type 'stored procedure' and tick the box 'return recordset named' and give it a name. Expand the stored procedure list in the 'database items' window and select the stored procedure you wish to use, you must create the stored procedure first to view it in the list. DW will then populate the variables window with @RETURN_VALUE and in the example above, the variable @anuncio will also be displayed. You need to supply the datatype, which maybe pre populated and the size, in this example 50. You also need to supply a default value, meaning if no value is passed to the stored procedure, what would you want to return in the recordset, I personally put in a value that does not appear in the target column, so an empty recordset is returned. Last thing, you need to supply the run-time value, this could be from a form or a link on your page or as Daniel says, from another recordset - something like Request.Form("myField", Request.QueryString("myField", rsMyData.Fields.Item("myColumn1".Value etc., etc..

You can then use and display the recordset results in the normal way.

Daniels suggestion of a view is an excellent one and can be used in a similar way, you may wish to persue this option.

Post back if you get stuck

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
Lee Diggins - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Replied 18 Feb 2005 15:47:39
18 Feb 2005 15:47:39 Daniel Severns replied:
Thanks Lee, that was a very nice reply and you taught me some valuable information too!

Regards,
Daniel
Replied 18 Feb 2005 16:18:44
18 Feb 2005 16:18:44 Lee Diggins replied:
Hi Daniel

You're welcome, that's what we're here for <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
Lee Diggins - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>

Reply to this topic