Solved

Error converting data type nvarchar to bigint.

Posted on 2016-10-22
2
87 Views
Last Modified: 2016-10-22
hi ,
this is the query :
Select Top(200)OrderRunId,OrderCustNum,OrderDate,OrderSum,OrderTM,
OrderEmpNum,Orders.OrderNum,Manot,AspkaDate,Mifrat,CloseDate,CustName,
(Select SUM(ISNULL(Quant,0)) From dbo.OrderDet where OrderDet.OrderNum = OrderRunId) as Quantity
from Orders inner join dbo.OrderDet on OrderRunId = Orders.OrderNum
inner join Customers on OrderCustNum=CustomerRunId order by OrderRunId desc

Open in new window


why i am getting this error  ?
0
Comment
Question by:Tech_Men
2 Comments
 
LVL 13

Accepted Solution

by:
Nakul Vachhrajani earned 500 total points
ID: 41855613
Can you check your underlying data? I suspect you have a data-type mismatch.

Suspect columns are:
- OrderRunId v/s OrderNum (one of them must be a VARCHAR whereas the other would be a BIGINT) - check in both dbo.OrderDet and dbo.Orders tables
- Quant (does Quant have non-numeric data? If yes, the ISNULL will fail because it needs both the expression and replacement value to be of the same datatype)

To resolve, you will have to either remove/correct the offending data or use explicit conversion to convert both sides to a common datatype.

When SQL Server faces mismatched data-types, it tries to *implicitly* convert one to another based on the rules of data type precedence which states that data of the data type with lower precedence (in this case VARCHAR) is converted to one with higher precedence (BIGINT).  I have written about this with an example in my blog post (https://nakulvachhrajani.com/2015/08/03/0357-sql-server-best-practices-avoid-implicit-conversions-as-they-may-cause-unexpected-issues-part-01/) in case you would like to take a look.
0
 

Author Closing Comment

by:Tech_Men
ID: 41855621
nice thanks ...
0

Featured Post

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

756 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