Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Column, parameter, or variable #2: Cannot find data type test_type.

$
0
0

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 DB1
SELECT 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


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>