Home All Groups Group Topic Archive Search About

GetDate inside a Function

Author
20 Jan 2006 12:42 AM
John
Hi,

I tried to use GetDate inside a SQL server 2000 user defined function and
got error:

Invalid use of GetDate within a function

Here is my code snippet:

DECLARE @Today smallDateTime
SET @Today = GetDate()

What should I do?

TIA

Author
20 Jan 2006 12:58 AM
Tom Moreau
GETDATE() is nondeterinistic and, thus, cannot be used in a function.  You
can, however, create a view and use it:

create view Now
as
    select getdate () RightNow
go

--
    Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON   Canada
www.pinpub.com

"John" <some***@microsoft.com> wrote in message
news:e6ZConVHGHA.532@TK2MSFTNGP15.phx.gbl...
Hi,

I tried to use GetDate inside a SQL server 2000 user defined function and
got error:

Invalid use of GetDate within a function

Here is my code snippet:

DECLARE @Today smallDateTime
SET @Today = GetDate()

What should I do?

TIA
Author
20 Jan 2006 2:26 AM
Hilary Cotter
do this

declare @date datetime
select @date =max(last_bitch)  from master.dbo.sysprocesses

--
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html

Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com

Show quote
"John" <some***@microsoft.com> wrote in message
news:e6ZConVHGHA.532@TK2MSFTNGP15.phx.gbl...
> Hi,
>
> I tried to use GetDate inside a SQL server 2000 user defined function and
> got error:
>
> Invalid use of GetDate within a function
>
> Here is my code snippet:
>
> DECLARE @Today smallDateTime
> SET @Today = GetDate()
>
> What should I do?
>
> TIA
>
Author
20 Jan 2006 10:19 AM
ML
last_bitch? Must be a dog show database. :)


ML

---
http://milambda.blogspot.com/
Author
20 Jan 2006 2:26 AM
Hilary Cotter
oops sorry, nasty typo there


declare @date datetime
select @date =max(last_bAtch)  from sysprocesses

--
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html

Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com

Show quote
"John" <some***@microsoft.com> wrote in message
news:e6ZConVHGHA.532@TK2MSFTNGP15.phx.gbl...
> Hi,
>
> I tried to use GetDate inside a SQL server 2000 user defined function and
> got error:
>
> Invalid use of GetDate within a function
>
> Here is my code snippet:
>
> DECLARE @Today smallDateTime
> SET @Today = GetDate()
>
> What should I do?
>
> TIA
>
Author
20 Jan 2006 2:50 AM
Dave Frommer
I was wondering if maybe the developer was having a bad day with the
wife/mother-in-law when he designed the Last_Bitch column <grin>

Show quote
"Hilary Cotter" <hilary.cot***@gmail.com> wrote in message
news:uPsQ4jWHGHA.3728@tk2msftngp13.phx.gbl...
> oops sorry, nasty typo there
>
>
> declare @date datetime
> select @date =max(last_bAtch)  from sysprocesses
>
> --
> Hilary Cotter
> Looking for a SQL Server replication book?
> http://www.nwsu.com/0974973602.html
>
> Looking for a FAQ on Indexing Services/SQL FTS
> http://www.indexserverfaq.com
>
> "John" <some***@microsoft.com> wrote in message
> news:e6ZConVHGHA.532@TK2MSFTNGP15.phx.gbl...
>> Hi,
>>
>> I tried to use GetDate inside a SQL server 2000 user defined function and
>> got error:
>>
>> Invalid use of GetDate within a function
>>
>> Here is my code snippet:
>>
>> DECLARE @Today smallDateTime
>> SET @Today = GetDate()
>>
>> What should I do?
>>
>> TIA
>>
>
>
Author
20 Jan 2006 7:12 AM
Mike Hodgson
ROFL!

I must admit, it was the very first thing that caught my eye when I
glanced at Hilary's code snippet.  Great Freudian slip there Hilary!

--
*mike hodgson*
http://sqlnerd.blogspot.com



Dave Frommer wrote:

Show quote
>I was wondering if maybe the developer was having a bad day with the
>wife/mother-in-law when he designed the Last_Bitch column <grin>
>
>"Hilary Cotter" <hilary.cot***@gmail.com> wrote in message
>news:uPsQ4jWHGHA.3728@tk2msftngp13.phx.gbl...

