Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parameter passing in Stored Procedure 1

Status
Not open for further replies.

rajkum

Programmer
Joined
Jul 30, 2003
Messages
48
Location
US
Hi,
I have a stored procedure where i pass two parameter
1. the field Name and
2. the Value

from an ASP page.

The Code below:

CREATE PROC storedProcName
@fldName varchar
@fldVal varchar
as
BEGIN
Select * FROM tableName WHERE @fldName = @fldVal
END

This does not return me any data....where it has to.
But when I replace the @fldName with the actual field name it works...
Pls Help..

Thanks in advance.
Raj.



 
Ah ... time for some dynamic SQL

declare @command varchar(400)

set @command = 'Select * FROM tableName WHERE' + @fldName + ' = ' + @fldVal

exec (@command)

Thanks

J. Kusch
 
Did you put in a comma after @fldName, like this?
Code:
CREATE PROC storedProcName
 @fldName varchar,
 @fldVal  varchar
as
BEGIN
Select * FROM tableName WHERE @fldName = @fldVal  
END
 
May need another space between the where and the ' as in ...

WHERE '

Also add a print statment, before your exec statment, to see how you code looks after the dynamic build. As in ...

PRINT @Command

Thanks

J. Kusch
 
Thanks J. Kusch.
That was helpfull!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top