473,748 Members | 2,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

T-SQL how to deal with results from stored proc

Try hard to become familiar with T-SQL.

Can anybodey tell me the best way to deal with set's provided by a
stored procedure. Til yesterday I thougt trapping set in temp table
using INSERT EXEC is a way out of this, but then I struggeled with
nested INSERT EXEC's.

What are all the system proc's good for if the results cannot be
evaluated? The approach of modular programming is to have code doing
similar things in one place.

If I try to make use of sp_helprolememb er to get login names for more
roles, pack the logins in one table and return the result set in a SP,
the procedure which calls that is unable to evaluate the set.
On the other hand I read the advice, not to access system tables
directly.

Is there a way out?
Jul 23 '05 #1
9 6438
Hi

If the system procedures do not provide what you want directly then you can
look at the code to see how they gather the information and then write your
own. I have personally rarely found that I have needed to embed and evaluate
the results from system stored procedures, but if you think that this should
be a mandatory requirement for these procedure then you may want to put the
suggestion forward to sq*****@microso ft.com.

You may want to look at your design and see if you are trying to re-invent
functionality that is available elsewhere, or if you are pitching the
application at the wrong level.

John

"Wolfgang Kreuzer" <wo************ ****@gmx.de> wrote in message
news:1120984025 .eedd1f00afef5f d7e145c7bdbfbea 0c3@teranews...
Try hard to become familiar with T-SQL.

Can anybodey tell me the best way to deal with set's provided by a
stored procedure. Til yesterday I thougt trapping set in temp table
using INSERT EXEC is a way out of this, but then I struggeled with
nested INSERT EXEC's.

What are all the system proc's good for if the results cannot be
evaluated? The approach of modular programming is to have code doing
similar things in one place.

If I try to make use of sp_helprolememb er to get login names for more
roles, pack the logins in one table and return the result set in a SP,
the procedure which calls that is unable to evaluate the set.
On the other hand I read the advice, not to access system tables
directly.

Is there a way out?

Jul 23 '05 #2
John Bell (jb************ @hotmail.com) writes:
If the system procedures do not provide what you want directly then you
can look at the code to see how they gather the information and then
write your own. I have personally rarely found that I have needed to
embed and evaluate the results from system stored procedures, but if you
think that this should be a mandatory requirement for these procedure
then you may want to put the suggestion forward to
sq*****@microso ft.com.


I would say that Microsoft has already started to take this direction.
In SQL 2005, plenty of well-establish system stored procedure are
becoming deprecated. Instead the approach is that you should get
system data from the new catalog views. of which sum may actually be
table-valued functions.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #3
Wolfgang Kreuzer (wo************ ****@gmx.de) writes:
Try hard to become familiar with T-SQL.

Can anybodey tell me the best way to deal with set's provided by a
stored procedure. Til yesterday I thougt trapping set in temp table
using INSERT EXEC is a way out of this, but then I struggeled with
nested INSERT EXEC's.
Look at http://www.sommarskog.se/share_data.html for a couple of
alternatives.
What are all the system proc's good for if the results cannot be
evaluated? The approach of modular programming is to have code doing
similar things in one place.
The concepts of SQL does not always fit entirely with the ideas of
modular programming.

In modular programming you compute some pieces here and some pieces
there. But in SQL the idea is that you give the entire thing to be
computed to the query optimizer and the optimizer will estimate what is
the most effecient order make this computation. For system metadata
this is not likely to be important, but if the query involves tables with
several million rows, this is getting essential.

That said, SQL does provide you modularisation through views and
inline table-functions. But the problem with a view is that while
it gives you the result that you need, it may perform computations
that you don't need for your current problem at hand.

For a complex system, modularisation is still required, because
duplicating logic is never good. But it should not be taken too far.
And partciularly, one needs to understand where modularisation may be
too expensive for performance.
On the other hand I read the advice, not to access system tables
directly.


