I’m working on a SQL Server database where db1.dbo.batches.id is stored as 1234 but db2.dbo.activity.batch_id is stored as B1234.
I am trying to join the two tables, something like this…
SELECT column1, column2
FROM db1.dbo.batches AS b
INNER JOIN db2.dbo.activity AS a
ON ('B' + b.id) = a.batch_id
The issue is the ('B' + b.id). I have tried CONCAT('B' + b.id), CAST('B' + b.id), and CONVERT(varchar(10),'B' + b.id) none of which have worked.
I can run a second select query but I was hoping for something more elegant.
Any ideas? Cheers!
Try putting the ‘B’ outside of the CONVERT function: