将mysql查询转换为等效的sql server特定查询()

时间:2012-12-14 06:01:28

标签: mysql sql sql-server tsql

以下是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查询,但我没能实现。你能帮我吗?

感谢

1 个答案:

答案 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
)

或者,您也可以使用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