Solved

Date() and Now() for MSSQL

Posted on 2006-06-14
4
1,596 Views
Last Modified: 2006-11-18
I am getting an error on my date and now functions when trying to insert into the MSSQL database:

      strSQLTST = ("Insert into Transactions "_
      &"(buyerID, "_
      &"sellerID, "_
      &"Type, "_
      &"[date], "_
      &"[dateTime], "_
      &"Location, "_
      &"status, "_
      &"amountW) "_
      &"VALUES "_
      
      &"("&      User&      ","_
      &""&      -1&            ","_
      &""&      3&            ","_
      &"date()," _
      &"Now()," _
      &"'"& Home &"'," _
      &"'Complete'," _
      &""&      Deduct&      ")")

What do I use for MSSQL?  This was originally for Access =)  Thanks!
0
Comment
Question by:JuniorBee
  • 2
4 Comments
 
LVL 22

Expert Comment

by:WMIF
ID: 16907824
use the vb functions and put quotes around them.

strSQLTST = ("Insert into Transactions "_
     &"(buyerID, "_
     &"sellerID, "_
     &"Type, "_
     &"[date], "_
     &"[dateTime], "_
     &"Location, "_
     &"status, "_
     &"amountW) "_
     &"VALUES "_
     
     &"("&     User&     ","_
     &""&     -1&          ","_
     &""&     3&          ",'"_
     &date() & "','" _
     &Now() & "'," _
     &"'"& Home &"'," _
     &"'Complete'," _
     &""&     Deduct&     ")")
0
 
LVL 22

Accepted Solution

by:
WMIF earned 500 total points
ID: 16907837
otherwise if you want the date and time from the sql server, use "getdate()".
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 16907909
Why are you using TWO date fields - it looks like Date and DateTime?  A single field can cover both.
0
 

Author Comment

by:JuniorBee
ID: 16907917
I forgot why I was using 2.  :/
I know it was for a good reason.  (laughs)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now