Solved

Error converting data type nvarchar to bigint.

Posted on 2016-10-22
2
89 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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.

739 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