<P>在一个存储过程中如下使用表变量:</P> <P>declare @tb table(id int identity(1,1), hotel_id varchar(20), member_price decimal)</P> <P> insert into @tb(hotel_id,member_price) select hotel_id,min(member_price) from hotel_room group by hotel_id order by min(member_price) ASC</P> <P>SET @strField = 'select a.hotel_name as hotel_name, a.hotel_id as hotel_id, isnull(a.star, '') as star, isnull(a.sowntown, '') as sowntown, isnull(a.hotel_traffic, '') as hotel_traffic, isnull(a.hotel_intro,'') as hotel_intro, a.is_extend as is_extend,b.member_price as member_price from hotel_detail as a inner join <FONT color=#ff0000>@tb</FONT> as b on a.hotel_id = b.hotel_id '</P> <P>SET @strSQL = @strField + @strWhere + @strOrder --因为怕代码太长@strWhere和@strOrder变量就先不在程序里贴出来了</P> <P>exec (@strSQL)</P> <P>执行存储过程的时候会报错,变量@tb未定义.请问我该怎么使用呢?谢谢!</P>
蝴蝶刀刀
交互式爱情
相关分类