在sql数据库中更新表

时间:2014-03-15 12:39:50

标签: sql-server

我有以下要求/业务规则: GALAXYS

delete * from Galaxys

'追加来自ADE数据 - qryGetGalaModel

INSERT INTO tbl Galaxys ( [ID Number], [ID Status], [ Type], [ID Completed], [MK Link ID], [MODEL Link ID], [ID Main Vendor] )
SELECT Ceekay_ID_WO.TNE_NO, Ceekay _TNE_WO.STATUS, Ceekay_TNE_WO.TYPE, Ceekay _TNE_WO.TNE_ID_COMPLETED, Ceekay_TNE_WO.CS_LINK_ID, CStr([cs_link_id]) AS [User Link ID], Ceekay_TNE_WO.SUPPLIER
FROM Ceekay _TNE_WO
WHERE (((Ceekay _TNE_WO.STATUS)<>"CANC") AND ((Ceekay_TNE_WO.WORK_TYPE)="De-Install" Or (Ceekay_TNE_WO.WORK_TYPE)="MBNL-De-Install") AND ((Ceekay_TNE_WO.TNE_COMPLETED) Is Null Or (Ceekay_TNE_WO.TNE_COMPLETED)>=#7/1/2007#) AND ((Ceekay_TNE_WO.TNE_TYPE)="RADIO"))
ORDER BY Ceekay _TNE_WO.TNE_COMPLETED;

&#39;添加链接结尾 - qryUpdateAandBends

UPDATE ((((tblGalaxys  INNER JOIN SPECTRUM_IQLINK ON tblGalaxys.[User Link ID] = Ceekay _IQLINK.LINK_ID) INNER JOIN Ceekay _LINK_END ON Ceekay_IQLINK.LINK_ID = Ceekay _LINK_END.LINK_ID) INNER JOIN Ceekay_LINK_END AS Ceekay _LINK_END_1 ON Ceekay _IQLINK.LINK_ID = Ceekay_LINK_END_1.LINK_ID) INNER JOIN (qryConvertSiteID AS qryConvertSiteID_1 INNER JOIN tbl CeekayLiteSiteDetails AS tbl CeekayLiteSiteDetails_1 ON qryConvertSiteID_1.Site_ID = tblCeekayLiteSiteDetails_1.Site_ID) ON Ceekay_LINK_END_1.SITE_ID = qryConvertSiteID_1.[site ID]) INNER JOIN (qryConvertSiteID INNER JOIN tblCeekayLiteSiteDetails ON qryConvertSiteID.Site_ID = tblCeekayLiteSiteDetails.Site_ID) ON SPECTRUM_LINK_END.SITE_ID = qryConvertSiteID.[site ID] SET tblGalaxys.[A Cell ID] = [tblCeekayLiteSiteDetails].[cell_id], tblGalaxys.[A Site ID] = [Ceekay_link_end].[site_id], tblGalaxys.[B Cell ID] = [tblCeekayLiteSiteDetails_1].[cell_id], tblGalaxys.[B Site ID] = [spectrum_link_end_1].[site_id]
WHERE (((Ceekay_LINK_END.END_ID)="A") AND ((Ceekay_LINK_END_1.END_ID)="B"));

&#39;添加网站信息 - qryUpdateGalaxyDetails

UPDATE (((tblGalaxys INNER JOIN Ceekay_SITE ON tblGalaxys.[A Site ID] = Ceekay_SITE.SITE_ID) LEFT JOIN Ceekay_SITE AS Ceekay_SITE_1 ON tblGalaxys.[B Site ID] = Ceekay_SITE_1.SITE_ID) LEFT JOIN WurzelSitesProgUpdate ON tblGalaxys.[A Site ID] = WurzelSitesProgUpdate.[TM Site ID]) LEFT JOIN WurzelSitesProgUpdate AS WurzelSitesProgUpdate_1 ON tblGalaxys.[B Site ID] = WurzelSitesProgUpdate_1.[TM Site ID] SET tblGalaxys.[A Site Name] = [Ceekay_site].[site_name], tblGalaxys.A Site Region] = IIf([Ceekay_site].[region]=1,"South",IIf([Ceekay_site].[region]=2,"Midlands",IIf([Ceekay_site].[region]=3 Or [Ceekay_site].[region]=4,"North"))), tblGalaxys.[A Site Area] = [WurzelSitesProgUpdate].[area], tblGalaxys.[A Site Programme] = [WurzelSitesProgUpdate].[technology type], tblGalaxys.[B Site Name] = [Ceekay_site_1].[site_name], tblGalaxys.[B Site Region] = IIf([Ceekay_site_1].[region]=1,"South",IIf([Ceekay_site_1].[region]=2,"Midlands",IIf([Ceekay_site_1].[region]=3 Or [Ceekay_site_1].[region]=4,"North"))), tblGalaxys.[B Site Area] = [WurzelSitesProgUpdate_1].[area], tblGalaxys.[B Site Programme] = [WurzelSitesProgUpdate_1].[technology type];

更新ML编号qryMakeTempMLNumber

SELECT tblRadioDeinstalls.[TNE Number], SPECTRUM_LNK.ML_NUMBER, SPECTRUM_LNK.LINK_STATUS
INTO tempMLNumber
FROM ((SPECTRUM_LNK INNER JOIN SPECTRUM_NODE ON SPECTRUM_LNK.A_END_NODE_ID = SPECTRUM_NODE.NODE_ID) 
INNER JOIN SPECTRUM_NODE AS SPECTRUM_NODE_1 ON SPECTRUM_LNK.B_END_NODE_ID = SPECTRUM_NODE_1.NODE_ID) 
INNER JOIN tblRadioDeinstalls ON (tblRadioDeinstalls.[A Site ID] = SPECTRUM_NODE.SITE_ID) AND (SPECTRUM_NODE_1.SITE_ID = tblRadioDeinstalls.[B Site ID])
WHERE (((SPECTRUM_LNK.LINK_TYPE)="R"));

qryUpdateMLNumber

UPDATE tblRadioDeinstalls INNER JOIN tempMLNumber ON tblRadioDeinstalls.[TNE Number] =
tempMLNumber.[TNE Number] SET tblRadioDeinstalls.[ML number] = [ML_NUMBER],
tblRadioDeinstalls.[Link Status] = [LINK_STATUS];

更新ML编号qryMakeTempMLNumber

SELECT Galaxys.[TNE Number], Ceekay_LNK.ML_NUMBER, Ceekay _LNK.LINK_STATUS
INTO tempMLNumber
FROM ((Ceekay _LNK INNER JOIN Ceekay _NODE ON Ceekay _LNK.A_END_NODE_ID = Ceekay _NODE.NODE_ID) 
INNER JOIN Ceekay _NODE AS Ceekay _NODE_1 ON Ceekay _LNK.B_END_NODE_ID = Ceekay _NODE_1.NODE_ID) 
INNER JOIN tblGalaxys ON (tblGalaxys.[A Site ID] = Ceekay_NODE.SITE_ID) AND (Ceekay _NODE_1.SITE_ID = tblGalaxys.[B Site ID])
WHERE (((Ceekay_LNK.LINK_TYPE)="R"));

qryUpdateMLNumber

UPDATE tblGalaxys INNER JOIN tempMLNumber ON tblGalaxys.[TNE Number] =
tempMLNumber.[TNE Number] SET tblGalaxys.[ML number] = [ML_NUMBER],
tblGalaxys.[Link Status] = [LINK_STATUS];

请求是使用sql query langauage在sql数据库中填充上面的内容。

有人可以帮忙吗

2 个答案:

答案 0 :(得分:0)

看起来你有所有的碎片。尝试这样的更新:

UPDATE tblRadioDeinstalls 
  SET tblRadioDeinstalls.[ML number] = [ML_NUMBER],
  tblRadioDeinstalls.[Link Status] = [LINK_STATUS]
FROM tblRadioDeinstalls 
INNER JOIN tempMLNumber ON tblRadioDeinstalls.[TNE Number] =
tempMLNumber.[TNE Number] ;

以下是SQL Server更新http://msdn.microsoft.com/en-us/library/8hwekas8(v=vs.80).aspx

的文档和示例的链接

答案 1 :(得分:0)

您可以在update语句中使用别名,这样可以更容易阅读。请查看下面的测试代码。

DECLARE @tableA TABLE
    (
     id INT
    ,MyData VARCHAR(20)
    );

INSERT INTO @tableA VALUES (0,'First Element'), (1,'Second Element'), (2, 'Fourth Element')

SELECT * FROM @tableA

UPDATE A
SET a.MyData = 'Third Element'
FROM @tableA AS A
WHERE a.id = 2;

SELECT * FROM @tableA

正如您注意到UPDATE @tableA AS A而不是UPDATE A我在A子句中执行了FROM并定义了UPDATE。在SET语句中UPDATE始终跟{{1}}之后的其他信息。