Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select statement as default for parameter for SP?

Author  Topic 

duanecwilson
Constraint Violating Yak Guru

273 Posts

Posted - 2009-08-12 : 15:42:59
I have to use first day of last month and last day of last month as defaults for a stored procedure. I want the user to be able to input them. This is one example of what should be the default for @EndDate:
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))

If I can't use that, is there another way to get that as the default?

Duane

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-08-12 : 15:51:43
may never get a good query plan doing that but

create proc ddd
@param datetime = null
AS

SET NOCOUNT ON;

Declare @param2 datetime

select @param2 = isnull(@param, DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)))

SELECT @param2
Go to Top of Page
   

- Advertisement -