Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error converting data type nvarchar to bigint.

Posted on 2016-10-22
2
Medium Priority
?
107 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 14

Accepted Solution

by:
Nakul Vachhrajani earned 2000 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

705 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