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.
| Author |
Topic |
|
shahabfarooqui
Starting Member
1 Post |
Posted - 2004-02-23 : 19:50:31
|
| Greetings All Just wondering what would be the best approach to rertrieve values from a table which can have unlimited number fields.SCENARIO:=========I have a excel spreadsheet which gets updated and then exported to sql DTS, so the first (7) fields remain the same always but remaining fileds might be dynamic. I need to get the values of fileds other than first 7 fields.I have attemted to do this way :============================================================set nocount onDeclare @TableName varchar(128), @ColumnList varchar(1000)Declare @SQL varchar(1000)set @TableName = 'developers'SELECT @ColumnList = COALESCE(@ColumnList + ', ', '') + column_name FROM INFORMATION_SCHEMA.ColumnsWHERE Ordinal_position >= 3and table_name = @TableNameSet @SQL = 'Select ' + @ColumnList + ' from ' + @TableName + ' WHERE DeveloperID = 1'Exec (@SQL)============================================================It works fine but as sson as I change the search criteria for example anything other then developer ID it just comes up with error saying the column _name does not exist.any advice would be most appreciated.regards |
|
|
|
|
|