Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getdate() error

Status
Not open for further replies.

katbear

Programmer
Mar 14, 2007
270
US
Help.

Why won't this work?

Code:
alter PROCEDURE myProc
(
  @AsOfDate DATETIME = GETDATE(),
)

Error: Incorrect syntax near '('.

Thanks
 
alter PROCEDURE myProc
(
@AsOfDate DATETIME = NULL,
)
AS
if @AsOfDate is null set @AsOfDate = GETDATE()

[COLOR=#aa88aa black]Cum catapultae proscriptae erunt tum soli proscript catapultas habebunt.[/color]
 
This is pure speculation but I have the feeling that the IF statement is more efficient than the Coalesce method.

My reasoning is that checking a single condition, in terms of the CPU execution steps necessary to carry it out, is more efficient than always making an assignment. In the case that the variable is not null, one less step has to be taken.


IS NULL, IF:
check for nullness, set variable to single expression.

IS NOT NULL, IF:
check for nullness.

IS NULL, Coalesce:
check for nullness, set variable to single expression.

IS NOT NULL, Coalesce:
check for nullness, set variable to single expression.

[COLOR=#aa88aa black]Cum catapultae proscriptae erunt tum soli proscript catapultas habebunt.[/color]
 
It means that given the same inputs, a function is not guaranteed to have the same output each time it is invoked.

A deterministic function always gives the same output for the same input. Power(10, 2) will always yield 100, every time. Getdate(), even with no inputs, yields a different value each time.

But I was under the impression that expressions couldn't be SP default values no matter what kind of expression they were, deterministic or not. Only literals are allowed (unless I'm wrong and if so please someone tell me).

[COLOR=#aa88aa black]Cum catapultae proscriptae erunt tum soli proscript catapultas habebunt.[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top