Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change SQL Object with ASP

Status
Not open for further replies.

Esoteric

ISP
Feb 10, 2001
93
US
Does anyone know if you can alter an SQL object with ASP? For instance: VIEW(s) I want to change the parameters in a VIEW statement within SQL and have it saved each time to run a report. Is this possible?

I need to update the VIEW(s) before the actual report executes. Currently I have to go in and manually update them.
 
You can submit DROP VIEW and CREATE VIEW statements with ADODB. The login for your ASP script will need dbo permission, or the minimum permission needed to add a view to the database.

Could you re-organize the queries so that the VIEW is always the same but query it with parameters in a stored procedure?

From ASP call the stored procedure with parameter values
Code:
CommandText = "{CALL monthly_report(vDateBegin, vDateEnd)}"
In the stored procedure use the parameters to query the view.
Code:
CREATE PROCEDURE [monthly_report](
@from DATETIME,
@thru  DATETIME)

AS

SELECT * FROM myViewForMonthlyReports
WHERE date_of_activity BETWEEN @from AND @thru
 
Have you tried this in ASP:
----
Sql = "Begin Procname("& par1& ", " & par2& "); end;"
conn.execute(sql)
--------
conn is your ative connection
Procname is the name of your procedure

hope this is of some use
 
Check into "ALTER VIEW"

The benefit of using ALTER rather than DROP + CREATE is that with ALTER, you don't have to reset permissions, but rather leave them intact while changing the VIEW just the same:

"ALTER VIEW vMyView AS SELECT * FROM someTable"

"ALTER VIEW vMyView AS SELECT * FROM someOtherTable"
penny.gif
penny.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top