这是存储过程,我需要选择 Distinct Records 并以随机顺序显示它们,但我面临一个错误,即选择 Distinct 不能与 newid() 一起使用,那么我该如何解决这个问题?
USE [OtlobODR]
GO
/****** Object: StoredProcedure [OtlobFood].[ListOffersItems] Script Date: 11/18/2012 13:01:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [OtlobFood].[ListOffersItems]
@Fk_CampaignID int
as
select distinct
CampaignID, CampaignOffers.OldPrice
, dbo.ItemSizes.IS_Id,
, dbo.Items.[Item_Description_L2] as Item_Description
, dbo.Items.[Item_Image]
, dbo.Items.[Item_Details]
, dbo.ItemSizes.[IS_Price] as Price
-- if null then it is not a featured meal
, dbo.ProviderItems.[PI_Id] as ProviderItems_PI_ID
, dbo.ItemCategories.[ItemCat_Id]
, dbo.Providers.Provider_Name_L2 as Provider_Name
, dbo.Providers.Provider_Menu_Logo
, dbo.Providers.Provider_Id
FROM Items
INNER JOIN ProviderItems ON Items.Item_Id = ProviderItems.Item_Id
INNER JOIN dbo.ItemSizes ON dbo.Items.Item_Id = dbo.ItemSizes.Item_Id
INNER JOIN CampaignOffers ON CampaignOffers.ItemID = ItemSizes.IS_Id
INNER JOIN dbo.ItemCategories ON dbo.Items.ItemCat_Id = dbo.ItemCategories.ItemCat_Id
INNER JOIN dbo.Providers ON dbo.ProviderItems.Provider_Id = dbo.Providers.Provider_Id
INNER JOIN dbo.Branches ON dbo.Providers.Provider_Id = dbo.Branches.Provider_Id
where Fk_CampaignID=@Fk_CampaignID
group by NEWID(),
CampaignID, CampaignOffers.OldPrice ,
dbo.ItemSizes.IS_Id,
dbo.Items.[Item_Description_L2],
dbo.Items.[Item_Image],
dbo.Items.[Item_Details],
dbo.ItemSizes.IS_Id,
dbo.ItemSizes.[IS_Price] ,
-- if null then it is not a featured meal
dbo.ProviderItems.[PI_Id] ,
dbo.ItemCategories.[ItemCat_Id],
dbo.Providers.Provider_Name_L2,
dbo.Providers.Provider_Menu_Logo
,dbo.Branches.Branch_Id,
dbo.Providers.Provider_Id,CampaignID,CampaignOffers.OldPrice
order by NEWID()