Link to home
Start Free TrialLog in
Avatar of r3nder
r3nderFlag for United States of America

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of r3nder

ASKER

Thanks Aneesh and Porter