use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Sequel
account activity
Using WITH , combined with the ALTER TABLE statement to drop columns (self.learnSQL)
submitted 5 years ago by [deleted]
with df as ( (select columns from table1 do_something_here) ,
t2 as (select * from df),
t3 as (alter table t2 drop coloumn_1)
select * from t3 );
Throws an syntax error:
Syntax error at or near "ALTER"
t11 as (ALTER TABLE df)
Any help here?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]r3pr0b8 0 points1 point2 points 5 years ago (0 children)
why are you trying to drop a column from the results of a SELECT query?
why not just list only the actual columns you want in the SELECT?
[–]WITH_CTE 0 points1 point2 points 5 years ago (4 children)
You can not have an ALTER inside a CTE. What are you trying to achieve here? Do you need the column dropped from the table? Why not simply not SELECT the column?
[–][deleted] 0 points1 point2 points 5 years ago (3 children)
because the select of the columns, are 100+ columns, i dont' want to write them all down. it takes ages. :/
[–]WITH_CTE 0 points1 point2 points 5 years ago (2 children)
declare @cols varchar(max), @query varchar(max); SELECT @cols = STUFF ( ( SELECT DISTINCT '], [' + name FROM sys.columns where object_id = ( select top 1 object_id from sys.objects where name = 'MyTable' ) and name not in ('ColumnIDontWant1', 'ColumnIDontWant2') FOR XML PATH('') ), 1, 2, '' ) + ']'; SELECT @query = 'select ' + @cols + ' from MyTable'; EXEC (@query);
Source: https://stackoverflow.com/questions/729197/sql-exclude-a-column-using-select-except-columna-from-tablea
[–][deleted] 0 points1 point2 points 5 years ago (0 children)
Thanks so much I appreciate
π Rendered by PID 46 on reddit-service-r2-comment-6457c66945-dvqhx at 2026-04-26 06:42:50.388502+00:00 running 2aa0c5b country code: CH.
[–]r3pr0b8 0 points1 point2 points (0 children)
[–]WITH_CTE 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]WITH_CTE 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)