<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>
字符串中加入表變量
泛舟湖上清波郎朗
2018-12-03 10:17:44