The only problem with the system tables is that in SQL 2005 they are
deprecated in favour of the catalog views. But in SQL 2000 there is not
that much alternatives.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #4
Erland,
thanks for your quick and exhaustive answer.

And thanks for not trying to convince me that modular programming is
the wrong approach. I understand that having a good data model which
allows to query/calculate the results is the main thing in SQL but
sometimes not the solution.

Wolfgang
Jul 23 '05 #5
Could you give us an example of when "having a good data model" is NOT
appropriate?

Maybe if you explained the scenario with DDL and sample data we could make
some suggestions more specific to your actual problem.

--
David Portas
SQL Server MVP
--
Jul 23 '05 #6
David Portas (RE************ *************** *@acm.org) writes:
Could you give us an example of when "having a good data model" is NOT
appropriate?


The standard example would be when you have a third-party application,
and you are supposed to write some home-brewed queries for reports. In
this situation you don't start redesigning the data model, how flawed it
may be.

Although, my guess is that Wolfgang tried to say even if you have a good
data model, that alone does evade the needs for modularizing your code.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #7
Stu
Amen. This is the first post I've read in a long time that recognizes
that the ideal solution may be beyond the control of the developer. I
know I deal with a lot of poorly designed databases that have to share
data, and I'm sure ohers do as well.

Stu

