General discussion

Locked

Stord Procedure to Get SQL Server Date

By adel_ibrahim ·
How can I get The server date in MSACCESS97 Form?
the follwing is a stord procedure I tried several time but I got nothing:

.SQL = "ALTER PROCEDURE GetServerDate AS DECLARE @Mydate DATETIME " & _
"SET @Mydate = GETDATE() " & _ "SELECT CAST(@Mydate AS varchar(11))"
.Execute
Is There is Some one can write to me The complete steps to get the server date on the access97 form.

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Stord Procedure to Get SQL Server Date

by Glen_McLeod In reply to Stord Procedure to Get SQ ...

Fisrt of all, this SQL will not execute the stored procedure, it will alter an existing one.

If the proc exists, you need to call it with a command object if you're using ADO.

Here's the ADO code:

Dim cmTime as ADODB.Command
Set cmTime = New ADODB.Command

With cnTime

Set .ActiveConnection = cnServer 'ADO Connection
.CommandType = adCmdStoredProc
.CommandText = "GetServerDate"
.Parameters.Append .CreateParameter("MyDate", adDate, adParamOutput)
.Execute
dLocalDateVariable = .Parameters("MyDate").Value

End With

You'd need to change your stored procedure to return the date *as a date* in an output parameter, but that's no big deal:

Alter Procedure GetServerDate (@MyDate datetime OUTPUT)
As
Begin
Set @MyDate = GetDate()
End

This way, you get the actual date value returned to your app, and you can format it anyway you want. You save memory and execution time by not creating a recordset object and assigning the results of a select query to the recordset, then reading the recordset's field for the value.

If you're using DAO, you're on your own, as I havent used DAO in a while, and the way to do this isn't quite so straightforward. RDO would be better, and actually quite similar to the code above.

Good Luck

Glen

Collapse -

Stord Procedure to Get SQL Server Date

by adel_ibrahim In reply to Stord Procedure to Get SQ ...

many thanks it is Ok

Collapse -

Stord Procedure to Get SQL Server Date

by adel_ibrahim In reply to Stord Procedure to Get SQ ...

This question was closed by the author

Back to Software Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums