stored procedure pass value in the parameters

  • Hi,

    The stored procedure below wanted to spend the parameters of the select. At this time only me is the stored procedure is to return only the first line of select, but I wanted the other as well.

    DECLARE @sku varchar(30), @Price Money,@Discount real

    SELECT @sku=sku,@Price=Price, @discount=Discount

    FROM tbProducts

    WHERE sku in ('XPTO','XPTO1')

    exec spPriceHistoric @sku,@Price,@Discount

    Thanks

  • I don't understand the request, can you be clearer please?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Hi,

    I want the stored procedure receives a loop in the query

    Thanks

  • A stored procedure can't "receive" a loop. It can loop, but it many cases it isn't necessary. Perhaps you could explain what it is that you're trying to do.

  • I believe the request is to split the @sku into a table , via dbo.DelimitedSplit8K for example:

    right now he's passing a string that happens to have a comma in it.

    WHERE sku in ('XPTO','XPTO1')

    your procedure spPriceHistoric must use the splitter function to convert your string into a table of strings.

    SELECT sku,Price, Discount

    FROM tbProducts

    WHERE sku in (SELECT Item FROM dbo.DelimitedSplit8K(@sku,',') )

    the example i mentionsed here is found in this article:

    http://www.sqlservercentral.com/articles/Tally+Table/72993/

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Lowell (3/15/2016)


    I believe the request is to split the @sku into a table , via dbo.DelimitedSplit8K for example:

    right now he's passing a string that happens to have a comma in it.

    WHERE sku in ('XPTO','XPTO1')

    your procedure spPriceHistoric must use the splitter function to convert your string into a table of strings.

    SELECT sku,Price, Discount

    FROM tbProducts

    WHERE sku in (SELECT Item FROM dbo.DelimitedSplit8K(@sku,',') )

    the example i mentionsed here is found in this article:

    http://www.sqlservercentral.com/articles/Tally+Table/72993/

    That might very well be it, but I'll admit I wouldn't have gotten that from the OP. I think it's time for amadeu to weigh in and clarify the question.

  • I have a table with the following product sku fields, price and discount, and wanted to create a historical table of the products that whenever alter prices or discount reflects the history table.

    The stored procedure analyze the historical table and if there is a change in price or discount, updates the table.

    They were able to see what I want?

  • Hi,

    The stored procedure below will select price changes due for example to a promotion, through the function.

    The stored procedure works only if only for a record, whenever I run spPriceH runs only once, when you should take the number of rows that the function has!

    How do I solve?

    Alter PROCEDURE [dbo].[spPriceH]

    AS

    declare @brandID smallint @sku nvarchar(18), @Price Money,@Discount real

    select @sku=sku,@Price=Price,@Discount=Discount,@brandID=brandID

    from [fnExpsku1](0)

    beginTRY

    DECLARE

    @brandIDT smallint, @skuT nvarchar(18), @PriceT Money,@DiscountT real, @statusT CHAR(1), @DateUpdateT SMALLDATETIME

    SELECT @brandT=@brandID, @skuT=sku, @PriceT=Price, @DiscountT=Discount, @StatusT=Status, @DateUpdateT=DateUpdate

    FROM PriceUpdateSku

    WHERE brandID=@brandID and sku=@sku

    IF @skuT IS NULL

    INSERT INTO PriceUpdateSku (BrandID,sku,Price,Deiscount,Status,DateUpdate)

    VALUES (@BrandID, @Sku, @Price,@Discount, 'S', GETDATE())

    BEGIN

    IF @BrandIDT<>@BrandID or @skuT<>@sku or @PriceT<>@Price or @DiscountT<>@Discount

    UPDATE PriceUpdateSku set Price=@Price, Discount=@Discount, Status='S', DateUpdate=GETDATE()

    WHERE brandID=@brandID and Sku=@Sku

    ELSE

    update PriceUpdateSku set Status='S' where brandID=@brandID and Sku=@Sku

    END

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply