Unable to get schema and create TableAdapter of a SQL Server stored procedure in Visual Studio

128 views Asked by At

I have following stored procedure. It generates ProductBalanceAndTurnover report for a period.

ALTER PROCEDURE [dbo].[ProductBalanceAndTurnover]
-- Add the parameters for the stored procedure here
@DateTime1 datetime,
@DateTime2 datetime
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here

DROP TABLE IF EXISTS #Balance1;
DROP TABLE IF EXISTS #Balance2;
DROP TABLE IF EXISTS #In;
DROP TABLE IF EXISTS #Out;
DROP TABLE IF EXISTS #Items;

SELECT
    Product, Price, SUM(Quantity * InOut) AS Balance1
INTO
    #Balance1
FROM
    Reg_Warehouse
WHERE
    ([DateTime] < @DateTime1)
GROUP BY
    Product, Price
HAVING
    (SUM(Quantity * InOut) <> 0);

SELECT
    Product, Price, SUM(Quantity * InOut) AS Balance2
INTO
    #Balance2
FROM
    Reg_Warehouse
WHERE
    ([DateTime] < @DateTime2)
GROUP BY
    Product, Price
HAVING
    (SUM(Quantity * InOut) <> 0);

SELECT
    Product, Price, SUM(Quantity) AS [In]
INTO
    #In
FROM
    Reg_Warehouse
WHERE
    ([DateTime] >= @DateTime1 AND [DateTime] < @DateTime2 AND InOut = 1)
GROUP BY
    Product, Price
HAVING
    (SUM(Quantity) <> 0);

SELECT
    Product, Price, SUM(Quantity) AS [Out]
INTO
    #Out
FROM
    Reg_Warehouse
WHERE
    ([DateTime] >= @DateTime1 AND [DateTime] < @DateTime2 AND InOut = -1)
GROUP BY
    Product, Price
HAVING
    (SUM(Quantity) <> 0);


SELECT
    Product,
    Price
INTO
    #Items
FROM
(
    SELECT
        Product,
        Price
    FROM
        #Balance1
    UNION ALL
    SELECT
        Product,
        Price
    FROM
        #Balance2
    UNION ALL
    SELECT
        Product,
        Price
    FROM
        #In
    UNION ALL
    SELECT
        Product,
        Price
    FROM
        #Out
)
AS m
GROUP BY
    m.Product,
    m.Price;

SELECT
    #Items.Product,
    dbo.GetProductLongName(#Items.Product) AS ProductLongName,
    Unit.FullName AS Unit,
    #Items.Price,
    #Balance1.Balance1,
    #Balance1.Balance1 * #Items.Price AS Balance1V,
    #In.[In] AS [In],
    #In.[In] * #Items.Price AS [InV],
    #Out.[Out] AS [Out],
    #Out.[Out] * #Items.Price AS [OutV],
    #Balance2.Balance2,
    #Balance2.Balance2 * #Items.Price AS Balance2V
FROM
    #Items
    LEFT OUTER JOIN #Balance1 ON #Balance1.Product = #Items.Product AND #Balance1.Price = #Items.Price
    LEFT OUTER JOIN #Balance2 ON #Balance2.Product = #Items.Product AND #Balance2.Price = #Items.Price
    LEFT OUTER JOIN #In ON #In.Product = #Items.Product AND #In.Price = #Items.Price
    LEFT OUTER JOIN #Out ON #Out.Product = #Items.Product AND #Out.Price = #Items.Price
    LEFT OUTER JOIN Product ON Product.Id = #Items.Product
    LEFT OUTER JOIN Unit ON Unit.Id = Product.Unit;


END

In my WinForms project in Visual Studio I can't create a TableAdapter for this stored procedure. Is there a solution for it?

Edit

enter image description here enter image description here enter image description here

0

There are 0 answers