如何添加两个select语句导致SQL Server存储过程?

时间:2014-04-02 16:24:05

标签: sql-server c#-4.0 stored-procedures

我有3张桌子

表1:Samplemaster

Acc_No | Address | ...

表2:Water

Serial | H2O | Cacho | ...

表3:Master

Type        | Column_Name |  Deliver 
-------------------------------------
Samplemaster| Acc_No      |   Yes 
Samplemaster| Address     |   Yes
Water       | Serial      |   Yes
Water       | H2O         |   Yes
Water       | Cacho       |   No

现在我要做的是编写一个存储过程来根据查询组合这些值我必须形成输出

首先,我必须添加表2 - 串行列,然后我必须添加samplemaster列 在此之前我必须检查主表中的交付列是否设置为是,如果是,那么我必须在结果查询中添加...,

输出:

Serial,Acc_No,Address,H20

代码:

CREATE PROCEDURE usp_TableSchema
   (@SampleType  varchar(50))
AS
BEGIN
   Declare @sampletypes varchar(max)
   Declare @samplemaster varchar(max)
   Declare @Count int

   select @samplemaster = a.Column_Name 
   from Master a 
   inner Join information_schema.columns c on c.column_name = a.Column_Name 
   Where 
       c.TABLE_NAME = 'samplemaster'
       and a.TableType = 'samplemaster'
       and a.Deliver = 'Yes'

   select @sampletypes = a.Column_Name 
   from Master a 
   Inner Join information_schema.columns c on c.column_name = a.Column_Name 
   Where 
       c.TABLE_NAME = @SampleType 
       and a.TableType = @SampleType 
       and a.Deliver = 'Yes'
    END
    GO

我不知道如何在存储过程中组合两个查询的值。,..请帮助我这个

0 个答案:

没有答案