x

LOCAL VARIABLES

How do I assign the selected UNIT_PRICE AS OLD_UNITPRICE to the local variable?

 DECLARE @OLD_UNITPRICE decimal;
 
 
     SELECT TOP 1 Q.ID AS QUOTE_ID 
           ,Q.QUOTE_DATE AS QUOTE_DATE 
           ,QL.LINE_NO AS QUOTE_LINE_NO 
           ,QP.QTY AS QUOTE_QTY 
           ,QP.UNIT_PRICE AS OLD_UNITPRICE 
     FROM    TIC.dbo.QUOTE_LINE QL 
     LEFT JOIN IC.dbo.QUOTE_PRICE QP 
            ON QL.QUOTE_ID = QP.QUOTE_ID 
          AND QL.LINE_NO = QP.QUOTE_LINE_NO 
     LEFT JOIN TIC.dbo.QUOTE Q 
            ON QL.QUOTE_ID = Q.ID 
     WHERE QL.PART_ID = @ticPartID 
       AND LEFT(QL.QUOTE_ID,1) = 'E'  
     ORDER BY Q.QUOTE_DATE DESC 
more ▼

asked Aug 14, 2012 at 01:30 AM in Default

avatar image

technette
1.4k 100 113 120

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

Try encapsulating just the result that you want when assigning, like the following

 DECLARE @OLD_UNITPRICE decimal;
 
 
 SELECT @OLD_UNITPRICE =   (
  SELECT TOP 1 QP.UNIT_PRICE 
  FROM    TIC.dbo.QUOTE_LINE QL 
  LEFT JOIN IC.dbo.QUOTE_PRICE QP 
     ON QL.QUOTE_ID = QP.QUOTE_ID 
  AND QL.LINE_NO = QP.QUOTE_LINE_NO 
  LEFT JOIN TIC.dbo.QUOTE Q 
     ON QL.QUOTE_ID = Q.ID 
  WHERE QL.PART_ID = @ticPartID 
    AND LEFT(QL.QUOTE_ID,1) = 'E'  
  ORDER BY Q.QUOTE_DATE DESC 
  )
more ▼

answered Aug 14, 2012 at 03:37 AM

avatar image

SirSQL
4.9k 4 5

Thank you for responding SirSQL.

I was hoping to multiply @OLD_UNITPRICE * @QTY

@QTY is a variable that is part of a cursor.

Is this posible with encapsulation?

Aug 14, 2012 at 05:45 AM technette

Just add a second statement, SET @OLD_UNITPRICE = @OLD_UNITPRICE * @QTY;

Aug 14, 2012 at 10:34 AM Grant Fritchey ♦♦
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1

asked: Aug 14, 2012 at 01:30 AM

Seen: 544 times

Last Updated: Aug 14, 2012 at 10:34 AM

Copyright 2016 Redgate Software. Privacy Policy