Looping problem

Results 1 to 2 of 2

Thread: Looping problem

  1. #1
    Join Date
    Dec 1969

    Default Looping problem

    Hi all!!<BR><BR>I have 3 MS SQL tables...<BR>Project_Master(Project_id,Client,CD,C onfirm_status)<BR>Project_details(Project_ID,Det1, Det2,Det3,Country_ID)<BR>Country_master(Country_id ,Country_name)<BR><BR>I need to display the count of Projects where confirm_status=1 where country_id=1<BR><BR>Here is my code<BR><BR>maxid=max(country_id)<BR><BR>For j=0 to maxid-1<BR>sqlyes="select count(PM.Project_id) from project_master PM,PROJECT_DETAILS PD,COUNTRY_MASTER CM where PM.PROJECT_ID=PD.PROJECT_ID and PD.COUNTRY_ID="&j&" AND PM.MOU_CONFIRMED=1 AND CM.COUNTRY_ID=PD.COUNTRY_ID"<BR><BR>next<BR><BR>Pl s tell me why I am getting two extra rows in the middle..and am I correct in looping through the records???<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Looping problem

    You don&#039;t need a loop to do this. The following code will return all the country IDs and the number of rows for each country where PM.MOU_CONFIRMED=1.<BR><BR><BR>select PD.COUNTRY_ID, count(*)<BR>from project_master PM<BR>join PROJECT_DETAILS PD on PD.PROJECT_ID=PM.PROJECT_ID<BR>join COUNTRY_MASTER CM on CM.COUNTRY_ID=PD.COUNTRY_ID<BR>where PM.MOU_CONFIRMED=1<BR>group by PD.COUNTRY_ID<BR><BR><BR>Gavin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts