Solved

SQL Server Stored Procedure

Posted on 2012-04-11
4
296 Views
Last Modified: 2012-04-12
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
Comment
Question by:sanjay-gandhi
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
parthmalhan earned 400 total points
ID: 37836211
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
 
LVL 9

Assisted Solution

by:sachinpatil10d
sachinpatil10d earned 100 total points
ID: 37836215
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
 

Author Comment

by:sanjay-gandhi
ID: 37836261
Let me try and revert... getting slightly busy....will revert by evening...thanks.
0
 

Author Closing Comment

by:sanjay-gandhi
ID: 37837734
Thanks, works fine.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now