I have written the following code in a SQL Server stored procedure to avoid cursor in the code. I have used temporary table for storing data and loop through the data.
SELECT *
INTO #temp
FROM
(SELECT *
FROM -----------------) AS x
SET @iRwCnt = @@ROWCOUNT
CREATE CLUSTERED INDEX idx_tmp ON #temp(ACID) WITH FILLFACTOR = 100
WHILE @iRwCnt > 0
BEGIN
SELECT TOP 1 @sValue = ACID
FROM #temp
SET @iRwCnt = @@ROWCOUNT
IF @iRwCnt > 0
BEGIN
SELECT
@mregno = regno, @amount = credit,
@remark = remark, @trans_type = transtype
FROM
#temp
WHERE
ACID = (SELECT TOP 1 ACID FROM #temp)
--begin tran
--my function
--commit tran
DELETE FROM #temp
WHERE ACID = @sValue --remove processed record
END
END
DROP TABLE #temp
This procedure is working as I wanted. It will be used by the members in the software.
My question is that as this code will be run by multiple users at the same time online, is this possible to create multiple temp table in the server as the same time?