Just to give an idea ..you may have to do this way....(I've not put the syntax)
Declare @SQL varchar(8000)
select @sql = 'SELECT '
declare cursor ...select fieldcol from fieldtable
--for each row in cursor loop through and add it to the select
select @sql = @sql + @fieldcol + ','
--until the end of loop
select @sql = @sql + @FromClause
select @sql = @sql + @whereclause
Select @sql = @sql + @orderbyclause
exec(@sql)
Main Topics
Browse All Topics





by: aneeshattingalPosted on 2006-05-31 at 22:57:21ID: 16805047
declare @fields table (FiledName varchar(255))
)+FiledNam e
INSERT INTO @fields SELECT 'ID'
INSERT INTO @fields SELECT 'NAME'
declare @op nvarchar(1000)
SELECT @op = COALESCE(LTRIM(@Op)+',',''
FROM @fields
EXEC('SELECT '+@op+ ' FROM sysobjects ')