• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

Insert statement Problem on SQL 2000

Does SQL server provide a sql command for current timestamp?  I was hoping to use a sql constant instead of code to generate the timestamp on an insert.  Below is an example of the query string.
   
  Dim sqlCommand As New StringBuilder
        sqlCommand.Append("Insert into tscAccount (account_name_txt, ")
        sqlCommand.Append("office_number_id, team_id, nmd_id, ")
        sqlCommand.Append("address_id, phone_number_id, ")
        sqlCommand.Append("create_user_name_txt, create_login_id_txt, create_tmstmp) ")
        'sqlCommand.Append(", modify_user_name_txt, ")
        'sqlCommand.Append("modify_login_id_txt, modify_tmstmp) ")

        sqlCommand.Append("Values ('")
        sqlCommand.Append(accountBean.AccountName)
        sqlCommand.Append("', ")
        sqlCommand.Append(nextOfficePhoneId)
        sqlCommand.Append(", ")
        sqlCommand.Append(accountBean.TeamId)
        sqlCommand.Append(", ")
        sqlCommand.Append(accountBean.NmdId)
        sqlCommand.Append(", ")
        sqlCommand.Append(nextAddressId)
        sqlCommand.Append(", ")
        sqlCommand.Append(nextMainPhoneId)
        sqlCommand.Append(", '")
        sqlCommand.Append(createUserName)
        sqlCommand.Append("', '")
        sqlCommand.Append(createUserId)
        sqlCommand.Append("', ")
        sqlCommand.Append("CURRENT_TIMESTAMP ")
        sqlCommand.Append(")")

Thanks,
Brian
0
u7c76
Asked:
u7c76
1 Solution
 
bruintjeCommented:
Hi u7c76,

There is the GETDATE() command

sqlCommand.Append(" GETDATE() ")

but it is T-SQL not sure what it would be in MySQL or Oracle, if it would work however is a second why not add it through a variable in code

hope this helps a bit
bruintje
0
 
arif_eqbalCommented:
You can use GetDate() as bruintje mentioned or use just Date() or CurrDate() functions
However if you want you can use the vb date or now function as well.
The difference is with vb function you'd get the client machine's timestamp while with the SQL function you'd get the Database Server's timestamp.

For VB function you need
sqlCommand.Append(Now)  
instead of
sqlCommand.Append("CURRENT_TIMESTAMP ")
0
 
u7c76Author Commented:
That worked!  
Thanks for your quick response.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tackle projects and never again get stuck behind a technical roadblock.
Join Now