Example of calling stored procedure in TSQL

Source: Internet
Author: User

------------------------------------
-- Author: Flystone
-- Version: V1.001
-- Date: 2008-08-01 12:39:33
------------------------------------

-- Test Data: ta
If object_id ('ta ') is not null
Drop table ta
Go
Create table ta (bno int, bname nvarchar (5), editor nvarchar (5), bpub nvarchar (7), bdate numeric (5, 1 ))
Go
Insert into ta
Select 1, 'database methods', 'wang ', 'gaojiao', 2006.9 union all
Select 2, 'information system', 'Liu ', 'kexue', 2006.8 union all
Select 3, 'database instance', 'wang ', 'gaojiao', 2006.9 union all
Select 4, 'database exercise ', 'zhang', 'jixie ', 2005.4
Go

-- Create proc
Create proc proc_a
@ Bno int
As
Select * from ta where bno <= @ bno
Go

-- Start
Select *
From OPENROWSET ('sqloledb', 'server =.; UID = sa; PWD = ', 'exec csdn_test.dbo.proc_a 2') AS
Select *
From OPENROWSET ('sqloledb', '.'; 'sa '; '', 'exec csdn_test.dbo.proc_a 2') AS

Select *
From OPENROWSET ('sqloledb', 'driver = {SQL Server}; SERVER =.; UID = sa; PWD = ', 'exec csdn_test.dbo.proc_a 2') AS

 

-- Drop proc
Drop proc proc_a

 

-- Result:

/*
Bno bname editor bpub bdate
--------------------------------------------------------------------------------------------
1. Database principle: wang gaojiao 2006.9
2. Information System liu kexue 2006.8

(The number of affected rows is 2)
Bno bname editor bpub bdate
--------------------------------------------------------------------------------------------
1. Database principle: wang gaojiao 2006.9
2. Information System liu kexue 2006.8

(The number of affected rows is 2)
Bno bname editor bpub bdate
--------------------------------------------------------------------------------------------
1. Database principle: wang gaojiao 2006.9
2. Information System liu kexue 2006.8

(The number of affected rows is 2)
*/
-- END

This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/happyflystone/archive/2008/08/01/2752936.aspx

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.