SELECT 'A'
Is valid in T-SQL, and it will quite literally display A as the result with no column header. But that query does NOT create a reference called a that holds the value of A.
SELECT CONCAT(a,b);
In SQL 2008 this won't work because that function simply isn't available. Note also that this row terminates with a semi-colon. Neither a nor b exist however as the only preceding line of code does not create any persistent reference.
SELECT a + b;
In SQL 2008 this might work (if both a and b existed and were strings)
SELECT 'B'
Is valid in T-SQL, and it will quite literally display B as the result with no column header. But that query does NOT create a reference called b that holds the value of B.
in brief
SELECT 'A'
does not give that value of A any name to refer to later.
- the concatenation is in the wrong order and terminates with ;
SELECT 'B'
does not give that value of B any name to refer to later.
T-SQL does allow the following:
DECLARE @a AS VARCHAR(10)
DECLARE @b AS VARCHAR(10)
SET @a = 'A'
SET @B = 'B'
SELECT @a + @b
;
Another approach:
select a + b
from (select 'A' as a, 'B' as b) as derived
Here the columns of the derived table are given an alias of a and b, which can be referenced in the outer select clause to perform the concatenation.