1

I have the following table in SQL Server 2014:

effDate  DATETIME(23) NOT NULL  
rateType CHAR(2) NOT NULL  
rate     DECIMAL(10, 8) NOT NULL  

When I run the following query, I get an error message:

Select Failed: 8114 Error converting data type varchar to numeric.

My query:

insert into hprs.dbo.OHPRSrates 
values ('01/01/2019', 'D', 0.02642000)

Why? The only numeric column in this row is rate and the insert value is clearly numeric

2
  • 2
    Any triggers?.. Commented Jan 3, 2019 at 18:26
  • 4
    What is that DATETIME(23) datatype?? Is it just a silly typo and you really mean DATETIME2(3) ?? Also: when using dates in string literal form, I'd always recommend to use the ISO-8601 format YYYYMMDD (no dashes or anything) to be independent of any language & regional settings in your SQL Server Commented Jan 3, 2019 at 18:28

2 Answers 2

5

I suspect those columns are not in the order you believe they are in. When inserting, you should really declare the columns you're inserting into. Does this, by any chance, work?

INSERT INTO hprs.dbo.OHPRSrates (effDate,rateType,rate)
VALUES ('01/01/2019','D',0.02642000);

Also, however, I would recommend using a unambiguous date format, such as yyyyMMdd. Thus, for your date, '20190101'. A value of 01/01/2019 is 01 January what ever way you read it, however, is 01/02/2019 02 January or 01 February? The answer depends on your language (settings).

Sign up to request clarification or add additional context in comments.

Comments

1

try this

insert into hprs.dbo.OHPRSrates 
(effDate, rateType, rate) values ('01/01/2019','D',0.02642000)

7 Comments

That was a good idea adding the column names, but "insert into hprs.dbo.OHPRSrates (effdate,ratetype,rate) values ('01/01/2019','D',0.02642000)" does not work. Same error. I also tried converting the date value to datetime, just in case that was the problem, but that didn't help. Any other ideas? This query has actually been running for years, so I don't know what's different.
Considering this is the same SQL as in my answe,r this implies there's more at hand, @MarkFoley . I suspect Martin Smith is right in the comment under your question "Any Triggers?"
Ah! I missed Martin Smith's comment. Of course! I checked the insert trigger and yes, it was catenating a varchar with the numeric rate to log to a change record. I changed that to catenating the varchar value with convert(varchar,rate), and the insert worked! Thanks a for the help!
BTW - this is my first stackoverflow post and I don't see how to mark an answer as accepted or a question as solved. I find nothing to 'click'
@MarkFoley Sorry for late response, you can upvote helpful answers (no matter how many) also you can mark it as answer below the upvote/downvote button
|

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.