user2168066 user2168066 - 11 months ago 66
MySQL Question

Add prefix text to select statement

I am trying to run a select statement on two different servers that have some matching primary keys. I want to be able to select the primary key but add the prefix 'A' to every record


ID "to this" ID
1 A1
2 A2
3 A3

This is what I have for the query

select 'A' + CAST ( AS VARCHAR(25)) as ID,a.*,':', b.*,':',c.*,':', d.*,':', e.*,'REPORTDT', g.*
from labgen.order_ a
join patient b on = b.chart
join insurance c on b.ins1 = c.code
join client d on d.num = a.client1
join salesgrp e on d.salesgroup = e.num
join reportdt g on a.accession = g.accession

Answer Source

Try this in the select statement:

select CONCAT('A', as ID, a.*,':', //etc

This link will also help.