Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select all columns minus x
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00817539
Message ID:
00817659
Views:
15
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
Map
View

Click here to load this message in the networking platform