Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Analysis Server and Reporting Services (2005)
 Passing Parameters in Select clauses : SSRS

Author  Topic 

Jarrodr
Starting Member

11 Posts

Posted - 2008-07-09 : 03:47:04

Hi all,

Making use of parameters, how do I pass parameter to choose the columns/fields of a table.
I know parameters are used in WHERE clauses to filter data but can parameters be used to choose the Column of a table ie. in a SELECT clause

(The sql statement below does not work, as I have found out)
SELECT @Column
FROM For_Sale

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-09 : 03:57:52
You need to use dynamic sql or write a series of CASE conditions to achieve this.

either

SET @Sql='SELECT '+ @Column + ' FROM For_Sale'
EXEC(@Sql)


or


SELECT CASE @Column
WHEN 'Col1' THEN Col1
WHEN 'Col2' THEN Col2
...
END
FROM For_Sale
Go to Top of Page
   

- Advertisement -