Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

SQL Server Stored Procedure

The following stored procedure is giving error "The function has too many arguments".
Kindly help.
------------------------------

USE [drugs]
GO
/****** Object:  StoredProcedure [dbo].[FetchReport1Graph]    Script Date: 04/11/2012 20:11:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[FetchReport1Graph]
(
   @Drug varchar(1000)
 )
as
 begin
   declare @strSelect varchar(1000)
      Begin Tran
      set @strSelect=  'select drugname, COUNT(patientId) as NumberDurg from AssessmentDrug where DrugName in(' + CAST(@Drug as varchar)+ ') group by DrugName'
       EXEC(@strSelect)
      Commit
 end
0
sanjay-gandhi
Asked:
sanjay-gandhi
  • 2
2 Solutions
 
parthmalhanCommented:
try Below:



ALTER procedure [dbo].[FetchReport1Graph]
(
   @Drug varchar(1000)
 )
as
 begin
   declare @strSelect varchar(1000)
      Begin Tran
 set @strSelect=  'select drugname, COUNT(patientId) as NumberDurg from AssessmentDrug where DrugName in(''' + CAST(@Drug as varchar)+ ''') group by DrugName'
ALTER procedure [dbo].[FetchReport1Graph]
(
   @Drug varchar(1000)
 )
as
 begin
   declare @strSelect varchar(1000)
      Begin Tran
0
 
sachinpatil10dCommented:
Your StoreProcedure excepts only one parameter  @Drug varchar(1000)

so the storeprocedure call will be

exec [dbo].[FetchReport1Graph] '100'

Open in new window


may be you are using it like this

exec [dbo].[FetchReport1Graph] '100','100'

Open in new window


which gives following error

Msg 8144, Level 16, State 2, Procedure FetchReport1Graph, Line 0
Procedure or function FetchReport1Graph has too many arguments specified.

you can use it

exec [dbo].[FetchReport1Graph] '100,200'

Open in new window

0
 
sanjay-gandhiAuthor Commented:
Let me try and revert... getting slightly busy....will revert by evening...thanks.
0
 
sanjay-gandhiAuthor Commented:
Thanks, works fine.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now