Dan,
I appreciate your help. The problem I'm still having is that the
@FrontPageProduct variable itself isn't the qualifying value that I want to
compare to the value contained in Products.Code. I'm wanting to use the
@FrontPageProduct variable as the column reference to get the value from the
joined table FrontPage and ultimately use that value as the qualifier. So,
basically I'm feeding a column reference through @FrontPageProduct.
If I run the SP with the value hard coded into it...
Products.Code = FrontPage.featuredItem
....it works fine. When I try to pass "featuredItem" through the
@FrontpageProduct variable...
Products.Code = FrontPage.@FrontpageProduct
.... I get a syntax error.
Maybe I'm just steering down the wrong path here. Thanks again for any help
you might provide.
Dave
"Dan Guzman" <da*******@nospam-earthlink.net> wrote in message
news:PZ******************@newsread3.news.atl.earth link.net...
Variable names are not qualified. The scope is the variable declared in
the proc. Also, you need to specify the varchar length. For example::
CREATE PROCEDURE dbo.frontpage
@FrontpageProduct varchar(30),
@FrontpageDay varchar(30)
AS
SELECT *
FROM Products
LEFT JOIN FrontPage ON
Products.Code = @FrontpageProduct
WHERE FrontPage.theDay = @FrontPageDay
GO
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Toonman" <to*****@NOSPAMtoonman.com> wrote in message
news:pK********************@news1.news.adelphia.ne t... I'm trying to use a couple of variables in a stored procedure. Things work fine when I hard code the data into the variables and also work fine
when I use the variable in the WHERE clause and hard code data for the other
variable. So, I think I have a syntax problem when trying to use
"FrontPage.@FrontpageProduct" as seen in my example code below. I've
tried many variations... and either get syntax errors or end up with a result
of "no records." If somebody could assist me with the proper syntax for a
"table_name.@variable_name" reference it would be greatly appreciated.
The following procedure is called from a VB/.asp page. It's for a
storefront front page where product codes listed in the table
"FrontPage" are used to pull product data from table "Products."
=============================
CREATE PROCEDURE dbo.frontpage
@FrontpageProduct varchar,
@FrontpageDay varchar
AS
SELECT * FROM Products LEFT JOIN FrontPage ON Products.Code =
FrontPage.@FrontpageProduct WHERE FrontPage.theDay = @FrontPageDay
GO
=============================
Again, thank you in advance for any help.
Dave