Fabio
Fabio

Reputation: 59

T-SQL Using a varchar in a select statement

I need to use the return of a function (VARCHAR) as columns in a select statement. For example:

A function fn1 returns a varchar @result='Alice,Bob'. How can I do a query using @result in a select statement, e.g:

SELECT @result FROM B 

and obtain the records of the columns Alice and Bob of another Table.

Thanks in advance

Upvotes: 1

Views: 1349

Answers (1)

npclaudiu
npclaudiu

Reputation: 2441

Try exec('select ' + fn_1() + ' from T')

Upvotes: 3

Related Questions