Skip to content

Instantly share code, notes, and snippets.

@darrelmiller
Created November 4, 2011 21:20
Show Gist options
  • Save darrelmiller/1340512 to your computer and use it in GitHub Desktop.
Save darrelmiller/1340512 to your computer and use it in GitHub Desktop.
Atom feed directly from database
WITH XMLNAMESPACES(DEFAULT 'http://www.w3.org/2005/Atom')
SELECT 'Customers' AS 'title',
'' AS 'subtitle',
'http://tavis.net/Customers' AS 'id',
REPLACE(CONVERT(varchar,(SELECT MAX(COALESCE(ModifiedDate,CreatedDate)) FROM tblCustomer), 121),' ','T') + 'Z' AS 'updated',
(SELECT cu.Code AS 'title',
REPLACE(CONVERT(varchar,COALESCE(ModifiedDate,CreatedDate) , 121),' ','T') + 'Z' AS 'updated',
'Darrel Miller' AS 'author/name',
'http://tavis.net/Customer/' + LTRIM(STR(cu.ID)) AS 'id',
(SELECT *
FROM (SELECT 'alternate' AS '@rel',
'http://tavis.net/Customers/1.html' AS '@href'
UNION
SELECT 'edit' AS '@rel',
'http://tavis.net/Customers/1.html' AS '@href') l
FOR XML PATH('link'),type ),
cu.ModifiedDate AS 'updated',
cu.Name AS 'summary'
FROM tblCustomer cu
FOR XML PATH('entry'),type )
FOR XML PATH('feed')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment