Pages

2017年10月13日 星期五

Declare Table at MSSQL



DECLARE  @RowsToProcess int,
                   @CurrentRow int
--Declare a temp table to stock the search result
DECLARE @TempTable TABLE
     (
          RowID int not null primary key identity,
          DataInt int default 0,
          DataNvarchar nvarchar(20) null,
          DataBit  bit null,
          DataDecimal decimal(15,2) default 0fault 0,
          ThisYearQuota decimal(15,2) default 0
     )
--Insert the search result to @TempTable
INSERT INTO @TempTable
SELECT *
FROM
           (
           SELECT *
           FROM DataTable
           ) z
--Max(Row)
SET @RowsToProcess = @@ROWCOUNT
--Start Row
SET @CurrentRow = 0
--Process row one by one
WHILE @CurrentRow < @RowsToProcess
     BEGIN
          SET @CurrentRow = @CurrentRow + 1
          --Select single rew data
          SELECT * FROM @TempTable WHERE RowID = @CurrentRow
     END

沒有留言:

張貼留言

 
 
Blogger Templates