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 2000 Forums
 SQL Server Development (2000)
 Assigning current date to a variable in SP

Author  Topic 

vin
Starting Member

26 Posts

Posted - 2003-03-25 : 04:02:02
Hi folks,

I am trying to assign current date to the in parameter of a SP if the user is explicity not sending the values.

The code is like this...
------------------------------------------------------
alter proc test
(
@tablename VARCHAR(30),
@start_dt datetime,
@end_dt datetime,
@tcol VARCHAR(2000) = null
)
As
begin
if @start_dt=''
set @start_dt=getdate()

if @end_dt=''
set @end_dt=getdate()

select @tablename,@start_dt,@end_dt,@tcol
end
go
-----------------------------------------------------

exec test 'Lib_types',NULL,'2003-01-20 04:33:05.533',NULL


o/p:---

Lib_types NULL 2003-01-20 04:33:05.533 NULL

------------------
The value is not getting assigned to the current date. Could somebody help me






Bambola
Posting Yak Master

103 Posts

Posted - 2003-03-25 : 04:23:29
[quote]
if @start_dt=''
set @start_dt=getdate()

if @end_dt=''
set @end_dt=getdate()

[quote]

if ISNULL(@start_dt,'') = ''
set @start_dt=getdate()

if ISNULL(@end_dt, '') = ''
set @end_dt=getdate()

Bambola.
Go to Top of Page

neil
Starting Member

29 Posts

Posted - 2003-03-25 : 04:28:06


You could try
set @start_dt = select GETDATE()





Go to Top of Page

vin
Starting Member

26 Posts

Posted - 2003-03-25 : 04:31:38
hi Bambola
thanx a lot
It is working...
thax again

and also could u pls tell me how to get the yesterdays date



Go to Top of Page

samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2003-03-25 : 04:41:34
quote:

how to get the yesterdays date


select getdate()-1

Sekar
~~~~
Success is not a destination that you ever reach. Success is the quality of your journey.
Go to Top of Page

Bambola
Posting Yak Master

103 Posts

Posted - 2003-03-25 : 04:53:35
quote:

and also could u pls tell me how to get the yesterdays date



Sure.
select dateadd(dy,-1,getdate())

Bambola.
Go to Top of Page
   

- Advertisement -