Solved

Error when saving to sql table a '/'

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

Technology Partners: 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!

Question has a verified solution.

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

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 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