Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL w/variables not returning records

Status
Not open for further replies.

olichap

Programmer
Mar 20, 2001
389
US
I am having trouble getting the following stored procedure to work. It will run when passed its parameters but does not return any records (if the same query is run manually 2000+ records are returned).



I have the following stored proc:

CREATE PROCEDURE test
@ContractCode varchar(10),
@dtFrom datetime,
@dtTo datetime,
@Umbrella int

AS

declare @option varchar(30)

if @umbrella = 0
set @option = 'c.contractcode'
else
set @option = 'cb.employercode'

select
c.claimsno,
c.attenddoctor,
c.patientcode,
p.sex,
cb.employercode
into #SavingsData1
from claimsa c inner join Patient p
on c.patientcode = p.patientcode
inner join claimsb cb on c.claimsno = cb.claimno
where
@option = @ContractCode and c.dateentered between @dtFrom and @dtTo
and c.claimsno like 'P%' and p.sex in('M','F') and c.attenddoctor <> 'ZZZZ'

select * from #savingsdata1

Any assistance would be appreciated. The results of the above example, when I can get it to work, must form the foundation for a rather large/complex stored procedure.

Thanks,

Oliver
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top