I have some problems/questions with the usage of [
,]
and '
in table names.
For example why this working
SELECT TOP 1000 [O'test]
,[NumeNOU]
FROM [dbname].[dbo].[O'conor]
and this not
use dbname
GO
DECLARE @COUNT int
SELECT @COUNT = Count(*) FROM dbname.INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = [dbname].[dbo].[O'conor]
PRINT @COUNT
with the error
Msg 4104, Level 16, State 1, Line 4 The multi-part identifier "dbname.dbo.O'conor" could not be bound.
or this
use dbname
GO
DECLARE @COUNT int
SELECT @COUNT = Count(*) FROM dbname.INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = [O'conor]
PRINT @COUNT
with the error
Msg 207, Level 16, State 1, Line 4 Invalid column name 'O''conor'.
but is working like this
use dbname
GO
DECLARE @COUNT int
SELECT @COUNT = Count(*) FROM dbname.INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'O''conor'
PRINT @COUNT