Well I would use dynamic sql to build it up(your question asks 'sql query' so i am staying away from code here), with a stored proc in your crystal report, that takes the parameters as columns EG:
Create proc myprocname
(
@columns varchar(400),
@table varchar(50)
)
AS
Declare @sql varchar(500)
Set @sql = 'SELECT ' + @columns + ' FROM ' + @table
EXEC @sql
(you will need to modify this thinking to suit your needs)
some extra reading here:
http://msdn.microsoft.com/en-us/library/ms188001.asp[
^]