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
 General SQL Server Forums
 New to SQL Server Programming
 Return latest date

Author  Topic 

Pinto
Aged Yak Warrior

590 Posts

Posted - 2006-01-20 : 05:09:05
I am trying to return the latest date in a stored procedure as shown below, but get the error 'incorrect syntax near @strLastDate'

CREATE PROCEDURE spRB_GetLastDateBookingDates

@strLastDate datetime OUTPUT

AS

SELECT max(BD_DateRequired) as @strLastDate
FROM tblRB_BookingDates
GO

RETURN

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-20 : 05:13:09
Use this
SELECT @strLastDate = max(BD_DateRequired)
FROM tblRB_BookingDates

'as' is use for defining alias for the column


-----------------
'KH'

Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2006-01-20 : 05:13:15
SELECT @strLastDate = MAX(BD_DateRequired)

-- Side comment, why preface @LastDate with @str if it isn't a string?
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2006-01-20 : 05:17:33
Thank you, it's working now.

re @str - I don't really know......
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-20 : 06:31:41
>>re @str - I don't really know......

Hereafter use Proper naming conventions

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2006-01-20 : 08:32:45
quote:
Originally posted by madhivanan

Hereafter use Proper naming conventions

Sounds like a sentence.
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2006-01-20 : 09:21:35
But the return value is a string..
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2006-01-20 : 10:01:05
DATETIME
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-20 : 18:45:48
What is the data type for BD_DateRequired ? datetime or varchar ?

It should be a datetime if you are stroing date in it.

If it is varchar or char, borrowing the famouse quote from Madhivanan
quote:
Originally posted by madhivanan

Hereafter use Proper naming conventions



-----------------
'KH'

Go to Top of Page
   

- Advertisement -