I’m trying to get the value of a variable using SQL select queries. Nothing new here.
SELECT p.ProductCode FROM Products_Joined AS p
However, I am wondering if it’s possible to prefix text to that result like;
SELECT 'XJ' + p.ProductCode FROM Product_Joined AS p
So it would look like XJ2156. I’m trying to prefix the data with a predefined string of text. Does anybody know how to accomplish this?
The correct way is exactly what you said in the question:
Note that this only works as long as
ProductCodeis a text type (varchar,nvarchar…).If it’s numeric, you have to convert it to text first: