Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Operand type clash: nvarchar is incompatible with Type_WP_Days

I Did some simple steps in my database

Step 1:

CREATE TYPE [dbo].[TempType] AS TABLE([MM] [INT])

Step 2:

CREATE PROC [DBO].[TEMP1] (@MYTAB TEMPTYPE READONLY)  
AS
BEGIN
    SELECT * 
    FROM @MYTAB
END

Step 3:

CREATE TABLE #TEMP11 ([MM] [INT])

INSERT INTO #TEMP11 
   SELECT 1 UNION 
   SELECT 2 UNION 
   SELECT 3 

SELECT * FROM #TEMP11

EXEC TEMP1 #TEMP11

Result:

(4 row(s) affected) 
(4 row(s) affected) 

Msg 206, Level 16, State 2, Procedure temp1, Line 0
Operand type clash: nvarchar is incompatible with TempType

I did it on two more servers it gave same message. What is the fault in my code. I used SQL Server 2008 R2 and SQL Server 2014 also.

like image 721
Sanjay Avatar asked Jul 30 '15 06:07

Sanjay


1 Answers

Instead of creating a temporary table, create a variable of type TempType:

DECLARE  @Temp11 TempType 

INSERT INTO @Temp11 SELECT 1 UNION SELECT 2 UNION SELECT 3 
SELECT * FROM @Temp11

EXEC TEMP1  @Temp11

Your procedure is not accepting a temporary table as input parameter but parameter of type TempType.

like image 142
gotqn Avatar answered Oct 01 '22 04:10

gotqn