Solved

INSERT Statement into SQL Server

Posted on 2002-07-15
6
149 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
6 Comments
 
LVL 5

Expert Comment

by:BlackDiamond
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 1

Expert Comment

by:soferstam
Comment Utility
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
Comment Utility
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
Comment Utility
Comment from expert accepted as answer

Computer101
E-E Admin
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

763 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

11 Experts available now in Live!

Get 1:1 Help Now