Link to home
Start Free TrialLog in
Avatar of rowmark
rowmark

asked on

Count of Records

Hi, I have a stored proc that will accept zipcode and radius as parameters
and return list of zipcodes based on the params.

I am inserting the results into a different table. I have couple of questions,

How do I loop through the records from above and insert into another table
How do I get a count of records thrown by the query.

If the count is >0 I want to insert into another table
ASKER CERTIFIED SOLUTION
Avatar of Mark Wills
Mark Wills
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh, and then to insert into another table, just use the insert command with a select :

insert my_other_table (< column list >)
select <column list>
from #my_zipcodes
where <conditions>


if there is nothing in #my_zipcodes that satisfy the <conditions> then it is a empty set and nothing is added.

if there is possibility of duplicate rows that might already exists then would have to extend those <conditions> with :

insert my_other_table (< column list >)
select <column list>
from #my_zipcodes Z
where <conditions>
AND not exists (select NULL from my_othertable O where O.zipcode = Z.zipcode and O.suburb = Z.suburb)