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
 Using MAX(Mydate) in sp RESOLVED

Author  Topic 

Pinto
Aged Yak Warrior

590 Posts

Posted - 2006-01-05 : 10:23:57
I have an sp which I should return the latest date in my sql table. Howver I am getting this error 'Implicit conversion from data type datetime to bigint is not allowed. Use the CONVERT function to run this query. ' Here's my sp and my code which calls the sp.

CREATE PROCEDURE spRB_MaxDate (
@MaxDate datetime OUTPUT
)
AS
SELECT @MaxDate =MAX(BD_DateRequired)
FROM tblRB_BookingDates

RETURN
GO

Here's how I call it

Dim MySQL1 As String = "spRB_MaxDate"
Dim myConn1 As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim Cmd1 As New SqlCommand(MySQL1, myConn1)
Cmd1.CommandType = CommandType.StoredProcedure

'Add the parameters


Dim outParm As SqlParameter = New SqlParameter("@MaxDate", 0)

outParm.Direction = ParameterDirection.Output
Cmd1.Parameters.Add(outParm)

myConn1.Open()
Cmd1.ExecuteNonQuery()
myConn1.Close()

'
' get value of new id
Dim MaxDate As DateTime = Cmd1.Parameters("@MaxDate").Value

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-01-05 : 10:38:48
what is the datatype of this column: tblRB_BookingDates.BD_DateRequired
Post an example of one of the values in that column.

Be One with the Optimizer
TG
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2006-01-05 : 10:39:58
I changed the ine to this and it worked

Dim outParm As SqlParameter = New SqlParameter("@MaxDate", CDate("01/01/06"))
Go to Top of Page
   

- Advertisement -