I have a result set from a SQL query. The result set will have multiple rows. I need to get a count of the rows and then perform a SQL INSERT using specific columns as arguments in a SQL insert loop. I hope that wasn't too convoluted of an explanation.
For example:
DECLARE @i int
SET @numrows = (SELECT COUNT(*) cnt FROM Patient WHERE ClientID = 5001)
SELECT FirstName, LastName, DOB FROM Patient WHERE ClientID = 5001
**make believe code just to demonstrate what I'm trying to accomplish**
for @i = 1 to @numrows
--do some INSERT function here using specific fields from the above SELECT query as arguments
NEXT i
Mike Brown
ITOT Solutions, Inc.
SQL Server 2012
Alpha Five v3 (12)