Solved

Error converting data type nvarchar to bigint.

Posted on 2016-10-22
2
82 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 Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql server query 18 36
Run Stored Procedure uisng ADO 5 20
Getting invalid Syntax SQL. 3 18
Reformat SQL - so SSRS can read the columns 25 11
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

840 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