Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

INSERT Statement into SQL Server

Posted on 2002-07-15
6
Medium Priority
?
166 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
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 1200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

885 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