?
Solved

Error when saving to sql table a '/'

Posted on 2016-11-07
5
Medium Priority
?
40 Views
Last Modified: 2016-11-07
We have problem with a specific row when saved and even noticed this type of error

Msg 213, Level 16, State 1, Line 29
Column name or number of supplied values does not match table definition.

Open in new window

After checking what was happening we noticed a user decided to use  "/" and iserted ion the transaction code.  So when the transacion is saved via the apps, we get the error above:

The error occur when:

INSERT INTO tablename VALUES ('TRAN/1002',0,0,0)

Open in new window


How can we save to our ms sql tables even though a user decided to use "/"?
0
Comment
Question by:rayluvs
[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
  • 3
  • 2
5 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 2000 total points
ID: 41877901
Supply the column names in your INSERT clause.

INSERT INTO tablename (ColumnA, ColumnB, ColumnC, ColumnD)
VALUES ('TRAN/1002',0,0,0)

Open in new window


>we noticed a user decided to use  "/" and iserted ion the transaction code.
Assuming TransactionCode is where ColumnA is in the above example, guessing it is a numeric data type and the slash makes it a string, so you'll have to have some kinda of data validation step to prevent an attempted insert of a string into a numeric column.
0
 

Author Comment

by:rayluvs
ID: 41877905
Yes thanx!
0
 

Author Comment

by:rayluvs
ID: 41877909
FYI:
The format of each columns is
ColumnA = nvarchar(255)
ColumnB = float
ColumnC = float
ColumnD = float

If columnA is already non-numeric, why the error?
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 41877912
How many columns are in this table?  If there's more than four, and the INSERT statement does not explicitly define the column order, then the INSERT will happen in the order the columns exist, which means if an id or other numeric column is the first one in the table then that's where the 'TRAN/1002' will be inserted.

Another possibility is that there is a column not referenced in the INSERT statement that is defined as NOT NULL.
0
 

Author Comment

by:rayluvs
ID: 41877949
Yes, it has 6 columns.

Ok, understood, thanx!
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

762 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