在老版的tsql里会出现想*= 和=*的语句,在本意是在代表左联及右联。
我们最近在做DB的升级 要升级到mssql2008。 所以要对老的sp进行修改。
其中一想就是吧*=和=*改为left和right jion。
一般情况下都还好,但有时会遇到比较复杂的语法如下
。。。。。
From table1 pl,
table2 pe,
table3 ch,
table4 cp
Where (pe.dt >= @dt and
pe.dt <= @dt_end )
and (cp.name = ‘source' and
pe.s *= cp.s)
and (ch.name = 'status' and
pe.hr_status_cd *= ch.code)
总感觉怪怪的。
有人可以详细解析一下么?
------解决方案--------------------
- SQL code
From table1 pl, table2 pe, table3 ch, table4 cp Where (pe.dt >= @dt and pe.dt <= @dt_end ) and (cp.name = ‘source' and pe.s *= cp.s) and (ch.name = 'status' and pe.hr_status_cd *= ch.code)' --=========================================================== from table1 pl inner join Table2 pe on --??? 这个地方,应该有跟pl的连接关系 left join table3 ch on pe.hr_status_cd = ch.code left join table4 cp on pe.s = cp.s where ch.name ='status' and cp.name ='source' and pe.dt >[email protected] and pe.dt <[email protected]_end
------解决方案--------------------
- SQL code
from table1 pl inner join Table2 pe on 1=1 --没有明确关系,可以用1=1代替 left join table3 ch on pe.hr_status_cd = ch.code left join table4 cp on pe.s = cp.s where ch.name ='status' and cp.name ='source' and pe.dt >[email protected] and pe.dt <[email protected]_end