473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

How to Modify a views' SQL source from a program

Hi all, Thanks in advance to any contributions to my question.

Im running SQLServer 2000 in a Win 2000 Server env.

Background:
==========

The database has many views that range from simple to complex joins on
tables.

The selection criteria is fixed eg. 'Where TaskTypeIdent = 2204 and
OutcomeId = 123 or 2322 or 1222 and
CicType = 87878 ... etc etc

Requirement:
===========

Now what I would like to do is be able to change the 'where =' value
part ie. 2204, dynamically if and when required, and it will be
required.

In other words there won't be a DBA handy to do this when it changes
hence I would like to write a front end UI to allow the user to easily
manage this.

There are upwards of 200 views like this.

Question:
========

Where in the system metadata can I access (if possible) the source of
the View such that I can update it with the new values. eg. 'Where
TaskTypeIdent = 7627 and OutcomeId = 2322 or 94847 or 989 and CicType =
1111 ... etc etc

Many thanks

Paul
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
5 2113
Paul Scotchford <pa*****************@eds.com> wrote in message news:<40*********************@news.frii.net>...
Hi all, Thanks in advance to any contributions to my question.

Im running SQLServer 2000 in a Win 2000 Server env.

Background:
==========

The database has many views that range from simple to complex joins on
tables.

The selection criteria is fixed eg. 'Where TaskTypeIdent = 2204 and
OutcomeId = 123 or 2322 or 1222 and
CicType = 87878 ... etc etc

Requirement:
===========

Now what I would like to do is be able to change the 'where =' value
part ie. 2204, dynamically if and when required, and it will be
required.

In other words there won't be a DBA handy to do this when it changes
hence I would like to write a front end UI to allow the user to easily
manage this.

There are upwards of 200 views like this.

Question:
========

Where in the system metadata can I access (if possible) the source of
the View such that I can update it with the new values. eg. 'Where
TaskTypeIdent = 7627 and OutcomeId = 2322 or 94847 or 989 and CicType =
1111 ... etc etc

Many thanks

Paul
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


You can use ALTER VIEW to change a view's definition, but you should
probably consider a different approach. In general, you don't want
users creating or modifying any objects in your database, because
allowing them to do so would create significant security and
maintenance issues.

It's not clear from your description why you hard-code values at all -
why not simply pass the values to your query at runtime, perhaps as
stored procedure parameters? And/or replace views with table-valued
functions, which accept parameters for the search values?

If your fundamental requirement is for reporting, you may want to look
at using a reporting package which will build queries for your users
directly (MS Reporting Services, Crystal Reports etc.). Or for a
stored procedure solution, check out this article:

http://www.sommarskog.se/dyn-search.html

Simon
Jul 20 '05 #2
>> Now what I would like to do is be able to change the 'where ='
value part ie. 2204, dynamically if and when required, and it will be
required. <<

That is called a PROCEDURE and not a VIEW.
In other words there won't be a DBA handy to do this when it

changes hence I would like to write a front end UI to allow the user
to easily manage this. <<

Giving users the power to write code on the fly to users is like
giving a teenage boy car keys and whiskey. Messing with schema
information tables is like doing your own dental work with garden
tools. What are you thinking, man?

Possible answer: You can build a table of constants within a schema
using Standard SQL like this and reference them inside the VIEWs:

CREATE TABLE Constant
(lock CHAR(1) DEFAULT 'X' NOT NULL PRIMARY KEY
CHECK (lock = 'X'),
pi REAL DEFAULT 3.141592653 NOT NULL,
e REAL DEFAULT 2.718281828 NOT NULL,
phi REAL DEFAULT 1.618033988 NOT NULL,
..);

INSERT INTO Constants DEFAULT VALUES;

