Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to pass parameters to an SP using select command

Posted on 2011-09-04
5
Medium Priority
?
240 Views
Last Modified: 2012-05-12
I have a SP and  I am trying to call it and trying to send the parameter using a select command  

right now i am getting this error when i run the below sql statements

Msg 201, Level 16, State 4, Procedure AddPropertyProfit, Line 0
Procedure or function 'AddPropertyProfit' expects parameter '@PropertyID', which was not supplied.

(1 row(s) affected)



could any one help me out here pls







DECLARE @ID INT

EXECUTE AddPropertyProfit
 SELECT '1981' AS PropertyID,
      'Listing' AS  [PropertyProfitType]
      ,Active
      ,AcqPurchasePrice  
      ,AcqPurchaseClosingDate  
      ,AcqRealPurchasePrice  
      ,AcqCommissionPercentage  
      ,AcqCommissionTotal  
      ,AcqCommissionTo  
      ,AcqClosingCosts  
      ,AcqPropertyTax  
      ,AcqHudEarlyClosingBonus  
      ,AcqPurchaseCreditsAndRefunds  
      ,RehabSupervisionFeeAmount  
      ,RehabSupervisionFeeTo  
      ,RehabCosts  
      ,RehabNewLoan  
      ,RehabNewLoanAmount  
      ,RehabNewLoanDebtService  
      ,RehabNewLoanLender  
      ,RehabLoanInterestPayments  
      ,RehabLoanFees  
      ,RehabPropertyTaxes  
      ,RehabPropertyTaxesPercentageOfMV  
      ,RehabInsurance  
      ,RehabInsurancePercentageOfMV  
      ,RehabUtilities  
      ,RehabCashForKeys  
      ,RehabCreditsAndRefunds  
      ,RehabMisc  
      ,RehabMiscDescription  
      ,CloseCommissionPercentage  
      ,CloseCommissionTotalAmount  
      ,CloseSellerCosts  
      ,CloseSellerPaidBuyerCostsPercentage  
      ,CloseSellerPaidBuyerCosts  
      ,ClosePestInspection  
      ,CloseInspections  
      ,CloseInspectionDescription  
      ,ClosePropertyTaxes  
      ,CloseClosingCredits  
      ,CloseManagementFeePercentage  
      ,CloseManagementFeeAmount  
      ,ClosingBookkeeping  
      ,CloseMisc  
      ,CloseMiscDescription  
      ,SaleClosingDate  
      ,FinalSalesPrice  
      ,UpdatedOn
      ,UpdatedBy
      ,CreatedOn
      ,OccupiedVacantStatusID
      ,WalkThroughEstimate
      ,ApprovedBudget
      ,EvaluationRehab
      ,EvaluationRehabOther
      ,AcqDeedRecordingFee
      ,RehabLegalFee
      ,RehabHOAExpense
      ,RehabMaintenanceFees
      ,RehabPestRepairs
      ,RehabVandalismRepairs
      ,@ID  output
      FROM PropertyProfit
      WHERE PropertyProfitID = 5
0
Comment
Question by:ziorinfo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 22

Expert Comment

by:Om Prakash
ID: 36482438
you need to pass the @PropertyID parameter in the SP. which can be done as:


EXECUTE AddPropertyProfit 5
OR
EXECUTE AddPropertyProfit @PropertyID =5
0
 

Author Comment

by:ziorinfo
ID: 36482439
I am already doing that the select command
 SELECT '1981' AS PropertyID
0
 
LVL 9

Accepted Solution

by:
mimran18 earned 2000 total points
ID: 36482472
Hi
plz try this

Drop table test
Go
Create table test
( [ID] int,
[name] nvarchar(50)
)
Go
Insert into test values (1,'test1')
Insert into test values (2,'test1')
Go
Drop table test2
Go
Create table test2
( [ID] int,
[name] nvarchar(50)
)
Go

Drop procedure testsp
Go
Create procedure testsp
@ID int,
@Name nvarchar(50)
as

Insert into [test2] values (@ID,@Name)

Go

declare @execstatementsbatch nvarchar(max)
select @execstatementsbatch = ''
SELECT @execstatementsbatch = @execstatementsbatch   + 'EXEC testsp ' + Convert(nvarchar(2),[ID]) +  ', '  +[Name] +  '; '
FROM [test] Where [ID] In (1,2)

exec(@execstatementsbatch)


Go
Select * from test2

Open in new window

0
 
LVL 6

Expert Comment

by:kswathi
ID: 36482505
First of all you need to declare it as parameter if not declared already in the sp if 1981 is static then


just Set @PropertyID =' 1981'


EXECUTE AddPropertyProfit @PropertyID

you need to set the parameter before calling the sp.



0
 
LVL 42

Expert Comment

by:dqmq
ID: 36482531
>I am already doing that the select command
 SELECT '1981' AS PropertyID

No, you are not.  In the following sequence:


EXECUTE AddPropertyProfit
 SELECT '1981' AS PropertyID,


EXECUTE is one statement and SELECT is another statement.  '1981' does not get passed to the procedure.  You need to do like this:


EXECUTE AddPropertyProfit '1981'

0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

722 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