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)
 Default Values in SQL Server 2000 - Dates

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-10-08 : 09:46:55
Steve writes "How do you set a date field in the database to have a default value of the current datetime?

This is easily done in MS Access but I seem to be having troubles with SQL Server.

Alternatively, how do you pass a datetime to a stored procedure in SQL Server. My current procedure is not working BUT if I take out the date parameter it is fine.

ie. Public Function AddRedirectPage( ByRef objConn, ByRef dtReferDate, ByRef strSiteName, ByRef strUrl )

'Reconnect if needed
If objConn.State = 0 Then
Set objConn = GetDBConnection()
End If

'Create and setup command
Dim objRedirectCmd
Set objRedirectCmd = Server.CreateObject("ADODB.Command")

With objRedirectCmd
.CommandText = "sp_AddRedirectPage"
.CommandType = adCmdStoredProc
.ActiveConnection = objConn
End With

'Append parameters
Dim objParamDate '**IF YOU REMOVE THIS PARAMETERS FROM STORED PROCEDURE AND HERE, EVERYTHING WORKS FINE
Set objParamDate = objRedirectCmd.CreateParameter("@referdate", adDate, adParamInput, 8, dtReferDate )
objRedirectCmd.Parameters.Append( objParamDate )

Dim objParamName
Set objParamName = objRedirectCmd.CreateParameter("@name", adVarChar, adParamInput, 200, strName)
objRedirectCmd.Parameters.Append( objParamName )

Dim objParamUrl
Set objParamUrl = objRedirectCmd.CreateParameter("@url", adVarChar, adParamInput, 200, strUrl)
objRedirectCmd.Parameters.Append( objParamUrl )

'Execute command
objRedirectCmd.Execute()




End Function"

1fred
Posting Yak Master

158 Posts

Posted - 2002-10-08 : 09:51:12
Right click on your table in enterprise manager. Click on design table and then click on your field. Look at the bottom your should find the properties default value. Just type (getdate()), and your field must be datetime

Go to Top of Page
   

- Advertisement -