Solved

Newbie Question Re: Stored Procedures/Views

Posted on 1998-08-06
6
216 Views
Last Modified: 2010-03-19
Here is my situation: I am using several views to consolidate data from a rather large table. The selection criteria is based on the contents of another table (that holds the names of the fields to be shown in the views.)

When a user makes a change to the selection criteria through my VB app, the selection criteria tables will be changed. This is a "trigger" to drop and recreate the existing views.  

Since I can't drop/create views in triggers or stored procedures, I was wondering if there is a way to call a VB exe from a stored procedure? Or if there is some better way to drop and create a view when a non-related table changes. I know I can do it through the program itself, but I would much prefer do it directly through sql to keep the views in sync with the selection criteria table.
0
Comment
Question by:trillian30
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 4

Expert Comment

by:mitek
ID: 1089431
I don't think you can create a view from an SQL Server trigger. The way I would approach this problem, would be creating an SQL stored procedure that would (using dynamic SQL, of course) drop and re-create the view, based on parameters passed to it.
This procedure would be called from VB app whenever "a user makes a change to the selection criteria"

Yes, there IS a way to call an external program from SP (xp_cmdshell) but I wouldn't even dare to use it to call anything larger than 'dir' command.

I would think, the way to do that is not "to call a VB exe from a stored procedure", but just the other way around. This way, it would be a simple call to SP, which would dynamicly build a DROP/CREATE VIEW statement and handle everything cleanly.

Again, can't give you an ANSWER, but a general plan of actions.

Tell me what you think about it.

BTW, that's NOT a newbie question.

0
 
LVL 4

Expert Comment

by:mitek
ID: 1089432
A really sick way of going about this problem would be to write a batch script for isql utility, that would drop/create the views, and call this file via xp_cmdshell from a trigger.
But only a sick (or really geniuos) mind could design something like THAT ...


0
 

Author Comment

by:trillian30
ID: 1089433
My understanding is that you also can not create a View in a stored procedure.  I'm not really sure what you mean by 'dynamic sql' though.
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 4

Expert Comment

by:mitek
ID: 1089434
I didn't say so. You CAN create a view from an SP, but it looks like it's not possible to call this SP from an SQL Server TRIGGER -- that's one of inherent limitations of triggers in SQL Server.

as for dynamic sql ? it's when you make a query within a stored procedure and then execute it with EXECUTE() command.

like that:

  DECLARE @01 varchar(255),@02 varchar(255),@03 varchar(255),@04 varchar(255)

  SELECT @01 = 'DROP VIEW testView '
  SELECT @02 = 'CREATE VIEW testView AS '
  SELECT @03 = 'SELECT * FROM ForumTopics '
  SELECT @04 = 'WHERE TopicSecurity=''MEM'''
  EXECUTE (@01)             -- drop the view
  EXECUTE (@02 + @03 + @04) -- recreate the view


0
 

Author Comment

by:trillian30
ID: 1089435
You are *so* fabulous! That worked perfectly! Do you want to resubmit so you can get the points for the answer?

0
 
LVL 4

Accepted Solution

by:
mitek earned 200 total points
ID: 1089436
Yep. Thank you very much. Let me know if you still have problems with it.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question