How do you show the string value of a user Defined MYSQL variable in the printed table?
Example:
This…
SELECT CONCAT_WS( ' ', o.FirstName, o.LastName ) AS FirstLast,
`Company`
FROM Orders o
Gives me this..
|---------------|----------|
| FirstLast | Company |
|---------------|----------|
| First1 Last1 | Company1 |
| First2 Last2 | Company2 |
| First3 Last3 | Company3 |
| First4 Last4 | Company4 |
|---------------|----------|
But this…
SELECT @firstlast = CONCAT_WS( ' ', o.FirstName, o.LastName ),
`Company`
FROM Orders o
Gives me this…
|-------------------------------------------------------------|----------|
| @firstlast = CONCAT_WS( ' ', o.FirstName, o.LastName ) | Company |
|-------------------------------------------------------------|----------|
| NULL | Company1 |
| NULL | Company2 |
| NULL | Company3 |
| NULL | Company4 |
|-------------------------------------------------------------|----------|
Obviously this is incorrect, but I don’t know what is.
How would I ‘print’ or display the value? I’m not even sure if I made the variable correct!
Any direction or pointers would be great.
The
=operator is for comparison. Since@firstlastisNULLthe result of the comparison isNULL.The assignment operator is
:=.Of course, in your specific example there is no advantage in using a variable.