摘要:SQL WHILE 用法
---常常會用到#暫存TABLE內的資料要用某一支StoredProcedure來異動資料----
---就會用到以下方式處理------------------------------------
DECLARE @ORDTP varchar(1) -- 展BOM圖號
DECLARE @ORDNO varchar(10) -- 執行時間
DECLARE @ORDSQ int -- 展BOM圖號
DECLARE @ORDSQ1 int -- 執行時間
SELECT * FROM ORDDE4 A
WHERE A.ORDFO = '118' AND ISNULL(A.ORDDY1,'') = '' AND A.ORDNO >= '15' AND A.ORDTP <> '4' AND ORDFCO = 'N'
AND A.ORDFNO IN (SELECT INPART FROM ORDMENO WHERE INPART = A.ORDFNO)
SET @ORDTP = (SELECT TOP 1 ORDTP FROM #1234 ORDER BY ORDTP,ORDNO,ORDSQ,ORDSQ1)
SET @ORDNO = (SELECT TOP 1 ORDNO FROM #1234 ORDER BY ORDTP,ORDNO,ORDSQ,ORDSQ1)
SET @ORDSQ = (SELECT TOP 1 ORDSQ FROM #1234 ORDER BY ORDTP,ORDNO,ORDSQ,ORDSQ1)
SET @ORDSQ1 = (SELECT TOP 1 ORDSQ1 FROM #1234 ORDER BY ORDTP,ORDNO,ORDSQ,ORDSQ1)
WHILE ( SELECT COUNT(*) FROM #1234 ) > 0
BEGIN
SET @ORDTP = (SELECT TOP 1 ORDTP FROM #1234 ORDER BY ORDTP,ORDNO,ORDSQ,ORDSQ1)
SET @ORDNO = (SELECT TOP 1 ORDNO FROM #1234 ORDER BY ORDTP,ORDNO,ORDSQ,ORDSQ1)
SET @ORDSQ = (SELECT TOP 1 ORDSQ FROM #1234 ORDER BY ORDTP,ORDNO,ORDSQ,ORDSQ1)
SET @ORDSQ1 = (SELECT TOP 1 ORDSQ1 FROM #1234 ORDER BY ORDTP,ORDNO,ORDSQ,ORDSQ1)
EXEC dbo.生管製程預計完成日反向推算 @ORDTP,@ORDNO,@ORDSQ,@ORDSQ1,'Y','',NULL
DELETE FROM #1234 WHERE ORDTP=@ORDTP AND ORDNO=@ORDNO AND ORDSQ=@ORDSQ AND ORDSQ1=@ORDSQ1
END
興滿逸筑2013年全新完工,位於恆春鎮外圍離市區只要2分鐘車程,有豪華的外觀、有美麗的庭院、也有溫馨舒適的房間,這裡車流量不多,空氣不錯,適合家族或成群結黨的朋友們一同旅遊的好地方。