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

technette gravatar image

technette
1.2k 81 97 107

(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

SirSQL gravatar image

SirSQL
4.8k 1 3

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.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

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: 434 times

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