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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 a step into dynamic sql

Author  Topic 

Vivaldi
Constraint Violating Yak Guru

298 Posts

Posted - 2001-08-15 : 11:25:46
Okay,

I have a proc that has some dynamic sql that works quite well.

Basically, if dates are passed in they are used, else ignored (from dynamic sql article)
and the same for staffid.

I have to accomodate a list of counties now as well, and they may/may not be passed in.

the list is essentially id's from a different table of counties.

So i have broken the string up into a temp table so I could use where county In (select countyid from county) effect. However I don't think this will work.

How do i say, if countylist is not null, then use the county condition
else ignore the county condition.

some code, @cntylist could be = 1, 12, 31, 42 (placed in temp table (#tpcounties) as indiv recs)

Set @e1 = (
Select Count(ap.caseid) as empcount
from APPerformance ap inner join Characteristics c
on ap.caseid = c.caseid
inner join StaffCase sc on sc.caseid = ap.caseid and sc.staffid = Coalesce(@staffid,sc.staffid)
inner join CaseInfo ci on ci.caseid = ap.caseid
inner join County on county.countyid = ci.servicecounty
and ci.servicecounty = ****ci.servicecounty******* what do i do here
where laborforcestatus='N' AND employed1='Yes'
AND
((exitqtrdate >= Coalesce(@begdate,exitqtrdate)) AND (exitqtrdate <= Coalesce(@enddate,exitqtrdate)))
)

Thanks SQL Jedi's

Composing temporary solutions to permanent problems
   

- Advertisement -