Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL to update a column using another column

Status
Not open for further replies.

sqlbee

Programmer
Jan 19, 2006
1
US
I need the logic/ansi sql to update a column, LP_Qty in my table using another col in the same table this is RF_Qty. RF_Qty gets updated everyday as the table refreshes everyday. But LP_Qty should be equal to RF_Qty only when it is FisPeriodEnd_Dt, else it should retain it's previous value till it is FisPeriodEnd_Dt.

My target table has the following Cols

Item_Id
FiscalPeriod_Id (MonthLevel)
RF_Qty,
LP_Qty

there is another table called Fiscal_Period that has
FiscalPeriod_Id (MonthLevel)
FiscalPeriodEnd_Dt (A date)

We also have current_date to use as this is not for history



how do I populate the target table?

thanks in advance




 
Code:
DECLARE @Date1 DATETIME
SET @Date1 = FisPeriodEnd_Dt

UPDATE targettable SET LP_Qty = RF_Qty
WHERE @Date1 = GetDate()

BlueCJH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top