SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

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


CREATE PROC [dbo].cs_User_GetOpmlFeedsFolders
	@UserId INT
AS

SELECT 	cfo.FolderName,
	cfe.Title,
	cfe.Url,
	cfe.Link
FROM 	cs_Folder cfo
RIGHT OUTER JOIN cs_FolderFeed cff
  ON cff.FolderId = cfo.FolderId
INNER JOIN cs_Feed cfe
  ON cff.FeedId = cfe.FeedId
  AND cff.UserId = @UserId
ORDER BY cfo.FolderName, cfe.Title


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

GRANT EXECUTE ON [dbo].cs_User_GetOpmlFeedsFolders  TO PUBLIC
GO
