General information
Forum:
Microsoft SQL Server
Roy,
You could try something like this
DECLARE @ColumnList AS VARCHAR(8000)
SELECT @ColumnList = CASE WHEN @ColumnList IS NULL THEN COLUMN_NAME ELSE @ColumnList + ',' + COLUMN_NAME END
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'MyTableName'
AND COLUMN_NAME NOT IN( 'MyColumnName1', 'MyColumnName2' )
EXECUTE ( 'SELECT ' + @ColumnList + ' FROM Plan_' )
Cheers,
Zoran
>Hi,
>
>I need to select all columns on a table except one. Right now I have to type a lot of columns in the query to accomplish this. Would be nice something like "Select * except cRegion FROM Countries", is there a way to do this in SQL Server?
>
>Thanks.
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only