Hi,
I have got an error message 'The conversion of the nvarchar value '34234324234' overflowed an int column.' while executing the following statement
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'
,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'
,0 AS 'Address_id'
,CA.address1 AS 'Address1'
,'' AS 'Address2'
,'' AS 'Address3'
,'' AS 'Town'
,CA.postcode AS 'Post_code'
,'' AS 'State'
,'' 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]