Blog Pages

Error when create new column and run some things on it

if not exists (select * from sys.columns where object_id = object_id('dbo.MyTable') and name = 'NewColumn')
begin
                alter table Customer.Configuration add NewColumn int null
end
do something with the new column - update, alter, etc.
--> Error message:
Msg 207, Level 16, State 1, Server <MyServer>, Line 17 Invalid column name 'NewColumn'.

Solution:
Close the batch pf the creation by adding 'GO' between the column creatuion and usage.

 if not exists (select * from sys.columns where object_id = object_id('dbo.MyTable') and name = 'NewColumn')
begin
                alter table Customer.Configuration add NewColumn int null
end
GO
do something with the new column - update, alter, etc.

Check the SQL server port number

In order to check the SQL server port number,
open:
Start button (windows) --> Go to All Programs --> Microsoft SQL Server 20XX --> Configuration Tools --> SQL Server Configuration Manager
And there: 
SQL Native Client 10.0 Configuration --> Client Protocols --> TCP/IP Properties (double click or Right click)
There you will see the default port number.