The insertion creates one row, so the table ought to have a singular
name. The "lock" column assures you that there is always only one
row. Now you can let users update this table to change things, and
have a way to re-set it to default values. But put a LOT of DCL on
this table!!
Jul 20 '05 #3
Thanx but you lost the plot somewhere. Obviously I did not explain
myself simply enough. But obviously I will have to refer to books
instead. CELCO you jugemental approach in your reply is indicative of an
arrogance know it all. Why waste time typing a reply when all you give
is a misguided opinion rather than some technical facts, man you are
useless...

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4
>> Thanx but you lost the plot somewhere. Obviously I did not explain
myself simply enough. But obviously I will have to refer to books
instead. CELKO you jugemental approach in your reply is indicative of
an arrogance know it all. Why waste time typing a reply when all you
give is a misguided opinion rather than some technical facts, man you
are useless... <<

What is your problem? Simon told you the same thing about letting
users write code on the fly; he was not as witty about it (did you
recognize the P.J. O'Rouke quote?). I also did give you a possible
solution that would not endanger the applications or the database. I
gave you a simple, portable way that you can "re-set" the schema to
default values, as a safety.

I feel that this is a much better approach than using an ALTER
statement and then trying to remember what a VIEW looked like 42
revisions ago (assuming the end users have the skills to write correct
code). What happens in that scenario is that User A changes the VIEW
and since he does not need column x, he drops it. When user B
executes the VIEW, he does need column x and it is gone. Or worse, a
calculation is changed but the column name is not.

If you want to do reports of some kinds, get a report writer. Much
easier, much cheaper in the long run, and much safer.

Horrible true story. I did a consulting job many years ago at a drug
company. The sales support database was on INFORMIX and all the
programmers had full DBA access to it. The database got doctor
information (name, address, specialities, etc.) from outside sources.
One programmer liked to use (I think I have the names right) Med-Data
and the other liked Phoenix.

The codes these services use for specialties are totally different --
numeric versus alpha, three versus five, etc.

The programmers each wrote ALTER TABLE, ALTER VIEW scripts to change
the database on the fly to use their favorite data source. The schema
was not the same for more than a day or two. Try to find that
problem! The solution was to pick one source and stick with it, and to
assign a single DBA.

You are trying to repeat the same scenario, but change
(DBA/programmers) to (programer/users).
Jul 20 '05 #5

Well I should have realised that often these forums are little more than
a platform for so called "know it alls" to show off their limited
knowledge, but I have found some threads that have been written by
experts.

I found my solution and have coded it thankyou and it serves the purpose
well for the environment I have to develop a solution for.

Your assertions reflect your lack of understanding of development
processes.

Thankyou for your input.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nona Me | last post by:
Is there a program that can make automatically input forms and views using the table design information in mysql. for example: in mysql you have a table: Customer with the next field: Name,...
0
by: Marko Poutiainen | last post by:
Situation: We had to make our SQLServer 2000 database multi-lingual. That is, certain things (such as product names) in the database should be shown in the language the user is using (Finnish,...
4
by: titanandrews | last post by:
Hi, I have ran into a situation that I think should be possible, but I am fairly new to XSLT so maybe not. Suppose I have the following document <ROOT> <FOO name="A"> <CHILD name="B"/>...
11
by: Konrad Den Ende | last post by:
I have a function returning a string but the problem is that the color of it is blue which suits me well for some pages but not for others. Is it possible to "feel" what the color of the background...
224
by: VB6 User | last post by:
Hi all devies! Many (.NUT, .NOT or whatever), APIs, VB6, Views & Questions Your can not call APIs directly in .NET, only via P/Invoke. There are some things that cannot be done in...
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
7
by: solidsna2 | last post by:
Hi, I am new to using SQL. I want to be able to exucute a query that I place in a view. I want this views to be executed every time a value change in one of the table in a particular field. ...
33
by: Peter | last post by:
People are telling me it is bad to put select * from <atable> in a view. I better should list all fields of the table inside the definition of the view. I dont know exactly why but some...
2
by: grant | last post by:
Man do I struggle with Enterprise Manager as a graphical tool for building views etc. Its flaky and hangs frequenlty so i have to kill it with the task manager and re open it. You cant debug...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.