Monday, September 21, 2009

How To use Table Type In SQL Server 2008

Here I give the T-SQL Statement for Table Datatype in SQL server 2008.

Use Below script you can create PeepsType as table and you can use it in anywhere in Storedprocedure, views and tables ,here i give sasmple procedure using table type

CREATE TYPE PeepsType AS TABLE (Name varchar(20), Age int)

DECLARE @myPeeps PeepsType

INSERT @myPeeps SELECT 'murphy', 35

INSERT @myPeeps SELECT 'galen', 31

INSERT @myPeeps SELECT 'samuels', 27

INSERT @myPeeps SELECT 'colton', 42

exec sp_MySproc2 @myPeeps

CREATE PROCEDURE sp_MySproc2(@myPeeps PeepsType READONLY)
as
begin

select * from @myPeeps

end

No comments:

Post a Comment