I am trying to fix a stored procedure that someone else wrote. Basically the proc takes an input value for GroupingCode and queries the rest of the tables based on that grouping code.
However it keeps returning null values. Here is the original stored proc:
ALTER PROCEDURE [dbo].[GetWebinars] (@GroupingCode VARCHAR(MAX) = 'AVM',
@ItemNumber VARCHAR(MAX) OUT,
@Title VARCHAR(MAX) OUT,
@SubTitle VARCHAR(MAX) OUT,
@ShortDescription VARCHAR(MAX) OUT,
@LongDescription VARCHAR(MAX) OUT,
@ShortImageUrl VARCHAR(MAX) OUT,
@MedImageUrl VARCHAR(MAX) OUT,
@LgImageUrl VARCHAR(MAX) OUT,
@GroupCode VARCHAR(MAX) OUT)
AS
SELECT @ItemNumber = prd.itemnumber,
@GroupingCode = prdtemp.groupingcode,
@Title = t.brochuredesc,
@SubTitle = prdtemp.SubTitle,
@ShortDescription = prdtemp.shortdescription,
@LongDescription = prdtemp.longdescription,
@ShortImageUrl = prdtemp.SmallImagePath,
@MedImageUrl = prdtemp.MediumImagePath,
@LgImageUrl = prdtemp.LargeImagePath
FROM pryor_producttemplate prdtemp
INNER JOIN pryor_prdItmmst prd
ON prdtemp.groupingcode = prd.groupcode
INNER JOIN pryor_topics t
ON prd.itemnumber = t.topiccode
WHERE prdtemp.groupingcode = @GroupingCode
AND t.country = 'U.S.A'
SELECT DISTINCT t.city,
t.country,
t.controlprice,
prd.itemnumber
FROM pryor_producttemplate prdtemp
INNER JOIN pryor_prdItmmst prd
ON prdtemp.groupingcode = prd.groupcode
INNER JOIN pryor_topics t
ON prd.itemnumber = t.topiccode
WHERE prdtemp.groupingcode = @GroupingCode
AND t.country = 'U.S.A'
I changed the first line and changed
@GroupingCode varchar(max) = 'AVM'
to
@GroupingCode varchar(max),
It seemed weird to me that the input value would be hard coded.
Anyway after making the change and executing the proc again I got null values. Is this proc written correctly?
I apologize if this is hard to read. I am not familiar with Markdown.
Thanks.
Oceantrain
if a value is not being supplied for @GroupingCode, then changing
to
results in @GroupingCode being set to NULL
Might this be the source of your problem?