Resolving "Arithmetic overflow error converting varchar to data type numeric" in SQL for insert statement - mysql

I want to create a SQL table with the following column datatypes.
Name : Varchar
Grade : Data will have “#” followed by numbers and also can be varchar. Eg : #1, #2, TML
Sizes : Can be whole numbers and fractions. Eg: 26/30, 80, 85/69
Average : Will be decimal numbers.
I have created table based on the above requirements:
CREATE TABLE [dbo].[Report_Proj](
[Name] [nvarchar](255) NOT NULL,
[Grade] [nvarchar](50) NOT NULL,
[Sizes] [float](10) NOT NULL,
[Average][decimal](10, 10) NOT NULL
But when I insert data into this table I’m getting the error “Msg 8115, Level 16, State 8, Line 1
Arithmetic overflow error converting varchar to data type numeric.
The statement has been terminated.”
Where could I possibly be going wrong.
Need the above data for reporting purposes and will not have any arithematic calculations in future.

just change the decimal value data type to (10,2)
declare #Report_Proj TABLE (
[Name] [nvarchar](255) NOT NULL,
[Grade] [nvarchar](50) NOT NULL,
[Sizes] [float](10) NOT NULL,
[Average][decimal](18, 2) NOT NULL)
insert into #Report_Proj ([Name],[Grade],[Sizes],[Average])values ('ram','#1',26/30,10.2)
select * from #Report_Proj

Related

SQL Using max value from a table as the starting number in an Identity column

This is a stupid question, but here it goes. I need to use the result of the first query as the
starting number in an Identity column. I don't want to do it manually each time.
SELECT MAX([VM_KEY]) + 1 as VM_KEY FROM [DB1].[dbo].[Table1] --30474373
CREATE TABLE [dbo].[table2](
[Segment_Name] [varchar](8) NULL,
[Segment_Name_Flag] [varchar](38) NULL,
[Counter] [int] NULL,
[VM_KEY] [int] IDENTITY(30474373,1) NOT NULL)
Any help would be appreciated.

SYSTEM ERROR: NumberFormatException: Zero length BigInteger

This error often appears when I try to CTAS from CSV data.
CSV Schema:
create or replace schema
(
`SomeCol1` BIGINT NOT NULL,
`SomeCol2` INT NOT NULL,
`SomeCol3` INT NOT NULL DEFAULT '0',
`SomeCol4` DATE NOT NULL FORMAT 'yyyy-MM-dd',
`SomeCol5` INT,
`SomeCol6` INT NOT NULL,
`SomeCol7` DECIMAL(10,2) NOT NULL,
`SomeCol8` DECIMAL (10,2) NOT NULL,
`SomeCol9` DOUBLE
)
for table "<path to CSVs>"
properties ('drill.strict' = 'true')
Then I run:
create table "<path to a parquet>" as select
<all 9 columns>
from "<path to CSVs>"
In some cases this error happens:
SYSTEM ERROR: NumberFormatException: Zero length BigInteger
Fragment 0:0
Please, refer to logs for more information. *
*) There is nothing more in the logs.
There are gigabytes of rows in the CSV and some of them are obviously in some bad shape.
1) How I'm supposed to find such error? At least on which column it happened? (except some hacks like reducing the count of columns and then rows, etc ..)
2) Is there some option to increase verbosity?
3) Or can I adjust the schema for .. better behavior?

Incorrect integer value: '' for column 'ProductSubcategoryKey'

I am trying to import my CSV file into the MySQL database. However, I am getting mentioned error. It applies to about 70% of my 800 records.
This is an example of the erroneous records.
1,"AR-5381",,"Adjustable Race","NA",
2,"BA-8327",,"Bearing Ball","NA",
3,"BE-2349",,"BB Ball Bearing","NA",
4,"BE-2908",,"Headset Ball Bearings","NA",
5,"BL-2036",,"Blade","NA",
6,"CA-5965",,"LL Crankarm","Black",
7,"CA-6738",,"ML Crankarm","Black",
8,"CA-7457",,"HL Crankarm","Black",
9,"CB-2903",,"Chainring Bolts","Silver",
10,"CN-6137",,"Chainring Nut","Silver",
And here is the structure of my table:
CREATE TABLE [Product](
[ProductKey] [int] NOT NULL,
[ProductAlternateKey] [nvarchar](25) NULL,
[ProductSubcategoryKey] [int] NULL,
[ProductName] [nvarchar](50) NOT NULL,
[Color] [nvarchar](15) NOT NULL,
[Size] [nvarchar](50) NULL
)
They all have this field as ,, . However, it is not a string and NULL value is allowed, so I don't understand where is the problem
How are you importing the data into the database? The problem here is that it reads the third column as empty string, which of course is not valid for an integer column. So in your case, you should tell whatever program you use for importing to not import this column at all or change it to null.

Column name or number of supplied values does not match table definition.

I'm writing a program in visual to use a database to make a PC builder type program. When I try to insert data into the PROCESSORS table, I get the following error:
ERROR:
Column name or number of supplied values does not match table definition.
Since my other inserts work fine, I don't know what's wrong with this one.
DROP TABLE PROCESSORS
DROP TABLE MOTHERBOARDS
DROP TABLE SOCKET_TYPE
DROP TABLE STORE;
CREATE TABLE PROCESSORS (
PRODCUT_ID VARCHAR(20) PRIMARY KEY,
BRAND VARCHAR(6) NOT NULL,
CORES INTEGER NOT NULL,
SPEED DECIMAL NOT NULL,
INTEGRATED_GPU VARCHAR(40) NOT NULL);
CREATE TABLE STORE(
STORE_ID VARCHAR(20) PRIMARY KEY,
PRODUCT_ID VARCHAR(20) NOT NULL,
PRODUCT_NAME VARCHAR(50) NOT NULL,
STORE VARCHAR(30) NOT NULL,
PRICE INTEGER NOT NULL);
/*Newegg Product I7-4470*/
INSERT INTO PROCESSORS VALUES('BX80646I74770','Intel',4,3.4,'None');
INSERT INTO STORE VALUES('N82E16819116900','BX80646I74770','Intel Core I7-4470 Haswell','Newegg',309.99);
Looks like you're entering a decimal in to an integer in the STORE Price column :)
Edit: Just noticed the DECIMAL type of the column is missing the impelementation syntax, e.g. DECIMAL(2,2). As it stands, according to here the default when not provided is DECIMAL(10, 0) which is a 10 digit integer basically. Provide precise parameters to the DECIMAL data type to allow the correct numbers with decimal places to be added, this will fix the INSERT problem.

SQL Server : storing date and time in separate columns

I am using SQL Server 2008 :
I want to keep date and time separated
I want both of them to have default value like NOW() when record is created
How can I control format of date and time
So far I have this code :
CREATE TABLE [Table1]
(
[RECORD_ID] int IDENTITY (1, 1) NOT NULL,
[INPUT_ID] int NOT NULL,
[DATE] date DEFAULT GETDATE(),
[TIME] time(7) DEFAULT GETDATE(),
PRIMARY KEY ([RECORD_ID])
)
I just don't know how to set time condensed data type to time(0). Is rest of my code ok, or there is a better approach ?