Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i am executing my stored procedure i got the error "..Must declare the scalar variable "@serviceCode" .."
my procedure is

ALTER PROC [dbo].[Clinic_ServiceInsuranceList]
@serviceCode INT ,
@InsuranceID INT 
AS
BEGIN
declare @sqlTextAllCount nvarchar(max);
	
set @sqlTextAllCount='
SELECT dbo.Service.Code,dbo.Service.Title,dbo.ActCostService.Cost,dbo.InsuranceServiceCost.Cost
 FROM dbo.Service,dbo.ActCostService,dbo.InsuranceServiceCost,dbo.InsuraceCost
WHERE
[dbo].[Service].ID=@serviceCode AND
--dbo.InsuraceCost.InsuraceID=@InsuranceID AND
dbo.ActCostService.ServiceID=@serviceCode AND
dbo.InsuranceServiceCost.ServiceID=@serviceCode '


if(@InsuranceID <>0)
			Set @sqlTextAllCount += ' And InsuraceCost.InsuraceID = '    +  convert(nvarchar,@InsuranceID)
Execute sp_executesql @sqlTextAllCount
END
Posted

Try this code


ALTER PROC [dbo].[Clinic_ServiceInsuranceList]
@serviceCode INT ,
@InsuranceID INT 
AS
BEGIN
declare @sqlTextAllCount nvarchar(max);
set @sqlTextAllCount='
SELECT dbo.Service.Code,dbo.Service.Title,dbo.ActCostService.Cost,dbo.InsuranceServiceCost.Cost
 FROM dbo.Service,dbo.ActCostService,dbo.InsuranceServiceCost,dbo.InsuraceCost
WHERE
[dbo].[Service].ID='+convert(nvarchar(10),@serviceCode)+' AND
dbo.ActCostService.ServiceID='+convert(nvarchar(10),@serviceCode)+' AND
dbo.InsuranceServiceCost.ServiceID='+convert(nvarchar(10),@serviceCode) +''
 

if(@InsuranceID <>0)
			Set @sqlTextAllCount += ' And InsuraceCost.InsuraceID = '    +  convert(nvarchar,@InsuranceID)
print 	@sqlTextAllCount
Execute sp_executesql @sqlTextAllCount
END
 
Share this answer
 
try with

SQL
set @sqlTextAllCount='
SELECT dbo.Service.Code,dbo.Service.Title,dbo.ActCostService.Cost,dbo.InsuranceServiceCost.Cost
 FROM dbo.Service,dbo.ActCostService,dbo.InsuranceServiceCost,dbo.InsuraceCost
WHERE
[dbo].[Service].ID=@serviceCode AND
--dbo.InsuraceCost.InsuraceID='+convert(nvarchar,@InsuranceID)+' AND
dbo.ActCostService.ServiceID='+convert(nvarchar,@serviceCode)+' AND
dbo.InsuranceServiceCost.ServiceID='+convert(nvarchar,@serviceCode)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900