Hello,
On SQL Server 2008R2 I receive this error when running the following code:
USE [DB1]
GO
IF NOT EXISTS (SELECT 1 FROM sys.types WHERE name = 'test_context_switch1')
CREATE TYPE [test_context_switch1] AS TABLE ([name] [sysname] NOT NULL)
GO
USE [DB2]
GO
IF NOT EXISTS (SELECT 1 FROM sys.types WHERE name = 'test_context_switch2')
CREATE TYPE [test_context_switch2] AS TABLE ([name] [sysname] NOT NULL)
GO
USE DB1
DECLARE @test1 test_context_switch1
USE DB2
DECLARE @test2 test_context_switch2
GO
If I put a GO before USE DB2, it works. If I comment the first DECLARE, it works. The following code also returns the correct results for each database:
USE DB1SELECT name FROM sys.types WHERE is_user_defined = 1
USE DB2
SELECT name FROM sys.types WHERE is_user_defined = 1
Any idea?
Thanks,
Andrei