Conversion failed when converting the varchar value '; ' to data type int.

I am having an issue with this query does anyone know why? therror is
Conversion failed when converting the varchar value '; ' to data type int.

 Select * FROM(  SELECT JobDownholeEquipment.StartTime as 'StartTime', 
 Cast(Job.JobID as char(25)) AS 'Location', 'Job' AS 'Event',  
 ('Tool Type: '+ Case JobType WHEN 0 Then 'surefire' else 'wildfire' end + '; '+'Run Number: '+ JobDownholeEquipment.RunID + '; ' + 'Tool Size: ' + JobDownholeEquipment.ToolSize + '; ' +   'Company: ' + Job.Company + '; ' + 'Rig: '+ Job.Rig + '; ' + 'Rig Number: ' +  Job.RigNumber + '; ' + 'Well Name: '+ Job.WellName ) AS 'Event Notes'  
 FROM (Job INNER JOIN JobDownholeEquipment ON Job.JobID = JobDownholeEquipment.JobID) 
 INNER JOIN SerializedAssets ON JobDownholeEquipment.ToolNumber = SerializedAssets.SerialNumber  
 WHERE JobDownholeEquipment.ToolNumber = 2 
 AND SerializedAssets.ToolType = 'TN' AND Job.Company <> 'Test Company'           
 AND JobDownholeEquipment.StartTime BETWEEN          '2012-01-01 00:00:00' AND '2015-12-31 23:59:59'   
 UNION  SELECT ToolAssemblies.UploadTime as 'StartTime', l.Location as 'Location', 'Tool Communication' AS 'Event', 
 ('Tool Size: ' + ToolSize + '; '+ 'Controller: '+ControllerSN +'; '+ 'Battery Gauge: '+BatteryGaugeSN +'; '+ 'Battery: ' + BatterySN + '; '+ 'Magnetics: '+ MagneticsSN) AS 'Event Notes'  
 FROM ToolAssemblies  JOIN   Locations as l ON l.LocationIndex = ToolAssemblies.DefaultLocationIndex  
 WHERE ToolAssemblies.ToolNumber= 2           AND ToolAssemblies.UploadTime BETWEEN          '2012-01-01 00:00:00' AND '2015-12-31 23:59:59'          
 UNION         SELECT iis.UploadDate as 'StartTime',l.Location as 'Location', '' as 'Event', 
 'Parts History reconcile' as 'Event Notes'          FROM Inventory_SerializedAssets iis         
 JOIN   Locations as l ON l.LocationIndex = iis.LocationID          
 WHERE iis.SerialNumber = 2  AND iis.ToolType = 'TN'        
 AND iis.UploadDate 
 BETWEEN            '2012-01-01 00:00:00' AND '2015-12-31 23:59:59'    )X  
 Order By StartTime DESC

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase AdministratorCommented:
replace 'Run Number: '+ JobDownholeEquipment.RunID + '; '


'Run Number: '+ cast( JobDownholeEquipment.RunID as varchar )  + '; '

Do similar casting for all the integer data types

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PortletPaulEE Topic AdvisorCommented:
AND ToolAssemblies.UploadTime BETWEEN '2012-01-01 00:00:00' AND '2015-12-31 23:59:59'

23:59:59 is NOT the end of a day (there are sub-second units to cater for)

the end of '2015-12-31' is actually '2016-01-01 00:00:00 +00000'

You should not use BETWEEN for dates ranges because of this see: "Beware of Between"
r3nderAuthor Commented:
Thanks Aneesh and Porter
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.