473,715 Members | 6,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Intensively used function in view needs a minimum and maximum from a table PartII

Because of an error in google or underlying site i can reply on my own
issue. Therefore i copied the former entered message in this message.
-------------------------------------REPY----------------------------------
Hi Maybe i wasn't clear. I want to dynamically check whether what the
lowest date and the highest date is in the calendar table. The
presented solutions has fixed dates and i don't want that.

If i could store a global variable in SQL server (dynamic properties?)
then it would be great. Fill this once and call it multiple times in
my intensively used function. Is this possible?

Greetz
Hennie

----------------------------Previously entered
issue-----------------------
I have a problem (who not?) with a function which i'm using in a view.
This function is a function which calculates a integer value of a
date. For example: '12/31/2004 00:00:00" becomes 20041231. This is
very handy in a datawarehouse and performes superfast. But here is my
problem.

My calendar table is limited by a couple of years. What happens is
that sometimes a value is loaded which is not in the range of the
Calendardate. What we want to do is when a date is loaded is that this
function insert a minimum date when date < minimum date and a maximum
date when date > maximum date.

Yes i know you're thinking : This is datamanipulatio n and yes this is
true. But now we loose information in our cubes and reports by inner
joining. So if we can use a minimum and a maximum than a user would
say: "This is strange, a lot of values on 1980/1/1!" instead of "I
think that i have not all the data!"

Greetz

Hennie
Plaats een reactie op dit bericht

Bericht 2 van deze discussie
Van:John Bell (jb************ @hotmail.com)
Onderwerp:Re: Intensively used function in view needs a minimum and
maximum from a table
View this article only
Discussies:comp .databases.ms-sqlserver
Datum:2004-12-30 03:56:25 PST
Hi

If you LEFT or RIGHT JOIN to the calendar table you will get a NULL
value
for the column, you can then is CASE to determine the value

CREATE FUNCTION ConvertDate (@datevalue datetime)
RETURNS INT
AS
BEGIN
DECLARE @dateint INT
SELECT @dateint = CAST( CASE WHEN A.Date < '20030101' THEN '19800101'
WHEN A.Date > '20051231' THEN '99991231'
ELSE CONVERT(CHAR(4) ,C.[Year]) + RIGHT('0'+
CONVERT(VARCHAR (2),C.[Month]),2) + RIGHT('0'+
CONVERT(VARCHAR (2),C.[Day]),2)
END AS INT )
FROM ( SELECT @datevalue AS [Date] ) A
LEFT JOIN CALENDAR C ON C.[Date] = A.[Date]
RETURN @dateint
END
GO

John

"Hennie de Nooijer" <hd********@hot mail.com> wrote in message
news:19******** *************** ***@posting.goo gle.com...
I have a problem (who not?) with a function which i'm using in a view. This function is a function which calculates a integer value of a
date. For example: '12/31/2004 00:00:00" becomes 20041231. This is
very handy in a datawarehouse and performes superfast. But here is my
problem.

My calendar table is limited by a couple of years. What happens is
that sometimes a value is loaded which is not in the range of the
Calendardate. What we want to do is when a date is loaded is that this
function insert a minimum date when date < minimum date and a maximum
date when date > maximum date.

Yes i know you're thinking : This is datamanipulatio n and yes this is
true. But now we loose information in our cubes and reports by inner
joining. So if we can use a minimum and a maximum than a user would
say: "This is strange, a lot of values on 1980/1/1!" instead of "I
think that i have not all the data!"

Greetz

Hennie Plaats een reactie op dit bericht

Bericht 3 van deze discussie
Van:Hugo Kornelis (hugo@pe_NO_rFa ct.in_SPAM_fo)
Onderwerp:Re: Intensively used function in view needs a minimum and
maximum from a table
View this article only
Discussies:comp .databases.ms-sqlserver
Datum:2004-12-30 15:32:06 PST
On 30 Dec 2004 02:38:51 -0800, Hennie de Nooijer wrote:
I have a problem (who not?) with a function which i'm using in a view.This function is a function which calculates a integer value of a
date. For example: '12/31/2004 00:00:00" becomes 20041231. This is
very handy in a datawarehouse and performes superfast. But here is my
problem.

(snip)

Hi Hennie,

Is this conversion all that your function does? If so, you might want
to
try the following alternative (using CURRENT_TIMESTA MP as example;
replace
it with your date column / parameter):

