[英]Temporary table subsitute in sql server
伙計們,這是我的臨時表代碼
SELECT
cosd.erscommoditydataseries.erscommodity_id AS
datatobeupdated,ERSBusinessLogic_ID
INTO temptable1
FROM cosd.erscommoditydataseries INNER JOIN cosd.ersconstructedvariablesoutcomes
ON
SUBSTRING(
cosd.erscommoditydataseries.erscommodity_sourceseriesid,
CHARINDEX('(', cosd.erscommoditydataseries.erscommodity_sourceseriesid)
+ 1,
CHARINDEX(')',
cosd.erscommoditydataseries.erscommodity_sourceseriesid)
-
CHARINDEX('(',
cosd.erscommoditydataseries.erscommodity_sourceseriesid) - 1) =
SUBSTRING(
cosd.ersconstructedvariablesoutcomes.ersconstructedvariable_outputdestination,
CHARINDEX('(', cosd.ersconstructedvariablesoutcomes.ersconstructedvariable_outputdestination)
+ 1, CHARINDEX(')',
cosd.ersconstructedvariablesoutcomes.ersconstructedvariable_outputdestination) -
CHARINDEX('(',
cosd.ersconstructedvariablesoutcomes.ersconstructedvariable_outputdestination)
- 1)
INNER JOIN cosd.ERSBusinessLogic
ON
cosd.ERSBusinessLogic.ERSBusinessLogic_ID=ERSConstructedVariable_BusinessLogicID
where erscommodity_sourceseriesid LIKE '%(N%'
AND cosd.ersconstructedvariablesoutcomes.ersconstructedvariable_outputdestination
LIKE '%CV(N%'
AND cosd.ersconstructedvariablesoutcomes.ersconstructedvariable_newdataseriesid
IS
NULL
update cosd.ERSConstructedVariablesOutcomes set ERSConstructedVariable_NewDataSeriesID=_dummy.datatobeupdated
from cosd.ERSConstructedVariablesOutcomes dummy JOIN temptable1 _dummy
on dummy.ERSConstructedVariable_BusinessLogicID= _dummy.ERSBusinessLogic_ID
但是我嘗試執行兩次,當然它說temptable1已經存在,但是還有其他方法可以執行此代碼。 我希望將選擇查詢的輸出更新到更新表中給出的表中
不要使用臨時表(或本地表):
;WITH _dummy as (
SELECT
cosd.erscommoditydataseries.erscommodity_id AS
datatobeupdated,ERSBusinessLogic_ID
FROM cosd.erscommoditydataseries INNER JOIN cosd.ersconstructedvariablesoutcomes
ON
SUBSTRING(
cosd.erscommoditydataseries.erscommodity_sourceseriesid,
CHARINDEX('(', cosd.erscommoditydataseries.erscommodity_sourceseriesid)
+ 1,
CHARINDEX(')',
cosd.erscommoditydataseries.erscommodity_sourceseriesid)
-
CHARINDEX('(',
cosd.erscommoditydataseries.erscommodity_sourceseriesid) - 1) =
SUBSTRING(
cosd.ersconstructedvariablesoutcomes.ersconstructedvariable_outputdestination,
CHARINDEX('(', cosd.ersconstructedvariablesoutcomes.ersconstructedvariable_outputdestination)
+ 1, CHARINDEX(')',
cosd.ersconstructedvariablesoutcomes.ersconstructedvariable_outputdestination) -
CHARINDEX('(',
cosd.ersconstructedvariablesoutcomes.ersconstructedvariable_outputdestination)
- 1)
INNER JOIN cosd.ERSBusinessLogic
ON
cosd.ERSBusinessLogic.ERSBusinessLogic_ID=ERSConstructedVariable_BusinessLogicID
where erscommodity_sourceseriesid LIKE '%(N%'
AND cosd.ersconstructedvariablesoutcomes.ersconstructedvariable_outputdestination
LIKE '%CV(N%'
AND cosd.ersconstructedvariablesoutcomes.ersconstructedvariable_newdataseriesid
IS
NULL
)
update cosd.ERSConstructedVariablesOutcomes set ERSConstructedVariable_NewDataSeriesID=_dummy.datatobeupdated
from cosd.ERSConstructedVariablesOutcomes dummy
JOIN _dummy
on dummy.ERSConstructedVariable_BusinessLogicID= _dummy.ERSBusinessLogic_ID
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.