代码改变世界

SQL中With关键字的简单用法

2011-02-25 03:18  音乐让我说  阅读(1060)  评论(0编辑  收藏  举报

代码如下:

select * from dbo.HRReOrPuType


/* with 的写法避免了产生临时表的IO,更多建议请参考:http://wudataoge.blog.163.com/blog/static/80073886200961652022389/ */
with t_rePuType1 as
(
	select Id from HRReOrPuType where typeName like '出勤奖%'
)/* 后面可以接N个,但with结束后,必须使用with定义的这些变量 ,
t_rePuType2 as 
(

) */
select * from dbo.HRUserReAndPu where hRReOrPuTypeId in (select * from t_rePuType1)

谢谢您的浏览!