September 19, 2007 at 5:12 pm
I have an alter function that repeats a value in the itemlist variable. I would like it to appear only once.
Example: plate, can, can, can, fork, knife, spoon
I would like this to read:
Example: plate, can, fork, knife, spoon
Any suggestions? My alter function is as follow:
set
ANSI_NULLS ON
set
QUOTED_IDENTIFIER ON
GO
ALTER
FUNCTION [dbo].[GetSpecialsInCase]
(
@TCaseId varchar
(25)
)
RETURNS VARCHAR
(2000)
AS
BEGIN
DECLARE
@itemList VARCHAR(8000)
SELECT
@itemList = IsNull(@itemlist + ', ' + char(13), space (0)) + SpecialsDesc
From
CaseToSpecialsMapping, SpecialsDesc
where
CaseToSpecialsMapping.SpecialsId = SpecialsDesc.SpecialsId
and
CaseToSpecialsMapping.TCaseId = @TCaseId
and
specials_outcome = 1
RETURN
@itemList
END
September 19, 2007 at 6:09 pm
Something like this will work...
ALTER FUNCTION [dbo].[GetSpecialsInCase] ( @TCaseId varchar(25) ) RETURNS VARCHAR(2000) AS BEGIN DECLARE @itemList VARCHAR(8000) SELECT @itemList = IsNull(@itemlist + ', ' + char(13), space (0)) + d.SpecialsDesc FROM (--=== Derived table "d" finds correct distinct SpecialsDesc SELECT DISTINCT SpecialsDesc From CaseToSpecialsMapping, SpecialsDesc where CaseToSpecialsMapping.SpecialsId = SpecialsDesc.SpecialsId and CaseToSpecialsMapping.TCaseId = @TCaseId and specials_outcome = 1 ) d
RETURN @itemList END
--Jeff Moden
Change is inevitable... Change for the better is not.
September 20, 2007 at 9:42 am
Thank you. It worked great.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply