Thursday, March 26, 2015

cursor

Hi Siddu_123,



I think Stan's first reply and Patrick's would be good to achieve your requirement. I don't see any necessity a CURSOR should be involved in this case. To insert 5000 rows with different IDs into you table, a recursive way can be alternative.




;WITH cte(Id,name,lastname,address,age,DOB,EX) AS
(
SELECT 5000,'sam', 'sammy','12 atlantic street',52,'7/15/1967','M'
UNION ALL
SELECT Id+1,name,lastname,address,age,DOB,EX FROM cte
WHERE Id<10000
)
INSERT INTO YOUTABLE SELECT * FROM cte
OPTION (MAXRECURSION 0)



If you have any question, feel free to let me know.


Eric Zhang

TechNet Community Support




No comments:

Post a Comment