snippetMinor
Operand type clash: my first User Defined Type with list of Integers, how to test via SSMS
Viewed 0 times
ssmswithusertypeclashoperandfirsttesthowvia
Problem
I found this wonderful code here
but I dont know how to test it via SSMS please
gives the error:
How can I test the list '1,2,3,4,5' please
CREATE TYPE [dbo].[StringList] AS TABLE(
[Item] [NVARCHAR](MAX) NULL
);
GO
CREATE PROCEDURE [dbo].[sp_UseStringList]
@list StringList READONLY
AS
BEGIN
-- Just return the items we passed in
SELECT l.Item FROM @list l;
END
GObut I dont know how to test it via SSMS please
declare @list StringList = '1,2,3,4,5'
exec sp_UseStringList @listgives the error:
Operand type clash: varchar is incompatible with StringListHow can I test the list '1,2,3,4,5' please
Solution
As you have declared
So instead of assigning
There's a pretty decent example in BOL, but I'll create one based on your example above.
dbo.StringList to be a User-Defined Table Type, you have to utilise it as you would a table.So instead of assigning
'1,2,3,4,5' as a string, you must INSERT this value into the table.There's a pretty decent example in BOL, but I'll create one based on your example above.
CREATE TYPE [dbo].[StringList] AS TABLE(
[Item] [NVARCHAR](MAX) NULL
);
GO
CREATE PROCEDURE [dbo].[sp_UseStringList]
@list StringList READONLY
AS
BEGIN
-- Just return the items we passed in
SELECT l.Item FROM @list l;
END
GO
DECLARE @StringList StringList
INSERT Into @StringList values('1'),('2'),('3'),('4'),('5')
EXEC sp_UseStringList @StringListCode Snippets
CREATE TYPE [dbo].[StringList] AS TABLE(
[Item] [NVARCHAR](MAX) NULL
);
GO
CREATE PROCEDURE [dbo].[sp_UseStringList]
@list StringList READONLY
AS
BEGIN
-- Just return the items we passed in
SELECT l.Item FROM @list l;
END
GO
DECLARE @StringList StringList
INSERT Into @StringList values('1'),('2'),('3'),('4'),('5')
EXEC sp_UseStringList @StringListContext
StackExchange Database Administrators Q#75770, answer score: 8
Revisions (0)
No revisions yet.