Passing a table name to Stored Proc

Results 1 to 2 of 2

Thread: Passing a table name to Stored Proc

  1. #1
    Rob Guest

    Default Passing a table name to Stored Proc

    I have 5 fields of prices. Which price displays depends<BR>on what the user is logged in as. I want to put this<BR>query in to a stored and pass the Price field.<BR><BR>This code works<BR><BR>Price = request.form("PriceLevel")<BR>SELECT Code,Title,"&Price&" from Products<BR><BR>But how would I put this code in a stored and pass the fieldname?<BR><BR>Thnaks,<BR><BR>Rob<BR><BR><BR><B R>

  2. #2
    F. Guest

    Default RE: Passing a table name to Stored Proc

    One of us needs to learn stored procs and it ain&#039t me. Sorry to be harsh but it&#039s back to the books for you.<BR><BR>Right, for starters, your stored proc should read something like:<BR><BR>CREATE dbo.MyProc<BR>(@PriceLevel int)<BR>AS<BR>SELECT Code,Title,Price from Products WHERE Price=@PriceLevel<BR><BR>Then you save this and make sure your web application can view this stored proc by changing the settings in Enterprise Manager.<BR><BR>In your ASP Page, you set up your connection object and your recordset object (look it up if you don&#039t know how). Let&#039s say you called them MyConn and MyRS respectively. You then write somewhere underneath: <BR><BR>strSQL="EXEC dbo.MyProc @PriceLevel=" & Request.Form("PriceLevel")<BR>MyRs=strSQL, MyConn<BR><BR>MyRS will now hold all the results of that select query you set up earlier.<BR><BR>Ho hum.<BR><BR>F.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts