Solved

INSERT Statement into SQL Server

Posted on 2002-07-15
6
160 Views
Last Modified: 2010-05-02
I am trying to run this statement to insert a record into SQL Server but I am getting an error: Record Update Error on #. Does anyone know how to correct this SQL statement and get rid of the error?

SQL = "INSERT INTO [Chart Location] (MRN, FName, LName, DOB, Area, AttPhy, Visit, [Date], UserID, [Timestamp]) values('" + sMRN + "', '" + sFirst + "', '" + sLast + "', #" + sBirthDate + "#, '" + sArea + "', '" + sAttPhy + "', '" + sVisit + "', #" + sDate + "#, 'HL7 Sock', #" & Now() & "#)"
0
Comment
Question by:stevensc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 5

Expert Comment

by:BlackDiamond
ID: 7155600
The # signs are an MS Access'ism.  You should not need them when making a call directly to SQL server.  Try putting the dates inside single ticks like your other values.  SQL server will convert the strings to datetime values before it does the insert.
0
 
LVL 5

Accepted Solution

by:
BlackDiamond earned 300 total points
ID: 7155607
Give it a try this way

SQL = "INSERT INTO [Chart Location] (MRN, FName, LName, DOB, Area, AttPhy, Visit, [Date], UserID, [Timestamp]) values('" + sMRN + "', '" + sFirst + "', '" + sLast + "', '" + sBirthDate + "', '" + sArea + "', '" + sAttPhy + "', '" + sVisit + "', '" + sDate + "', 'HL7 Sock', '" & Now() & "')"
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7155652
You also may have better luck with the date columns if you use a yyyy-mm-dd format, as in:
Format$(Now(), "YYYY-MM-DD")

Anthony
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:soferstam
ID: 7155898
It also could give this error when you trying to insert not acceptable value.For example with wrong datatype or null for requered column.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8012509
Hi stevensc,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept BlackDiamond's comment(s) as an answer.

stevensc, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 8096033
Comment from expert accepted as answer

Computer101
E-E Admin
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

751 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