SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[cs_Feed_GetProperties]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[cs_Feed_GetProperties]
GO

CREATE PROC [dbo].cs_Feed_GetProperties
	@FeedId INT
AS


SELECT 	cf.Url,
	cf.Title,
	cf.Link,
	cf.Language,
	cf.Generator,
	cf.SubscribeDate,
	cf.LastUpdateDate,
	cfs.StateName,
	cfs.Description,
	[SubscribeCount] = (SELECT COUNT(*) FROM cs_FolderFeed WHERE FeedId = cf.FeedId),
	[PostCount] = (SELECT COUNT(*) FROM cs_FeedPost WHERE FeedId = cf.FeedId)
FROM 	cs_Feed cf,
	cs_FeedState cfs
WHERE cf.FeedStateId = cfs.FeedStateId
  AND cf.FeedId = @FeedId


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

GRANT EXECUTE ON [dbo].cs_Feed_GetProperties  TO PUBLIC
GO
