Results 1 to 4 of 4
  1. #1
    Join Date
    May 2008
    Posts
    97

    Unanswered: Variable Assignment

    Hi, any help would be greatly appreciated.

    In my stored procedure I would like to make an assignment to a variable (called AVGPrice). Is this possible?
    Code:
    Alter PROCEDURE sp_GetPartNosForVendorPart
       @InVendPartNo  varchar(30),
       @InVendPartPrice real,
       @Category varchar(10),
       @AVGPrice real
    AS
    
    @AVGPrice = SELECT Round(avg(TNPriceBid), 2) FROM TNPriceLine where TNVendPart = @InVendPartNo group by TNVENDPART;
    
    /* use  our @AVGPrice for something else */
    INSERT INTO BookKeeping
    VALUES (1, @AVGPrice)

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    Code:
    Alter PROCEDURE sp_GetPartNosForVendorPart
       @InVendPartNo  varchar(30),
       @InVendPartPrice real,
       @Category varchar(10),
       @AVGPrice real
    AS
    
    SELECT @AVGPrice = Round(avg(TNPriceBid), 2) FROM TNPriceLine where TNVendPart = @InVendPartNo group by TNVENDPART;
    
    /* use  our @AVGPrice for something else */
    INSERT INTO BookKeeping
    VALUES (1, @AVGPrice)
    Yep.

  3. #3
    Join Date
    May 2008
    Posts
    97
    Is this bad practice? Or would it be better to use a nested Select statement?

  4. #4
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    It is not a bad practice, unless it is abused, but then, so isn't everything. Just be careful if your select statement returns more than one row.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •