sql SQL Update命令。包括SQL代码,用于根据两个表匹配的另一个表的值更新表。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql SQL Update命令。包括SQL代码,用于根据两个表匹配的另一个表的值更新表。相关的知识,希望对你有一定的参考价值。

UPDATE OPTIMUM_REBATE
SET RetailTarget = 930330.73,
ElectronicsTarget = 178446.89
WHERE CUST_ID = 1359709
UPDATE OPTIMUM_REBATE
SET	Platinum = (
	CASE
		WHEN ot1.Program = 'PLAT' THEN 1
		ELSE NULL
	END),
	Ambassador = (
	CASE
		WHEN ot1.Program = 'AMB' THEN 1
		ELSE NULL
	END)
FROM OPTIMUM_REBATE or1, (SELECT
	lcc.CUST_ACCOUNT_ID,
	ot.Program
FROM OptimumRebateTemp2 ot
LEFT OUTER JOIN LU_CUSTOMER lcc
	ON lcc.CUSTOMER_NAME = ot.CUSTOMER_NAME) ot1
WHERE or1.CUST_ID = ot1.CUST_ACCOUNT_ID
UPDATE DimTransactionByMonth SET MonthDay =( 
CASE DimTransactionByMonth.Month
    	WHEN 'December' THEN CAST(DimTransactionByMonth.Year + '-12-01' AS DATETIME2)
    	WHEN 'January' THEN CAST(DimTransactionByMonth.Year + '-01-01'  AS DATETIME2) 
		WHEN 'February' THEN CAST(DimTransactionByMonth.Year + '-02-01' AS DATETIME2)
		WHEN 'Feuary' THEN CAST(DimTransactionByMonth.Year + '-02-01' AS DATETIME2)
		WHEN 'March' THEN CAST(DimTransactionByMonth.Year + '-03-01' AS DATETIME2)
		WHEN 'April' THEN CAST(DimTransactionByMonth.Year + '-04-01' AS DATETIME2)
		WHEN 'May' THEN CAST(DimTransactionByMonth.Year + '-05-01' AS DATETIME2)
		WHEN 'June' THEN CAST(DimTransactionByMonth.Year + '-06-01' AS DATETIME2)
		WHEN 'July' THEN CAST(DimTransactionByMonth.Year + '-07-01' AS DATETIME2)
		WHEN 'August' THEN CAST(DimTransactionByMonth.Year + '-08-01' AS DATETIME2)
		WHEN 'September' THEN CAST(DimTransactionByMonth.Year + '-09-01' AS DATETIME2)
		WHEN 'October' THEN CAST(DimTransactionByMonth.Year + '-10-01' AS DATETIME2)
		WHEN 'November' THEN CAST(DimTransactionByMonth.Year + '-11-01' AS DATETIME2)
    	 --ELSE
    END)
UPDATE OPTIMUM_REBATE
SET RetailTarget = ot1.Retail, ElectronicsTarget = ot1.FMS
FROM
OPTIMUM_REBATE or1
,(
SELECT lcc.CUST_ACCOUNT_ID, ot.Retail,ot.FMS FROM OptimumRebateTemp2 ot
LEFT OUTER JOIN LU_CUSTOMER lcc
ON lcc.CUSTOMER_NAME = ot.Customer_name) ot1
WHERE or1.CUST_ID = ot1.CUST_ACCOUNT_ID
UPDATE Optimum_Rebate_Periods
SET PeriodStart = '4.1.2014',
PeriodEnd = '4.1.2015'
WHERE ID = 2
UPDATE or1
SET or1.RetailTarget = ot.[2015 Retail Base Target],
or1.ElectronicsTarget = ot.[2015 FMS Base Target]
from
OPTIMUM_REBATE or1
inner JOIN
OptimumTemp ot
ON
ot.CUSTOMER_NAME = or1.CUSTOMER_NAME

以上是关于sql SQL Update命令。包括SQL代码,用于根据两个表匹配的另一个表的值更新表。的主要内容,如果未能解决你的问题,请参考以下文章

来自 UPDATE 查询的“SQL 命令未正确结束”错误 [重复]

通过正则表达式判断 SQL 命令是不是为 UPDATE 命令

经典MSSQL语句大全和常用SQL语句命令的作用

ORA-00933: UPDATE 命令的 SQL 命令未正确结束 [关闭]

SQL 命名法:INSERT/UPDATE/DELETE 的“查询”或“命令”?

如何使用 sysdate 更新日期列,包括动态 sql 中的时间戳