Solved

Error when saving to sql table a '/'

Posted on 2016-11-07
5
27 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
  • 3
  • 2
5 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 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 65

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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