gwarcher
asked on
Invalid Column error in where clause on stored procedure execution
I have a basic stored procedure that I created that is failing with an invalid collumn name error when executed. The only problem is that the variable being passed goes into the where clause and is not a column name.
ALTER PROCEDURE [dbo].[spSearchFirstName]
@FirstName varchar(155)
AS
BEGIN
EXEC('Select first, last, address, address2, city, state, zip, county, [Home Phone],
[Work Phone], [Mobile Phone],
order, description
FROM vwAllOrders
WHERE first = ' + @FirstName
)
END
--EXECUTION
EXEC spSearchFirstName @FirstName = N'Thomas '
ALTER PROCEDURE [dbo].[spSearchFirstName]
@FirstName varchar(155)
AS
BEGIN
EXEC('Select first, last, address, address2, city, state, zip, county, [Home Phone],
[Work Phone], [Mobile Phone],
order, description
FROM vwAllOrders
WHERE first = ' + @FirstName
)
END
--EXECUTION
EXEC spSearchFirstName @FirstName = N'Thomas '
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, force of habit using EXEC.
Open in new window