473,696 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Storing variables from a user-defined function

I've looked all over but can't find a solid answer. I've got a
function that runs from a View and when the function runs the first
time it is calculating a Temperature for a group of Formulas. What I
want to do is calculate this temperature in the UDF on the first pass
and store it somewhere (table, global variable etc.). On every
execution after that I'd like to use the value stored so I don't have
to recalculate the value again for the specific group defined.

I've looked at storing the data in a table from the UDF but UDF's
don't support dynamic SQL statements and can't run a stored procedure.
The key here is we have a view that calls a UDF (user-defined
function). Using SQL 2000.

Any ideas would be very helpful. Thanks.
Jul 20 '05 #1
2 2559
On 18 Aug 2004 10:26:18 -0700, Steve D wrote:
I've looked all over but can't find a solid answer. I've got a
function that runs from a View and when the function runs the first
time it is calculating a Temperature for a group of Formulas. What I
want to do is calculate this temperature in the UDF on the first pass
and store it somewhere (table, global variable etc.). On every
execution after that I'd like to use the value stored so I don't have
to recalculate the value again for the specific group defined.

I've looked at storing the data in a table from the UDF but UDF's
don't support dynamic SQL statements and can't run a stored procedure.
The key here is we have a view that calls a UDF (user-defined
function). Using SQL 2000.

Any ideas would be very helpful. Thanks.


Sorry, but you're out of luck. UDFs can't have "side effects." Quote from
SQL Server Books Online:

The statements in a BEGIN...END block cannot have any side effects.
Function side effects are any permanent changes to the state of a resource
that has a scope outside the function such as a modification to a database
table. The only changes that can be made by the statements in the function
are changes to objects local to the function, such as local cursors or
variables. Modifications to database tables, operations on cursors that
are not local to the function, sending e-mail, attempting a catalog
modification, and generating a result set that is returned to the user are
examples of actions that cannot be performed in a function.

However, there's a good chance that the optimizer won't call your UDF
repeatedly. If the values being passed to the function are the same for all
members of a group, chances are the optimizer will notice and only call the
UDF once.
Jul 20 '05 #2
Steve D (st************ ***@ecolab.com) writes:
I've looked all over but can't find a solid answer. I've got a
function that runs from a View and when the function runs the first
time it is calculating a Temperature for a group of Formulas. What I
want to do is calculate this temperature in the UDF on the first pass
and store it somewhere (table, global variable etc.). On every
execution after that I'd like to use the value stored so I don't have
to recalculate the value again for the specific group defined.

I've looked at storing the data in a table from the UDF but UDF's
don't support dynamic SQL statements and can't run a stored procedure.
The key here is we have a view that calls a UDF (user-defined
function). Using SQL 2000.


As Ross said, you can't do it. You would have to write a stored procedure
instead. This procedure would have to store the data in a table, since
there are no global variables in SQL Server. And, no, you cannot call
stored procedures from views.

It looks like you will have to reconsider your design.

--
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 20 '05 #3

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

Similar topics

7
1692
by: pescott | last post by:
I am still struggling to get some files uploaded to a database as BLOB data. I have 5 includes which allows the user to upload 5 files, numbered accordingly. However, there are script errors. Duhh, why else would I post? Well, here goes: CODE $adres = trim (htmlspecialchars($_POST)); $verkocht = trim (htmlspecialchars($_POST)); $form_description1 = trim (htmlspecialchars($_POST));
14
2595
by: mjkahn | last post by:
I've read (and read!) that you shouldn't store objects in Session variables. I've read these reasons: - The object takes up memory that may not be freed until the session times out. Better to create the object only when you actually use it. - Causes poor performance because the thread that created the object has to service all requests for it. Assuming I can live with the memory and performance implications (a big if,
2
1737
by: Jax | last post by:
Say for example a user of my website makes a selection on the site and I want to store that value for use on a later page what is the best way to do that? My only method at the moment that I know would be to create a static class and static variables inside of that. But if more then one person was using the page would they be using the same variables? Or do they get a version of the static class each? I dont know, which is why I ask. jax
6
2071
by: Saket Mundra | last post by:
I have a web application with two forms. After user enters data in first form he is directed to the second form. After Filling the second form as he clicks on save button, the data entered is stored in the database using a Transaction Object, That inserts data, entered by user in both the forms, in the database. My problem is where shall i store the data entered by the user in the first form when he is redirected to next form and till i...
4
1846
by: Mike | last post by:
I've created a custom IHttpModule that does custom authentication. Currently it stores authenticated user info in a hashtable within the class so I don't have to re-authenticate against a database everytime a logged in user hits a page. So far, it works great. Here is my question, is my approach for storing logged in users correct? Meaning, can I be sure that only one instance of my IHttpModule will be created for my Application. So...
0
2355
by: Larry Neylon | last post by:
Hi there, I'm currently trying to implement a website that will store and retrieve Polish, so I need to be able to handle Polish characters using classic ASP with MySql5. Does anybody have an experience of doing this as I'm banging my head against a brick wall getting this to work using either utf8 or latin2. I can't believe I'm the first person in the world to want to do this! I've input Polish characters directly into the database...
6
3195
by: (PeteCresswell) | last post by:
User wants to go this route instead of storing pointers in the DB and the documents outside. Only time I tried it was with only MS Word docs - and that was a loooong time ago - and it seemed to me like there were performance issues at the time. How about the different types? The MS docs I would expect Access to differentiate and handle appropriately (i.e. .DOC and .XLS).. but how about ..PDF? and can I stash a .TXT document in the...
9
7293
by: david | last post by:
I have a class with some business-logic and with every roundtrip, I need an instance of this class, so I have to create it, every time again. That doesn't seem very efficient. I thought it would be 'better' to store an instance of this class in a session-variable, so it's available all the time and needs to be instanced only once. Is this, generally speaking, a good idea, storing objects in session-variables ? Do you guys ever use this...
4
12591
by: =?Utf-8?B?YmFzdWxhc3o=?= | last post by:
Hi; I want to store a datatable (or an arraylist) as a session variable but when I try; Session = al_RecNo; I get an error that; "Cannot implicitly convert type 'System.Collections.ArrayList' to 'string'"
6
1910
by: psbasha | last post by:
Hi , Currenty I am storing the Graphical User Interface options in a string memeber variable of a class as show below: SampleCode Tkinter Modules ( Graphical User Interface): ------------------------------------------------------------- a) File.py class File: def __init__(self):
0
8661
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8595
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
9008
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
8875
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,...
0
8849
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5855
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2313
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1989
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.