1

以下是 MySQL 查询,

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 查询,但未能实现。你能帮我么?

谢谢

4

1 回答 1

3

它失败的唯一原因是因为CONCATmysql功能,所以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
)

或者,您也可以使用 Join 执行 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
于 2012-12-14T06:04:35.817 回答