Click here to Skip to main content
15,886,720 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

I have a stored procedure as given below:

SQL
Create Procedure ProcName(@transname varchar(200),@transno varchar(200))
As
BEGIN
set nocount on 
select tb1.pono,tb2.billno from table1 tb1
inner join table2 tb2 on tb1.id=tb2.id
where @transname=@transno
set nocount off
END


When I execute this I dont get any output.

But if I remove one parameter @transname and alter the procedure as below, I get the output.

SQL
Create Procedure ProcName(@transno varchar(200))
As
BEGIN
set nocount on 
select tb1.pono,tb2.billno from table1 tb1
inner join table2 tb2 on tb1.id=tb2.id
where pono=@transno
set nocount off
END


Actually, I want the user to pass the parameter @transname and execute the query. Please help me achieve that. What am I missing here? or what mistake I have done?
Posted
Comments
Azee 6-Oct-13 6:29am    
You have already passed @transno alone in the second scipt, and have tried passing @tranname in the first one, what exactly do you want to do with these paramters. what will you compare @transname with? any table column's value?

1 solution

i think in first procedure your mistake is like you are comparing your two procedure parameter in your where condition where @transname=@transno and as per my understanding transname and transno are two different value and that why your where condition is not fullfill so nothing will be selected from your table1 and table2 so please modified your where condition and check it out
 
Share this answer
 
Comments
Tejas Vaishnav 5-Oct-13 1:40am    
if this helps out please mark it as answer
Rahul Krishnan R 5-Oct-13 1:58am    
Thank you for you valuable suggestion.
I want both @transname and @transno to be passed by the user as parameters.then only I will get my expected result.
What modification can I bring here in the where condition to fulfill my need?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900