SQL Server 2008 Table-Valued parameter usage

Source: Internet
Author: User

The following example uses Transact-SQL and demonstrates how to create a table-valued parameter type, declare a variable to reference it, populate the parameter list, and then pass the value to the stored procedure.

1  UseAdventureWorks;2 GO3 4 /*creating table-valued parameter types*/5 CREATETYPE Locationtabletype as TABLE 6(LocationNameVARCHAR( -)7, CostrateINT );8 GO9 Ten /*Create a procedure to get the table-valued parameter data*/ One CREATE PROCEDUREusp_insertproductionlocation A     @TVPLocationtabletype READONLY -   as  -     SETNOCOUNT on the     INSERT  into [AdventureWorks].[Production].[ Location] -([Name] -,[costrate] -,[Availability] +,[ModifiedDate]) -         SELECT *,0,GETDATE() +          from  @TVP; A  GO at  - /*declare a variable to reference the type*/ - DECLARE @LocationTVP  -  asLocationtabletype; -  - /*ADD data to the table variable.*/ in INSERT  into @LocationTVP(LocationName, costrate) -     SELECT [Name],0.00 to      from  +     [AdventureWorks].[ Person].[StateProvince]; -  the /*passing data from a table variable to a stored procedure*/ * EXECUsp_insertproductionlocation@LocationTVP; $ GO

SQL Server 2008 Table-Valued parameter usage

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.