SELECT CAST(CONVERT(va rchar, CURRENT_TIMESTA MP, 112) AS int)

You could put this in the UDF (probably at least as fast as your
current
Calenmdar-table based function), or use it inline as a replacement to
the
function call (probably even faster).

It should work for all dates from Jan 1st 1753 through Dec 31st 9999.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #1
2 2331
On 3 Jan 2005 08:26:56 -0800, Hennie de Nooijer wrote:

(snip)
Hi Maybe i wasn't clear. I want to dynamically check whether what the
lowest date and the highest date is in the calendar table. The
presented solutions has fixed dates and i don't want that.


Hi Hennie,

Did you try my suggestion, to replace your current calendar-based
user0defined function with the following expression, using builtin
functions only:

CAST(CONVERT(va rchar, date_column, 112) AS int)

If you did try this, why didn't it work?

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #2
Hi

If you are using a stored procedure then you can do the

SELECT @maxdate =MAX([Date]) @mindate = MIN([Date]) FROM MyCalendar

and then pass these as parameters to your function. Alternatively you
can have the select appropriate select statements instead of the hard
coded dates in the function.

As Hugo says: why is there a problem with the dates not being in your
calendar table? The cast/convert option is probably the quickest!

John

Hennie de Nooijer wrote:
Because of an error in google or underlying site i can reply on my own issue. Therefore i copied the former entered message in this message.
-------------------------------------REPY---------------------------------- Hi Maybe i wasn't clear. I want to dynamically check whether what the
lowest date and the highest date is in the calendar table. The
presented solutions has fixed dates and i don't want that.

If i could store a global variable in SQL server (dynamic properties?) then it would be great. Fill this once and call it multiple times in
my intensively used function. Is this possible?

Greetz
Hennie

----------------------------Previously entered
issue-----------------------
I have a problem (who not?) with a function which i'm using in a view. This function is a function which calculates a integer value of a
date. For example: '12/31/2004 00:00:00" becomes 20041231. This is
very handy in a datawarehouse and performes superfast. But here is my
problem.

My calendar table is limited by a couple of years. What happens is
that sometimes a value is loaded which is not in the range of the
Calendardate. What we want to do is when a date is loaded is that this function insert a minimum date when date < minimum date and a maximum
date when date > maximum date.

Yes i know you're thinking : This is datamanipulatio n and yes this is
true. But now we loose information in our cubes and reports by inner
joining. So if we can use a minimum and a maximum than a user would
say: "This is strange, a lot of values on 1980/1/1!" instead of "I
think that i have not all the data!"

Greetz

Hennie
Plaats een reactie op dit bericht

Bericht 2 van deze discussie
Van:John Bell (jb************ @hotmail.com)
Onderwerp:Re: Intensively used function in view needs a minimum and
maximum from a table
View this article only
Discussies:comp .databases.ms-sqlserver
Datum:2004-12-30 03:56:25 PST
Hi

If you LEFT or RIGHT JOIN to the calendar table you will get a NULL
value
for the column, you can then is CASE to determine the value

CREATE FUNCTION ConvertDate (@datevalue datetime)
RETURNS INT
AS
BEGIN
DECLARE @dateint INT
SELECT @dateint = CAST( CASE WHEN A.Date < '20030101' THEN '19800101' WHEN A.Date > '20051231' THEN '99991231'
ELSE CONVERT(CHAR(4) ,C.[Year]) + RIGHT('0'+
CONVERT(VARCHAR (2),C.[Month]),2) + RIGHT('0'+
CONVERT(VARCHAR (2),C.[Day]),2)
END AS INT )
FROM ( SELECT @datevalue AS [Date] ) A
LEFT JOIN CALENDAR C ON C.[Date] = A.[Date]
RETURN @dateint
END
GO

John

"Hennie de Nooijer" <hd********@hot mail.com> wrote in message
news:19******** *************** ***@posting.goo gle.com...
I have a problem (who not?) with a function which i'm using in a

view.
This function is a function which calculates a integer value of a
date. For example: '12/31/2004 00:00:00" becomes 20041231. This is
very handy in a datawarehouse and performes superfast. But here is my problem.

My calendar table is limited by a couple of years. What happens is
that sometimes a value is loaded which is not in the range of the
Calendardate. What we want to do is when a date is loaded is that this function insert a minimum date when date < minimum date and a maximum date when date > maximum date.

