Solved

Error converting data type nvarchar to bigint.

Posted on 2016-10-22
2
58 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 11

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now