Sql TableToString Eg.
-------------------------------------------------------------------------
CREATE PROC usp_GetALLProductsByCategory
(
@catid INT -- try by changing to varchar and passing whole list as '2,4,5,1' etc.
)
AS -- usp_GetALLProductsByCategory '2'
BEGIN
SELECT ID,prodname,catID as CategoryCommaSeparated,
[dbo].[TableToString](catID) as FullCategoryNames
FROM tblprod
WHERE EXISTS (select entry from [ListToTable](tblprod.catID) WHERE entry=@catid)
ORDER BY ID DESC
END
--------------------------------------------------------------------------
//Changes to be made in [dbo].[TableToString]
DECLARE @pages varchar(200)
SELECT @pages = COALESCE(@pages + ', ', '') + convert( varchar(50),catname)FROM
(
select catname from tblcat,
(select entry from [dbo].[ListToTable](@mylist)) newtable
where tblcat.ID=cast (newtable.entry as bigint)
) as new
return @pages
-------------------------------------------------------------------------
CREATE PROC usp_GetALLProductsByCategory
(
@catid INT -- try by changing to varchar and passing whole list as '2,4,5,1' etc.
)
AS -- usp_GetALLProductsByCategory '2'
BEGIN
SELECT ID,prodname,catID as CategoryCommaSeparated,
[dbo].[TableToString](catID) as FullCategoryNames
FROM tblprod
WHERE EXISTS (select entry from [ListToTable](tblprod.catID) WHERE entry=@catid)
ORDER BY ID DESC
END
--------------------------------------------------------------------------
//Changes to be made in [dbo].[TableToString]
DECLARE @pages varchar(200)
SELECT @pages = COALESCE(@pages + ', ', '') + convert( varchar(50),catname)FROM
(
select catname from tblcat,
(select entry from [dbo].[ListToTable](@mylist)) newtable
where tblcat.ID=cast (newtable.entry as bigint)
) as new
return @pages
0 comments:
Post a Comment