Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2001-11-24 : 16:28:07
|
| Bruce writes "http://www.sqlteam.com/forums/link.asp?Topic_ID=6460 Well I got it but if there is another way I would love to see it to use it for other problems like this. I used the temp table to get it done. Again I love your site. ThanksCREATE Procedure SP_RetrieveRec_lookupjobs @contid varchar(12), @StartTime datetime, @EndTime datetime, @JobsCnt intAsCREATE TABLE #TempJobs (ContractorID varchar(12),CompanyName varchar(40),Job_ID char(30) )if @contid <> ''beginINSERT #TempJobs select a.ContractorID, a.CompanyName , b.Job_ID from Contractor a, CustomerJobInfo b, ContractorZipservices c, ContractorZipsTable d ,CustOrderAddress e Where a.ContractorID = @contid and c.ContractorID = a.ContractorID and b.ServiceID = c.ServiceID and c.ContractorID = d.ContractorID and b.JobAddressID = e.JobAddressID and D.zip = e.JobPostalcode and b.DateCreated>=(convert(smalldatetime,convert(char(10),@StartTime,1))) and b.DateCreated<= (convert(smalldatetime,convert(char(10),@EndTime,1))) and b.BadJob = 0 endelsebeginINSERT #TempJobs select a.ContractorID, a.CompanyName , b.Job_ID from Contractor a, CustomerJobInfo b, ContractorZipservices c, ContractorZipsTable d , CustOrderAddress e Where (a.TestAcc <> '1' and b.BadJob <> '1' and c.ContractorID = a.ContractorID and b.ServiceID = c.ServiceID and c.ContractorID = d.ContractorID and b.JobAddressID = e.JobAddressID and D.zip = e.JobPostalcode and b.DateCreated>=(convert(smalldatetime,convert(char(10),@StartTime,1))) and b.DateCreated<= (convert(smalldatetime,convert(char(10),@EndTime,1))) and b.BadJob = 0)end CREATE TABLE #TempJobsTotals (ContractorID varchar(12),CompanyName varchar(40),jobs int )beginINSERT #TempJobsTotals Select Distinct ContractorID, CompanyName , count(ContractorID) as jobs From #TempJobs Group By ContractorID,CompanyName Order by CompanyNameendbegin Select * From #TempJobsTotals Where jobs >=@JobsCnt enddrop table #TempJobsdrop table #TempJobsTotalsThat did it. I also made it possible to only display jobs over a selected number. Maybe this would help someone elseBruce" |
|
|
|
|
|
|
|