>
>>oops sorry, nasty typo there
>>
>>
>>declare @date datetime
>>select @date =max(last_bAtch)  from sysprocesses
>>
>>--
>>Hilary Cotter
>>Looking for a SQL Server replication book?
>>http://www.nwsu.com/0974973602.html
>>
>>Looking for a FAQ on Indexing Services/SQL FTS
>>http://www.indexserverfaq.com
>>
>>"John" <some***@microsoft.com> wrote in message
>>news:e6ZConVHGHA.532@TK2MSFTNGP15.phx.gbl...
>>   
>>
>>>Hi,
>>>
>>>I tried to use GetDate inside a SQL server 2000 user defined function and
>>>got error:
>>>
>>>Invalid use of GetDate within a function
>>>
>>>Here is my code snippet:
>>>
>>>DECLARE @Today smallDateTime
>>>SET @Today = GetDate()
>>>
>>>What should I do?
>>>
>>>TIA
>>>
>>>     
>>>
>>   
>>
>
>

>
Author
20 Jan 2006 8:47 AM
Tibor Karaszi
Thanks for pointing that out. Needed a good laugh in the morning. :-)

Show quote
"Dave Frommer" <anti@spam.com> wrote in message news:eQaWLxWHGHA.1028@TK2MSFTNGP11.phx.gbl...
>I was wondering if maybe the developer was having a bad day with the
> wife/mother-in-law when he designed the Last_Bitch column <grin>
>
Author
20 Jan 2006 9:20 AM
Uri Dimant
Show quote
:-))))))))))))))))



"Dave Frommer" <anti@spam.com> wrote in message
news:eQaWLxWHGHA.1028@TK2MSFTNGP11.phx.gbl...
>I was wondering if maybe the developer was having a bad day with the
>wife/mother-in-law when he designed the Last_Bitch column <grin>
>
> "Hilary Cotter" <hilary.cot***@gmail.com> wrote in message
> news:uPsQ4jWHGHA.3728@tk2msftngp13.phx.gbl...
>> oops sorry, nasty typo there
>>
>>
>> declare @date datetime
>> select @date =max(last_bAtch)  from sysprocesses
>>
>> --
>> Hilary Cotter
>> Looking for a SQL Server replication book?
>> http://www.nwsu.com/0974973602.html
>>
>> Looking for a FAQ on Indexing Services/SQL FTS
>> http://www.indexserverfaq.com
>>
>> "John" <some***@microsoft.com> wrote in message
>> news:e6ZConVHGHA.532@TK2MSFTNGP15.phx.gbl...
>>> Hi,
>>>
>>> I tried to use GetDate inside a SQL server 2000 user defined function
>>> and got error:
>>>
>>> Invalid use of GetDate within a function
>>>
>>> Here is my code snippet:
>>>
>>> DECLARE @Today smallDateTime
>>> SET @Today = GetDate()
>>>
>>> What should I do?
>>>
>>> TIA
>>>
>>
>>
>
>
Author
20 Jan 2006 11:48 AM
Tom Moreau
The mask has slipped... ;-)

--
   Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON   Canada
www.pinpub.com
..
"Hilary Cotter" <hilary.cot***@gmail.com> wrote in message
news:uPsQ4jWHGHA.3728@tk2msftngp13.phx.gbl...
oops sorry, nasty typo there


declare @date datetime
select @date =max(last_bAtch)  from sysprocesses

--
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html

Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com

Show quote
"John" <some***@microsoft.com> wrote in message
news:e6ZConVHGHA.532@TK2MSFTNGP15.phx.gbl...
> Hi,
>
> I tried to use GetDate inside a SQL server 2000 user defined function and
> got error:
>
> Invalid use of GetDate within a function
>
> Here is my code snippet:
>
> DECLARE @Today smallDateTime
> SET @Today = GetDate()
>
> What should I do?
>
> TIA
>
Author
20 Jan 2006 2:09 PM
ML
Of all solutions mentioned in other post (with the exception of the "b*tch"
discussion) the fastest would be to simply supply the current datetime as a
parameter.


ML

---
http://milambda.blogspot.com/

AddThis Social Bookmark Button