user2168066 user2168066 - 2 months ago 11
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

ex:

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


This is what I have for the query

select 'A' + CAST (a.id AS VARCHAR(25)) as ID,a.*,':', b.*,':',c.*,':', d.*,':', e.*,'REPORTDT', g.*
from labgen.order_ a
join patient b on a.id = 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

Try this in the select statement:

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

This link will also help.

Comments