Click here to Skip to main content
15,921,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why give this Error???

SQL
ALTER proc [dbo].[Mysp_selecttop_with_favorite]
@sort bit = 0
as
declare @tt as TABLE 
(
	[CategoryID] [tinyint] NOT NULL,
	[ItemID] [int] NULL,
	[ItemTitle] [nvarchar](4000) NULL,
	[ItemDate] [datetime] NULL,
	[MinutesAgo] [int] NULL,
	[ItemInsertDate] [datetime] NULL,
	[ItemImageMainURL] [varchar](4000) NULL,
	[ItemImageLocalURL] [varchar](4000) NULL,
	[ItemURL] [nvarchar](4000) NULL,
	[ItemDescription] [nvarchar](max) NULL,
	[ExDate] [datetime] NULL
)

INSERT INTO @tt(CategoryID,ItemID,ItemTitle,ItemDate,MinutesAgo,ItemInsertDate,ItemImageMainURL,ItemImageLocalURL,ItemURL,ItemDescription)
execute ('Mysp_CategoryAllFeedsItems_SelectTop')




UPDATE @tt
SET 
[@tt].ItemID=tblFavorite.ItemID,
[@tt].ItemTitle = tblFavorite.ItemTitle,
[@tt].ItemDate=tblFavorite.ItemInsertDate,
[@tt].MinutesAgo=tblFavorite.MinutesAgo,
[@tt].ItemInsertDate=tblFavorite.ItemInsertDate,
[@tt].ItemImageMainURL=tblFavorite.ItemImageMainURL,
[@tt].ItemImageLocalURL=tblFavorite.ItemImageLocalURL,
[@tt].ItemURL=tblFavorite.ItemURL,
[@tt].ItemDescription=tblFavorite.ItemDescription
FROM tblFavorite  
WHERE
[@tt].CategoryID = tblFavorite.CategoryID AND (DATEDIFF(minute, tblFavorite.ExDate, GETDATE())) <=0



select case(@sort)
when 0 then  (SElect top 4 * from @tt order by CategoryID asc)
when 1 then  (SElect top 4 * from @tt order by CategoryID desc)
end
Posted
Comments
_Asif_ 1-Jul-14 1:23am    
On which line you getting this problem?

1 solution

Hi,

That's because the CASE statement can return only one value, not multiple values.

Instead of this:
SQL
select case(@sort)
when 0 then  (SElect top 4 * from @tt order by CategoryID asc)
when 1 then  (SElect top 4 * from @tt order by CategoryID desc)
end

Try this:
SQL
if (@sort = 0)
   select top 4 * from @tt order by CategoryID asc
else
   select top 4 * from @tt order by CategoryID desc
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900