Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Newbie Question Re: Stored Procedures/Views

Posted on 1998-08-06
6
Medium Priority
?
227 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 800 total points
ID: 1089436
Yep. Thank you very much. Let me know if you still have problems with it.

0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

715 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