DECLARE @Main_Obj numeric(18, 0),@Tool_Warehouse varchar(50),@Component_No varchar(50)
DECLARE center CURSOR FOR
SELECT [Object_Id]
,[Tool_Warehouse]
,[Component]
FROM [BusinessQuotation].[dbo].[Main]
OPEN center
DECLARE @NU numeric(18, 0)
DECLARE @SNU VARCHAR(5)
FETCH NEXT FROM center INTO @Main_Obj,@Tool_Warehouse,@Component_No
WHILE @@FETCH_STATUS = 0
BEGIN
SET @NU=1
WHILE @NU<= @Component_No
BEGIN
IF (@NU<10)
BEGIN
SET @SNU='00'+CAST(@NU AS VARCHAR)
END
ELSE
BEGIN
SET @SNU='0'+CAST(@NU AS VARCHAR)
END
INSERT INTO [BusinessQuotation].[dbo].[Component_File]
([Tool_Warehouse],[Main_Obj],[Component_No])
VALUES
(@Tool_Warehouse,@Main_Obj,'C-'+@SNU)
SET @NU=@NU+1
END
FETCH NEXT FROM center INTO @Main_Obj,@Tool_Warehouse,@Component_No
END
CLOSE center
DEALLOCATE center
沒有留言:
張貼留言