Click here to Skip to main content
16,017,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have got an error message 'The conversion of the nvarchar value '34234324234' overflowed an int column.' while executing the following statement


SQL
DECLARE
	@Company_ID INT =759
	,@Start_Date DATETIME ='2010/01/01 00:00:00'
	,@End_Date DATETIME ='2011/01/13 00:00:00'
	,@User_ID INT =22704
	,@Page_Index	AS	INT =0
  	,@Page_Size	AS	INT =0
  	
  	CREATE TABLE #ExportDataTable1
		(     
		Customer_ID    	BIGINT			null	
		,Company_ID    	INT			null
		,Surname       	NVARCHAR(100)		null
		,Forename      	NVARCHAR(100)		null
		,Customer_Name	NVARCHAR(150)		null
		,Salesman_name	NVARCHAR(150)		null
		,Address_id    	INT			null
		,Address1	NVARCHAR(510)		null
		,Address2	NVARCHAR(510)		null
		,Address3	NVARCHAR(510)		null
		,Town		NVARCHAR(200)		null
		,Post_code	NVARCHAR(200)		null
		,[State]	NVARCHAR(200)		null
		,Country_Code	CHAR(2)			null
		,Country	NVARCHAR(50)		null
		,Country_id	INT			null
		,Telephone	NVARCHAR(100)		null
		,RowNumber	INT IDENTITY(1,1)	
		)
	INSERT INTO #ExportDataTable1(  Customer_ID    	
					,Company_ID    	
					,Surname       	
					,Forename      	
					,Customer_Name	
					,Salesman_name	
					,Address_id    	
					,Address1		
					,Address2		
					,Address3		
					,Town			
					,Post_code		
					,[State]		
					,Country_Code	
					,Country		
					,Country_id		
					,Telephone
					)
	SELECT DISTINCT  
		CAST(C.custid as BIGINT) AS 'Customer_ID'
                     --Lead customer objects
                     ,C.companyid  AS 'Company_ID'
                     ,C.surname	   AS 'Surname'
                     ,C.forename   AS 'Forename'
                     ,title.title + ' ' + C.forename + ' '+ C.surname
                                   AS 'Customer_Name'
		     ,CON.ForeName + ' ' + CON.Surname
                                   AS 'Salesman_name'
		     ,C.tel	   AS 'Telephone'
			 
                    --Address objects
                    ,0		   AS 'Address_id'
                    ,CA.address1   AS 'Address1' 
                    ,''		   AS 'Address2'
                    ,''		   AS 'Address3'
                    ,''		   AS 'Town'
                    ,CA.postcode   AS 'Post_code'
                    ,''		   AS 'State'
                    --Country objects
                    ,''		   AS 'Country_Code'
                    ,''		   AS 'Country'
                    ,0		   AS 'Country_id'
              FROM customers C 
              inner join   egm.[dbo].entries AS ef
                    ON     C.custid= ef.custid
	      LEFT JOIN    title
	            ON     C.title =title.id 
	      Left JOIN    customeraddress AS CA
		    ON     CA.custid =C.custid
	      Left JOIN    portfolio.dbo.[User] AS U
		    ON     U.[User_id]  =C.salesmanid  
	      Left JOIN    Portfolio.dbo.Contact AS CON
		    ON     CON.Contact_id =U.Contact_id 
					   
	WHERE       
	   ef.companyid = @Company_ID
	   AND f = 1
	   AND ef.[exit] >= @Start_Date
	   AND ef.[exit] <= @End_Date  
        ORDER BY
	   Forename, Surname


[edit]Formatted SQL statement - Original Griff[/edit]
Posted
Updated 12-Jan-11 21:32pm
v3

The value is simply to big to store in an INT type. Try using the BIGINT instead.

http://msdn.microsoft.com/en-us/library/ms187745.aspx[^]

Good luck!
 
Share this answer
 
Comments
Dalek Dave 13-Jan-11 3:49am    
WEll Spotted.
Looks like one of the column in your tables is declared as
NVARCHAR and then it is used as one of the JOINS to INT column, resulting in implicit conversion that fails.

You need to either pass the integer as string or vice-versa. Have a look at this thread[^] discussing the same.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900