473,386 Members | 1,832 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,386 software developers and data experts.

Use getdate function in a own Function

Hi,
I have written a stored proc with some temporary tables and also used
a getdate() in my stored proc. When i try to call the sproc the error
is that we can only use extended sprocs or function inside a sproc.
Now if try to write the stored proc directly inside a fuction ie copy
paste after changing my temp tables to tables the problem is , i get a
error invalid use of getdate in sproc.What do i do to get something
for my results inside a table.
Thanks in advance.
RVG
Jul 20 '05 #1
5 22685
Care to post your code here? If you are using GetDate() as a default value
for an input parameter you may see an error similar to the one you
mentioned. BTW, are you using an SP or UDF?

--
- Anith
( Please reply to newsgroups only )
Jul 20 '05 #2
[posted and mailed, please reply in news]

Rajesh Garg (ra*******@rediffmail.com) writes:
I have written a stored proc with some temporary tables and also used
a getdate() in my stored proc. When i try to call the sproc the error
is that we can only use extended sprocs or function inside a sproc.
Now if try to write the stored proc directly inside a fuction ie copy
paste after changing my temp tables to tables the problem is , i get a
error invalid use of getdate in sproc.What do i do to get something
for my results inside a table.


You say that you are writing a stored procedure, but to me it sounds
like you are working with a user-defined function, UDF.

In a UDF you are fairly limited in what you can do, as you have noted
from the error message. The gist is that you may not change the state
of the database, and the function must be deterministic. That is, it
must always return the same result give a certain a set of data in
the database.

What your real problem is, is a little unclear to me, but it sounds
like you might get some hints from an article of mine. See
http://www.algonet.se/~sommar/share_data.html.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3
My requirement is:

I want the final result in some table coz i can create only a view so
as to use the results of the sproc.

drop procedure Sproc_esqlReconcileWithBiz_WMS
go
create Procedure Sproc_esqlReconcileWithBiz_WMS
@InputDateStr as datetime
,@InputInterfaceDb as varchar(32)
,@InputInterfaceType as varchar(10)
as
begin
set nocount on

Declare @InputDate as numeric
Declare @lQryStr as nvarchar(2000)

DECLARE @lTimeZoneAdjustment AS BIGINT
SET @lTimeZoneAdjustment = (SELECT DateDiff(SECOND, DateAdd(SECOND,
0, '01/01/1970'), GETDATE()) - DateDiff(SECOND, DateAdd(SECOND, 0,
'01/01/1970'), GETUTCDATE()))

Set @InputDate = DateDiff(SECOND, DateAdd(SECOND, 0,
'01/01/1970'), cast(@InputDateStr as varchar(20)) ) -
@lTimeZoneAdjustment

Create Table #XIA (DEST varchar(15), BSQ varchar(32), MSG
varchar(2050) )

IF @InputInterfaceType = 'CMS'
Set @lQryStr = 'SOMETHING'
IF @InputInterfaceType = 'BMS'
Set @lQryStr = 'SOMETHING'

exec sp_executesql @lQryStr

UPDATE #XIA SET BSQ = Left(BSQ,3) + substring(BSQ, 5, (Select
case when charindex(char(13), BSQ)<=0 then 4 else charindex(char(13),
BSQ) - 5 end) ) where dest = '-'

Create Table #MismatchTrades ( Destination varchar(15),
BranchSeqNo varchar(32), TotTradesInOrs numeric, TotTradesInBiz
numeric )

Insert into #MismatchTrades
Select XIATrades.Dest AS 'ExecutionDestination',
XIATrades.ExRefNumber as 'Exch Ref #', XIATrades.Cnt as 'XIA Trade
Count', BIZTrades.cnt as 'BIZ Trade Count'
from
(
SOMETHING
)

Select xia.Dest as 'ExecutionDestination', xia.MSG,
missed.BranchSeqNo as 'Exch Ref #', missed.TotTradesInOrs as 'No of
Trades in XIA', missed.TotTradesInBiz as 'No of Trades in BIZ'
from #XIA xia JOIN #MismatchTrades missed
ON xia.BSQ = missed.BranchSeqNo AND xia.Dest =
missed.Destination
order by xia.BSQ

