Solved

how to pass parameters to an SP using select command

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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