我的SQL语句如下:
- SQL code
INSERT INTO #TMP_LAND ( land_id, big_land_id, land_number ) ( SELECT a.land_id, c.land_id, c.land_number FROM (SELECT * FROM imp_land WHERE case_number = @inCase_Number) a, (SELECT * FROM imp_land_mod WHERE case_number = @inCase_Number) b, ch_land c WHERE a.land_number *= b.land_number AND a.land_number = c.land_number AND b.att_gra_mod IS NULL )
在SQLServer2005中,会有如下错误:消息 4147,级别 15,状态 1,过程 DATA_IMPORT,第 138 行
此查询使用的不是 ANSI 外部联接运算符("*=" 或 "=*")。若要不进行修改即运行此查询,请使用存储过程 sp_dbcmptlevel 将当前数据库的兼容级别设置为 80 或更低。极力建议使用 ANSI 外部联接运算符(LEFT OUTER JOIN、RIGHT OUTER JOIN)重写此查询。在将来的 SQL Server 版本中,即使在向后兼容模式下,也不支持非 ANSI 联接运算符。
当然,这里可以通过设置兼容级别:
- SQL code
EXEC SP_DBCMPTLEVEL 'TABLE_NAME','90'
------解决方案--------------------
- SQL code
INSERT INTO #TMP_LAND ( land_id, big_land_id, land_number ) ( SELECT a.land_id, c.land_id, c.land_number FROM (SELECT * FROM imp_land WHERE case_number = @inCase_Number) a left join (SELECT * FROM imp_land_mod WHERE case_number = @inCase_Number) b on a.land_number = b.land_number inner join ch_land c on a.land_number = c.land_number WHERE b.att_gra_mod IS NULL )