SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Error converting data type varchar to numeric


Error converting data type varchar to numeric

Author
Message
OldSageMonkey
OldSageMonkey
Grasshopper
Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)

Group: General Forum Members
Points: 23 Visits: 17
Hi All,
Im not the greatest at SQL but Im getting better. I do not understand why I get the following error in my simple select query. I get the (Msg 8114, Level 16, State 5, Line 1 Error converting data type varchar to numeric.)

SELECT
ed.[Employee Name],
bd.SORTUSER_EMPID,
bd.SORTDTTM
FROM
[BOXES].[dbo].[BOXDETAILS_ORL] bd
JOIN
[Employee].[dbo].[Employee Data] ed
ON
bd.SORTUSER_EMPID = ed.[Employee ID]
WHERE
SORTDTTM >= dateadd(day,-30,getdate())


calvo
calvo
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1864 Visits: 4009
Perhaps some table definitions, test data, and expected output?

______________________________________________________________________________________________
Forum posting etiquette. Get your answers faster.
OldSageMonkey
OldSageMonkey
Grasshopper
Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)

Group: General Forum Members
Points: 23 Visits: 17
I can query the one box table but when I add the join and include bringing in the employees name it give me the error, and I cannot figure out which line it is. Plus I dont understand what your asking for with table definitions, sorry. But I am just trying to get the persons name, next to their EMPID and the sorted date time. (SORTDTTM.)
Lowell
Lowell
One Orange Chip
One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)

Group: General Forum Members
Points: 29587 Visits: 39986
i would guess it's due to the joins:

bd.SORTUSER_EMPID = ed.[Employee ID]


i think maybe one column is an integer or numeric column, and the other is varchar?
due to data type precedence, the varchars are being converted to integer, and some values are not actually numeric:


try converting to a varchar join for teh data type, since it's being implicitly converted anyway?

CONVERT(varchar,bd.SORTUSER_EMPID) = CONVERT(varchar,ed.[Employee ID])



Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Luis Cazares
Luis Cazares
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17474 Visits: 19122
My guess is that one of the columns bd.SORTUSER_EMPID or ed.[Employee ID] is numeric and the otherone is a varchar and contains a non-numeric value. This error would be caused by an implicit conversion. To avoid it, cast the numeric column as varchar and consider changing the data types from your columns to the adequate data types.

EDIT: Lowell had the same guess than me and posted faster than me :-D


Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
OldSageMonkey
OldSageMonkey
Grasshopper
Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)

Group: General Forum Members
Points: 23 Visits: 17
Thanks Lowell, That was it. :-D
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search