Yes i know you're thinking : This is datamanipulatio n and yes this is true. But now we loose information in our cubes and reports by inner joining. So if we can use a minimum and a maximum than a user would
say: "This is strange, a lot of values on 1980/1/1!" instead of "I
think that i have not all the data!"

Greetz

Hennie

Plaats een reactie op dit bericht

Bericht 3 van deze discussie
Van:Hugo Kornelis (hugo@pe_NO_rFa ct.in_SPAM_fo)
Onderwerp:Re: Intensively used function in view needs a minimum and
maximum from a table
View this article only
Discussies:comp .databases.ms-sqlserver
Datum:2004-12-30 15:32:06 PST
On 30 Dec 2004 02:38:51 -0800, Hennie de Nooijer wrote:
I have a problem (who not?) with a function which i'm using in a

view.
This function is a function which calculates a integer value of a
date. For example: '12/31/2004 00:00:00" becomes 20041231. This is
very handy in a datawarehouse and performes superfast. But here is myproblem.

(snip)

Hi Hennie,

Is this conversion all that your function does? If so, you might want
to
try the following alternative (using CURRENT_TIMESTA MP as example;
replace
it with your date column / parameter):

SELECT CAST(CONVERT(va rchar, CURRENT_TIMESTA MP, 112) AS int)

You could put this in the UDF (probably at least as fast as your
current
Calenmdar-table based function), or use it inline as a replacement to
the
function call (probably even faster).

It should work for all dates from Jan 1st 1753 through Dec 31st 9999.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)


Jul 23 '05 #3

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

Similar topics

4
6072
by: Lobang Trader | last post by:
Hi all, I am trying to create a username and a password class. I would like to know what are the RECOMMENDED minimum and maximum length for both fields? These fields will be something like this: private static final int DEFAULT_MINIMUM_LENGTH = ??????
6
4056
by: Jef Driesen | last post by:
I need to implement a function to implement the rounding of floating point values. At the moment i have two different implementations, depending on the type of the return value (integer or double). // Integer calculation (fast) int iround(const double x) { return (x>=0 ? static_cast<int>(x + 0.5) : static_cast<int>(x + 0.5) } // Floating point calculation (slow) double dround(const double x) {
2
1909
by: Hennie de Nooijer | last post by:
I have a problem (who not?) with a function which i'm using in a view. This function is a function which calculates a integer value of a date. For example: '12/31/2004 00:00:00" becomes 20041231. This is very handy in a datawarehouse and performes superfast. But here is my problem. My calendar table is limited by a couple of years. What happens is that sometimes a value is loaded which is not in the range of the Calendardate. What we...
1
2728
by: Najib Abi Fadel | last post by:
Hi i have an ordered table of dates let's say: 1/1/2004 8/1/2004 15/1/2004 29/1/2004 5/2/2004 12/2/2004
1
7946
by: itsolutionsfree | last post by:
Hi All, i am deep trouble.so,please help me how to get minimum and maximum dates for particular Month and Year.Any kind of help will help. for ex: im passing : March 2006 Minimum Date - 01/March/2006 Maximum Date - 31/March/2006
5
3617
by: pat270881 | last post by:
hello, i should implement this class: namespace test_1 { class statistician { public: // CONSTRUCTOR
14
12703
by: Olw | last post by:
Hello, Does anyone have a nice link to some code for calculating the gradient of a function in C? Thanks, Olw
1
6810
by: greek | last post by:
Hi! I'm suppode to write a prg to calculate maximum and minimum of 4 intergers by using functions i've writen the code but getting the error: call of a non function..cant see my error help me..here is my code #include<iostream.h> #include<conio.h> void max(int a,int b,int c,int d); void min(int a,int b,int c,int d); int num1,num2,num3,num4,max_val,min_val; void main()
2
3433
by: John Geddes | last post by:
Has anyone come up with an "IsInview" function that one could use to test whether scrollIntoView is needed? Imagine a (scrolled) list of editable item prices. I want to impose maximum and minimum limits - so I test the just-changed value when the user either starts to edit another field, or tries to close the form. If there is an error, I need to highlight the error - and that means scrolling back to the problem item if it is not in...
0
8821
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
8718
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
9196
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
9103
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
7973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5967
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
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3175
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
2539
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.