Jul 23 '05 #8
On Sun, 10 Jul 2005 16:17:07 +0100, "David Portas"
<RE************ *************** *@acm.org> wrote:
Could you give us an example of when "having a good data model" is NOT
appropriate? No - what I wanted to express in short (maybe it was a bit to short)
is
- I agree with Erland that in 99 % of the cases query data a leave it
with the optimizer to find a way to retrieve the data required is
certainly the right approach
- avoiding redundancies (normalised structure - to a certain degree
(somewhere between 2.5th and 3rd normal form) - is a key issue

I don't want dig more into detail on that 'data model' thing ...


Maybe if you explained the scenario with DDL and sample data we could make
some suggestions more specific to your actual problem. My problem I was trying to solve is, checking membership in several
role at the beginning of stored procedures.

My attempt was to use INSERT EXEC to fetch te results of several
sp_helprolememb er calls in a temp table (in some stored proc;
up_EnumSuperUse rs; up_EnumApplAdmi ns ...) and return collected data as
a record set. In a wrapping stored proc I intended to collect data
from some of the proc's above and check if current user or specified
user is in the list - but as far as I know evaluating data from a
stored proc record set requires INSERT EXEC which does not allow
nesting for whatever reason.

On the other hand, UDF's do not allow usage of non-deterministic
functions, call of stored proc, INSER, CREATE etc.

Having that in mind and following Kalen Delaney advise - never use
direct access to system tables, use system stored proc instead, you
end up in the middle of nowhere, ring-fenced by DONT's without Gates.

What I have done is, I took the SQL statement out of sp_helprolememb er
put it in several UDF's which just returns a BIT value indicating if
someone is member of a role or some of them. Having in mind (now -
hopefully later, when new version of SQL server is rolled out, as
well) that I may have to rewrite code (I normally hate things like
that- and try to avoid it whereever possible).

--
David Portas
SQL Server MVP


Jul 23 '05 #9
Wolfgang Kreuzer (wo************ ****@gmx.de) writes:
My attempt was to use INSERT EXEC to fetch te results of several
sp_helprolememb er calls in a temp table (in some stored proc;
up_EnumSuperUse rs; up_EnumApplAdmi ns ...) and return collected data as
a record set. In a wrapping stored proc I intended to collect data
from some of the proc's above and check if current user or specified
user is in the list - but as far as I know evaluating data from a
stored proc record set requires INSERT EXEC which does not allow
nesting for whatever reason.

On the other hand, UDF's do not allow usage of non-deterministic
functions, call of stored proc, INSER, CREATE etc.
You can also use temp tables, as I discuss in the article I pointed you to.
What I have done is, I took the SQL statement out of sp_helprolememb er
put it in several UDF's which just returns a BIT value indicating if
someone is member of a role or some of them.


I don't know exactly what you are doing, but have you looked at the
built-in function is_member()?

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #10

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

Similar topics

0
2294
by: udo polder | last post by:
hello all i am having some problems calling a stored procedure on MSSQL2000 from VC7. i have build up an OLEDB-Consumer (for stored Procs) via vizzard and modifyed it a little, to bring in the cloumn and param map. when i start the program i can call OpenAll() and the system gets the recordset from the DB. but data is corrupted :( also the recordcount DOSE match the recordcount from the stored proc (if i add a entry to the table i get one...
14
1832
by: Roy | last post by:
Apologies for the cross-post, but this truly is a two-sided question. Given the option of creating Looping statements within a stored proc of sql server or in the code-behind of an .net webpage, which would you choose and why? Reason I ask is I created a webpage which essentially runs through a litany of loops to determine which stored proc to kick off. This is written in the code-behind. It occurred to me that I could probably just...
0
1143
by: John | last post by:
Hi all, I'm calling a stored proc which does 4 "selects" and then I populate a dataset looping through the dr using a dr.NextResult() but the stored proc may not return any results for one or more Select stetments. When this happens, a table is not returned so the dataset.Fill() does not populate conatin 4 tables which then each bind to a grid - the nett result is that the relevant gridview may not show the correct data. Now when I do...
5
2113
by: John | last post by:
Hi all, I'm sorry I'm reposting this but the original was urgent and I do need closure on this. I'm calling a stored proc which does 4 "selects" and then I populate a dataset looping through the dr using a dr.NextResult() but the stored proc may not return any results for one or more Select stetments. When this happens, a table is not returned so the dataset.Fill() does not populate conatin 4 tables which then each bind to a grid -...
6
2162
by: Paul M | last post by:
Hi All, I'm currently writing a z/OS DB2 Stored Proc in C, using an example from the IBM Stored Procedure guide (SG24-7083-00). The database calls to read and update the database work fine...however, I can't seem to figure out how to pass parms to the C Program. The compile, bind, and run using DB2BATCH all work fine, however, when I attempt to access any values passed into the program, they're not present. Here's part of the JCL...
10
4273
by: syntego | last post by:
I think I have discovered a bug in the handling of null values (vs NULL values) passed as parameters to a stored proc. I have always believed that the database handled NULL and null the same. The following statement returns the expected results: select case when NULL is null then 'SAME' else 'DIFFERENT' end from sysibm.sysdummy1; returns SAME.
3
6387
by: satkins | last post by:
Hello everyone. I've been trying to find if this is even possible but nothing I've found has really helped. I've got a stored proc with a few input parameters and one output parameter. I would like to call this proc from another proc and have proc 2 return the result of proc1 as a column. Some thing like this create procedure Proc1 @Input1 numeric, @Input2 varchar(20), @Input3 money output as Select @Input3 = Amount from...
1
2293
by: central_scrutinizer | last post by:
I have an ASP that has been working fine for several months, but it suddenly broke. I wonder if windows update has installed some security patch that is causing it. The problem is that I am calling a stored procedure via an ASP (classic, not .NET) , but nothing happens. The procedure doesn't work, and I don't get any error messages. I've tried dropping and re-creating the user and permissions, to no avail. If it was a permissions...
0
994
by: =?Utf-8?B?UXVpbWJseQ==?= | last post by:
At one seemingly inoccuous step in my CLR stored procedure, execution stops and the query times-out. I've tried debugging the stored proc by stepping into it from within VS. When I do, I get to the code in question, but then simply get this message: WARNING: Debugger was accessing T-SQL variables while managed code was not suspended. Waiting until the access is done to continue T-SQL execution. Continueing T-SQL execution.
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9562
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9386
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.