Solved

how to pass parameters to an SP using select command

Posted on 2011-09-04
5
238 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 500 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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