I have a table which has fields
Code,Company,City,Zip,County,State,Type
first i need to group the data by Code and company.
i.e
group A
Code:001 and Company:A
group B
Code:002 and Company:A
and so on
and in each of these groups i need to loop and apply some business rules to identify single record .My purpose is to identify one good record among all the records
My business rules are like
1. Do join to another table on zip code (if zip is not null) and eliminate rest of the records in that set which does not have matching zip code.
2. Do join to another table on City and State (if zip is null) and eliminate rest of the records in that set which does not have matching City and State.
3. If there are any sets which does not satisfy 3) and 4) above, get the record with Type of 1 in the set.
Kindly let me know how to approach this,
Will cursors be the right choice or can i just do this with temp table.
I am using SQL Server 2008 R2.
Thanks in advance
Kannan
↧