DECLARE @SQLA VARCHAR(6000),@SQLB VARCHAR(8000),@SQLC VARCHAR(8000)
IF object_id('tempdb..##tableA')IS NOT NULL DROP TABLE ##tableA
IF object_id('tempdb..##tableB')IS NOT NULL DROP TABLE ##tableB
set @SQLA=' SELECT * INTO ##tableA FROM
(SELECT Number,Lasts,Heel,SuggestedPrice,ColorsAvailable FROM TSHOE) A ORDER BY Lasts '
EXEC(@SQLA)
Create Table [dbo].[##tableB]
(
T_Number varchar(50 ) Null ,
T_Lasts varchar(50) null ,
T_Price decimal(10,2) null ,
T_Heel varchar(50) null ,
T_Color_A varchar(5000))
Declare @v_Num varchar(50),@v_Lasts varchar(50),@v_price decimal(10,2),@v_Heel varchar(50),
@v_Color_A varchar(5000),@v_s varchar(5000)
Declare win Cursor
FOR
SELECT Number,Lasts,Heel,SuggestedPrice FROM ##tableA Group by Number,Lasts,Heel,SuggestedPrice
Open win
Fetch Next From win into @v_Num,@v_Lasts,@v_Heel,@v_price
While @@Fetch_Status=0
begin
declare winone cursor
for
select ColorsAvailable from ##tableA
where Number=@v_Num and Lasts=@v_Lasts and Heel=@v_heel and SuggestedPrice=@v_price
open winone
set @v_s=''
fetch next from winone into @v_color_A
while @@fetch_status=10
begin
set @v_s=@v_s+@v_color_A
fetch next from winone into @v_color_A
end
insert into ##tableB
(T_Number,T_Lasts,T_Price,T_Heel,T_Color_A)
values(@v_Num,@v_Lasts,@v_price,@v_Heel,@v_s)
deallocate winone
fetch next from win into @v_Num,@v_Lasts,@v_Heel,@v_price
end
deallocate win
select * from ##tableB
帮我修改一下好吗?@v_s中没有值!