I had a alter table that used to work and now its not and I dont know why when I run the below I get Invalid column name 'Q'. Many thanks if anyone can work this out
Alter Table [all] Add [Q] varchar(1)
Update dbo.[all] Set Q = '1' Where [IncpDt] between '2010-01-01' and '2010-03-31'
asked May 24 '12 at 01:42 PM in Default
Add the batch separator GO to the code
answered May 24 '12 at 01:45 PM
Kev Riley ♦♦
I see that Kev answered the question with a GO between the statements. But my first remark still applies
First of all I must point out that you should never use varchar(1) as a data type for a column. varchar means that the column is of variable length. If the field is 0 or 1 character long, you should use the char(1) data type. Using a variable length data type uses up extra space.
Second: It's not clear in your question if it is the ALTER TABLE statement that's causing the error or if it's the UPDATE statement.
If it's the later - the UPDATE statement - , it's probably because you haven't schema qualified the table name in your ALTER TABLE statement, and you might have another default schema than 'dbo'. Check in sys.tables if you have more than one table named 'all'.
If it's the former - ALTER TABLE statement causes the error - I can't really see anything wrong with it, except I think you should make it a habit to always schema qualify your table names, and you should avoid varchar(1).