end
The final select statement results i want to get in a function. How do
i get it then.
Thanks for al the help.I will try to follow the link u have sent me.
RVG
Erland Sommarskog <so****@algonet.se> wrote in message news:<Xn*********************@127.0.0.1>...
[posted and mailed, please reply in news]

Rajesh Garg (ra*******@rediffmail.com) writes:
I have written a stored proc with some temporary tables and also used
a getdate() in my stored proc. When i try to call the sproc the error
is that we can only use extended sprocs or function inside a sproc.
Now if try to write the stored proc directly inside a fuction ie copy
paste after changing my temp tables to tables the problem is , i get a
error invalid use of getdate in sproc.What do i do to get something
for my results inside a table.


You say that you are writing a stored procedure, but to me it sounds
like you are working with a user-defined function, UDF.

In a UDF you are fairly limited in what you can do, as you have noted
from the error message. The gist is that you may not change the state
of the database, and the function must be deterministic. That is, it
must always return the same result give a certain a set of data in
the database.

What your real problem is, is a little unclear to me, but it sounds
like you might get some hints from an article of mine. See
http://www.algonet.se/~sommar/share_data.html.

Jul 20 '05 #4
Rajesh Garg (ra*******@rediffmail.com) writes:
I want the final result in some table coz i can create only a view so
as to use the results of the sproc.


I'm afraid that this a lost battle. You make references to getdate()
and getdate(), and while the result is deterministic in some sense, SQL
Server does not realize this. You could fix this by passing the time-zone
adjustment as a parameter, but then you also invoke dynamic SQL, which
you cannot do in a function.

The best I could think if is to save the result of the SP in a
table, but then you would need some refresh command.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #5
I had to look do a complete turnaround to find a possible way.
Thanks for your help anyways
Cheers
RVG

Erland Sommarskog <so****@algonet.se> wrote in message news:<Xn**********************@127.0.0.1>...
Rajesh Garg (ra*******@rediffmail.com) writes:
I want the final result in some table coz i can create only a view so
as to use the results of the sproc.


I'm afraid that this a lost battle. You make references to getdate()
and getdate(), and while the result is deterministic in some sense, SQL
Server does not realize this. You could fix this by passing the time-zone
adjustment as a parameter, but then you also invoke dynamic SQL, which
you cannot do in a function.

The best I could think if is to save the result of the SP in a
table, but then you would need some refresh command.

Jul 20 '05 #6

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

Similar topics

2
by: Konstantin Zakharenko | last post by:
Hello, Our QA team have running a lot of test scripts (for automated regression testing), they run them on the different databases (Oracle/MS SQL). Several of those tests are dependent on the...
10
by: Bill Edwards | last post by:
I'm trying to produce an array of working days but want to force Saturday and Sunday to return the date of the previous Friday, e.g. Sunday 9/12/04 should return Friday 9/10/04 and similarly...
3
by: Yann Laviolette | last post by:
Hi! I look for a function like the Windows function getdate(&d); and gettime(&t); to have the date and the time. Also I look for a function like spawnl to call another program. These function...
1
by: lasek | last post by:
Hi all, Someone can help me ? char compete; //20 char compete contain a 'date value' returned from oracle procedure (Pro*C)and you can imagine his value, for example,"01/01/2005"
6
by: Matik | last post by:
Hi, I have a funny situation. Within: MSSQL 2000 SP3, everything below described is running on same PC. there is a program running, which sends information to two other programs. This...
6
by: FFMG | last post by:
Hi, My timezone is GMT +2 So when I do a $date = getdate( 0 ); I get: $date = {
3
by: Yas | last post by:
Hi, I am creating creating a table with a Date column dd-mm-yyyy. But I cant seem to find a SQL function that just returns today's date. getDate() returns the time as well so I cant use it. ...
1
by: napjohn8 | last post by:
here is my question with getdate function --12. List the names and staff number for staff who manage detached properties that have a current lease i.e. there is a lease and its end date is in the...
7
by: Bassem | last post by:
I'm trying to select all records inserted in a certain day, so comparing date only and ignore the time. I searched for a function but didn't found. I found this: WHERE day() = day(GetDate()) AND...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...
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,...

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.