0

如何创建返回此 SELECT 语句的(表格)结果的 T-SQL 存储过程:

USE automation

SELECT insurer.name,
insurer.case_name,
contact.name,
contact_address.line_1,
contact_address.city,
state.state_abbr,
contact_address.zip

FROM person as insurer

INNER JOIN persons_relationship on persons_relationship.person2_id = insurer.person_id
INNER JOIN person contact on contact.person_id = persons_relationship.person_id
INNER JOIN person_address contact_person_address on contact_person_address.person_id = contact.person_id
INNER JOIN address contact_address on contact_address.address_id = contact_person_address.address_id
INNER JOIN state on state.state_id = contact_address.state_id

insurer.person_class_id = 2
4

3 回答 3

1

做这样的事情:

USE Automation
GO

CREATE PROCEDURE dbo.YourProcedureNameHere
AS
   SELECT 
       insurer.name,
       insurer.case_name,
       contact.name,
       contact_address.line_1,
       contact_address.city,
       state.state_abbr,
       contact_address.zip
   FROM 
       person as insurer
   INNER JOIN 
       persons_relationship on persons_relationship.person2_id = insurer.person_id
   INNER JOIN 
       person contact on contact.person_id = persons_relationship.person_id
   INNER JOIN 
       person_address contact_person_address on contact_person_address.person_id = contact.person_id
   INNER JOIN 
       address contact_address on contact_address.address_id = contact_person_address.address_id
   INNER JOIN 
       state on state.state_id = contact_address.state_id

你就完成了。现在您可以将您的声明称为:

EXEC sp_executesql N'dbo.YourProcedureNameHere'  
于 2013-02-12T05:58:07.970 回答
0

我建议你也放

SET NOCOUNT ON 

直接在AS之后。一些数据访问库对x 记录受影响的消息感到困惑,这会将其关闭。

于 2013-02-12T06:02:36.033 回答
-1

put this query in the stored procedure and when you will run this stored procedure you will get tabular result

于 2013-02-12T03:23:01.863 回答