Solved

Error when saving to sql table a '/'

Posted on 2016-11-07
5
25 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

20 Experts available now in Live!

Get 1:1 Help Now