1

I want to create a SQL table with the following column datatypes.

  1. Name : Varchar
  2. Grade : Data will have “#” followed by numbers and also can be varchar. Eg : #1, #2, TML
  3. Sizes : Can be whole numbers and fractions. Eg: 26/30, 80, 85/69
  4. 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.

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

5 Comments

Thank U! It's resolved. Have been struggling with it for some time!
Hi, I have a small issue here, I have observed that the "Sizes" value is "0" and not 26/30 after I run the statement. Is it possible to display 26/30 in the column?
even if you give float because of '/' divided by symbol it is getting divided..instead of that change that data type to varchar(10) and give value in '26/30' in single quotes
It has executed now. Thnx a ton!
How I wish I could. I have not got enough reputation to upvote your answer :( . Will do once I can.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.