2012-12-14 68 views
1

以下是MySQL查詢,轉換MySQL查詢到相應的SQL服務器的特定查詢()

DELETE FROM ATTRIBUTE_INSTANCE 
WHERE ATTRIBUTE_INSTANCE.ATTRIBUTE_NAME 
IN 
(SELECT CONCAT(ATTRIBUTE_TEMPLATE.TEMPLATE_ID,'.',ATTRIBUTE_TEMPLATE.ATTRIBUTE_NAME) 
    FROM ATTRIBUTE_TEMPLATE, TEMP_ENTITY_TABLE 
WHERE ATTRIBUTE_TEMPLATE.TEMPLATE_ID=TEMP_ENTITY_TABLE.ENTITY_ID 
); 

我想將它轉化爲等價的SQL Server查詢,但我沒能實現。你能幫我麼?

感謝

+0

你好你能告訴我們你在哪裏掙扎嗎?和任何嘗試這樣做?示例代碼更改? –

回答

3

爲什麼會失敗的唯一原因是因爲CONCAT MySQL的功能,所以對於TSQL使用+代替CONCAT

DELETE FROM ATTRIBUTE_INSTANCE 
WHERE ATTRIBUTE_INSTANCE.ATTRIBUTE_NAME IN 
( 
    SELECT ATTRIBUTE_TEMPLATE.TEMPLATE_ID + '.' + ATTRIBUTE_TEMPLATE.ATTRIBUTE_NAME 
    FROM ATTRIBUTE_TEMPLATE, TEMP_ENTITY_TABLE 
    WHERE ATTRIBUTE_TEMPLATE.TEMPLATE_ID=TEMP_ENTITY_TABLE.ENTITY_ID 
) 

交替,你也可以做與加入DELETE,

DELETE a 
FROM ATTRIBUTE_INSTANCE a 
     INNER JOIN 
     ( 
      SELECT ATTRIBUTE_TEMPLATE.TEMPLATE_ID + '.' + 
        ATTRIBUTE_TEMPLATE.ATTRIBUTE_NAME As ColumnName 
      FROM ATTRIBUTE_TEMPLATE 
        INNER JOIN TEMP_ENTITY_TABLE 
         ON ATTRIBUTE_TEMPLATE.TEMPLATE_ID = TEMP_ENTITY_TABLE.ENTITY_ID 
     ) b ON a.ATTRIBUTE_NAME = b.ColumnName 
+0

非常感謝,我會測試它並回復你。謝謝你的協助。 – Ramesh