Saturday, February 25, 2012

Column name as the result of a query?

Simple example would look like that in MS SQL

SELECT 'a' AS (SELECT language_name FROM language WHERE language_id = 1)

So that the display is

English
a

as we assume that

SELECT language_name FROM language WHERE language_id = 1

returns only English

I have tried to that with a variable but it does not work

declare @.that as varchar(15);
set @.that = (select language_name_u from language where language_id = 1);
select 'a' as @.that

LOL

I just tried another way as i was going to post

declare @.that as varchar(15);
set @.that = (select language_name_u from language where language_id = 1);
select 'a' as "@.that"

and it worked!

Posting anyway so people might answer with a better solution with no variable

Thanks a lot

Mordandeclare @.that as varchar(15);
set @.that = (select language_name_u from language where language_id = 1);
select 'a'= @.that

No comments:

Post a Comment