[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Insert statement Problem on SQL 2000

Posted on 2006-05-08
3
Medium Priority
?
168 Views
Last Modified: 2012-05-05
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
Comment
Question by:u7c76
3 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 600 total points
ID: 16636561
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
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 16636603
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
 

Author Comment

by:u7c76
ID: 16639974
That worked!  
Thanks for your quick response.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month19 days, 18 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question