<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Footprints in the snow of a warped mind - SQL</title>
    <link>http://blogs.thesitedoctor.co.uk/test/</link>
    <description>newtelligence powered</description>
    <language>en-us</language>
    <copyright>Tim</copyright>
    <lastBuildDate>Tue, 14 Dec 2010 12:46:42 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>timgaunt@gmail.com</managingEditor>
    <webMaster>timgaunt@gmail.com</webMaster>
    <item>
      <trackback:ping>http://blogs.thesitedoctor.co.uk/test/Trackback.aspx?guid=06a7ede9-ec1f-417c-b460-9487f269a078</trackback:ping>
      <pingback:server>http://blogs.thesitedoctor.co.uk/test/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.thesitedoctor.co.uk/test/PermaLink,guid,06a7ede9-ec1f-417c-b460-9487f269a078.aspx</pingback:target>
      <dc:creator>Tim</dc:creator>
      <wfw:comment>http://blogs.thesitedoctor.co.uk/test/CommentView,guid,06a7ede9-ec1f-417c-b460-9487f269a078.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.thesitedoctor.co.uk/test/SyndicationService.asmx/GetEntryCommentsRss?guid=06a7ede9-ec1f-417c-b460-9487f269a078</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top: 0px; border-right: 0px; padding-top: 0px" title="error[2]" border="0" alt="error[2]" align="right" src="http://blogs.thesitedoctor.co.uk/tim/images/616c06524d21_ABF1/error2.png" width="260" height="260" />We
were contacted the other day by a client with issues selecting data from one of their
tables after a recent server crash (not running on our servers or a site that we were
involved in developing). The issue was easy enough to recreate as you just needed
to select records after the server crash and you'd get the error:
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:066de93b-0bfa-4bff-ab25-4f6d104e0588" class="wlWriterEditableSmartContent">
          <pre class="brush: text;">Warning: Fatal error 823 occurred at date / time Note the error and time, and contact your system administrator.</pre>
        </div>
        <p>
A quick Google suggests a physical disk drive error and having a quick look at the
issues it wasn't pretty. Running:
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:4ef19624-c777-4d57-b382-bf4757d70a3a" class="wlWriterEditableSmartContent">
          <pre class="brush: sql;">DBCC CHECKDB('DatabaseName') WITH NO_INFOMSGS, ALL_ERRORMSGS</pre>
        </div>
        <p>
Resulted in:
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:5aa36243-c2a8-4d90-bb96-b88e4bdf61a9" class="wlWriterEditableSmartContent">
          <pre class="brush: xml;">Msg 8909, Level 16, State 1, Line 5 
Table error: Object ID 0, index ID 12341, page ID (1:5880). The PageId in the page header = (9728:16777220). 
CHECKTABLE found 0 allocation errors and 1 consistency errors not associated with any single object. 


....


DBCC results for 'TableName'. 
Msg 8928, Level 16, State 1, Line 5 
Object ID 871674153, index ID 0: Page (1:5880) could not be processed. See other errors for details. 


....


There are 20993 rows in 584 pages for object 'TableName'. 
CHECKTABLE found 0 allocation errors and 8 consistency errors in table 'TableName' (object ID 871674153). 
Msg 8909, Level 16, State 1, Line 5 
Table error: Object ID 1109413712, index ID 24940, page ID (1:5883). The PageId in the page header = (25198:1632843825). 
CHECKTABLE found 0 allocation errors and 1 consistency errors in table '(Object ID 1109413712)' (object ID 1109413712). </pre>
        </div>
        <p>
Most of the solutions found on Google resulted in some form of system restore but
that's no good in this instance as the backups only existed for after the problem
was identified (great eh!) so were useless.
</p>
        <p>
Although it's not an ideal solution, you can use DBCC CHECKTABLE which in our case
fixed the issue:
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:7aaaa196-804c-4161-afb0-12132fca51e1" class="wlWriterEditableSmartContent">
          <pre class="brush: sql;">--Put the database into single user mode
ALTER DATABASE [db2370] SET SINGLE_USER WITH NO_WAIT
--Check the erors and fix any issues found (that you can)
DBCC CHECKTABLE ('Orders', REPAIR_REBUILD)
--Put the database back into multiuser mode
ALTER DATABASE [db2370] SET MULTI_USER WITH NO_WAIT</pre>
        </div>
        <p>
 
</p>
        <p>
I'd be interested to know other solutions people may have to this issue.
</p>
        <p>
          <strong>Note to readers:</strong> Check that your hosting provider performs regular
backups and checks the health of your server regularly to avoid this happening to
you.
</p>
        <img width="0" height="0" src="http://blogs.thesitedoctor.co.uk/test/aggbug.ashx?id=06a7ede9-ec1f-417c-b460-9487f269a078" />
      </body>
      <title>SQL Server: Warning: Fatal error 823 occurred at date / time Note the error and time, and contact your system administrator.</title>
      <guid isPermaLink="false">http://blogs.thesitedoctor.co.uk/test/PermaLink,guid,06a7ede9-ec1f-417c-b460-9487f269a078.aspx</guid>
      <link>http://blogs.thesitedoctor.co.uk/test/2010/12/14/SQLServerWarningFatalError823OccurredAtDateTimeNoteTheErrorAndTimeAndContactYourSystemAdministrator.aspx</link>
      <pubDate>Tue, 14 Dec 2010 12:46:42 GMT</pubDate>
      <description>&lt;p&gt;
&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top: 0px; border-right: 0px; padding-top: 0px" title="error[2]" border="0" alt="error[2]" align="right" src="http://blogs.thesitedoctor.co.uk/tim/images/616c06524d21_ABF1/error2.png" width="260" height="260" /&gt;We
were contacted the other day by a client with issues selecting data from one of their
tables after a recent server crash (not running on our servers or a site that we were
involved in developing). The issue was easy enough to recreate as you just needed
to select records after the server crash and you'd get the error:
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:066de93b-0bfa-4bff-ab25-4f6d104e0588" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: text;"&gt;Warning: Fatal error 823 occurred at date / time Note the error and time, and contact your system administrator.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
A quick Google suggests a physical disk drive error and having a quick look at the
issues it wasn't pretty. Running:
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:4ef19624-c777-4d57-b382-bf4757d70a3a" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: sql;"&gt;DBCC CHECKDB('DatabaseName') WITH NO_INFOMSGS, ALL_ERRORMSGS&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
Resulted in:
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:5aa36243-c2a8-4d90-bb96-b88e4bdf61a9" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: xml;"&gt;Msg 8909, Level 16, State 1, Line 5 
Table error: Object ID 0, index ID 12341, page ID (1:5880). The PageId in the page header = (9728:16777220). 
CHECKTABLE found 0 allocation errors and 1 consistency errors not associated with any single object. 


....


DBCC results for 'TableName'. 
Msg 8928, Level 16, State 1, Line 5 
Object ID 871674153, index ID 0: Page (1:5880) could not be processed. See other errors for details. 


....


There are 20993 rows in 584 pages for object 'TableName'. 
CHECKTABLE found 0 allocation errors and 8 consistency errors in table 'TableName' (object ID 871674153). 
Msg 8909, Level 16, State 1, Line 5 
Table error: Object ID 1109413712, index ID 24940, page ID (1:5883). The PageId in the page header = (25198:1632843825). 
CHECKTABLE found 0 allocation errors and 1 consistency errors in table '(Object ID 1109413712)' (object ID 1109413712). &lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
Most of the solutions found on Google resulted in some form of system restore but
that's no good in this instance as the backups only existed for after the problem
was identified (great eh!) so were useless.
&lt;/p&gt;
&lt;p&gt;
Although it's not an ideal solution, you can use DBCC CHECKTABLE which in our case
fixed the issue:
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:7aaaa196-804c-4161-afb0-12132fca51e1" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: sql;"&gt;--Put the database into single user mode
ALTER DATABASE [db2370] SET SINGLE_USER WITH NO_WAIT
--Check the erors and fix any issues found (that you can)
DBCC CHECKTABLE ('Orders', REPAIR_REBUILD)
--Put the database back into multiuser mode
ALTER DATABASE [db2370] SET MULTI_USER WITH NO_WAIT&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
I'd be interested to know other solutions people may have to this issue.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Note to readers:&lt;/strong&gt; Check that your hosting provider performs regular
backups and checks the health of your server regularly to avoid this happening to
you.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.thesitedoctor.co.uk/test/aggbug.ashx?id=06a7ede9-ec1f-417c-b460-9487f269a078" /&gt;</description>
      <comments>http://blogs.thesitedoctor.co.uk/test/CommentView,guid,06a7ede9-ec1f-417c-b460-9487f269a078.aspx</comments>
      <category>Server Maintenance</category>
      <category>Server Management</category>
      <category>SQL</category>
      <category>SQL Server</category>
    </item>
    <item>
      <trackback:ping>http://blogs.thesitedoctor.co.uk/test/Trackback.aspx?guid=3c783a9f-6450-4b6b-a372-5bb8c9ca109f</trackback:ping>
      <pingback:server>http://blogs.thesitedoctor.co.uk/test/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.thesitedoctor.co.uk/test/PermaLink,guid,3c783a9f-6450-4b6b-a372-5bb8c9ca109f.aspx</pingback:target>
      <dc:creator>Tim</dc:creator>
      <wfw:comment>http://blogs.thesitedoctor.co.uk/test/CommentView,guid,3c783a9f-6450-4b6b-a372-5bb8c9ca109f.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.thesitedoctor.co.uk/test/SyndicationService.asmx/GetEntryCommentsRss?guid=3c783a9f-6450-4b6b-a372-5bb8c9ca109f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://blogs.thesitedoctor.co.uk/tim/images/Download-any-document-types-values-as-cr_ECF7/image.png" width="320" height="260" />In
a follow up to my post yesterday -<a href="http://blogs.thesitedoctor.co.uk/tim/2010/11/08/Download+Umbraco+Content+Properties+Into+A+Crosstab+Table.aspx" target="_blank">How
to download Umbraco content properties into a crosstab table</a> this is the follow
up SQL Script that makes it even easier to download any Umbraco document type into
Excel.
</p>
        <p>
This SQL Script is fairly simple, basically what it does is it gets the properties
associated with the specified document type and then pivots the values so you end
up with a table of data that looks like this:
</p>
        <table border="0" cellspacing="0" cellpadding="2">
          <thead>
            <tr>
              <th valign="top" width="20">
Id</th>
              <th valign="top" width="20">
Property 1</th>
              <th valign="top" width="20">
Property 2</th>
              <th valign="top" width="20">
Property 3</th>
              <th valign="top" width="237">
Property n</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td valign="top" width="20">
123</td>
              <td valign="top" width="20">
String</td>
              <td valign="top" width="20">
Int</td>
              <td valign="top" width="20">
Date</td>
              <td valign="top" width="237">
xxx</td>
            </tr>
          </tbody>
        </table>
        <h2>How to use the script
</h2>
        <p>
All you need to do is set the parameter "@ContentTypeId" to the document type you
want (as in my <a href="http://blogs.thesitedoctor.co.uk/tim/2010/11/08/Download+Umbraco+Content+Properties+Into+A+Crosstab+Table.aspx" target="_blank">previous
post</a> you can get this by checking out the link on the document type).
</p>
        <p>
Once you set the id, just run the script and voila there's the data.
</p>
        <p>
If you run the code and get "Command(s) completed successfully" then you've not set
the id right so double check and try again.
</p>
        <h2>The Script
</h2>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:40c53f65-8da0-43c3-ba9d-5f15451a170e" class="wlWriterEditableSmartContent">
          <pre class="brush: sql;">DECLARE @cols NVARCHAR(max), @ContentTypeId int
SET @ContentTypeId = 1074

SELECT  @cols = STUFF(( 
	SELECT DISTINCT TOP 100 PERCENT
        '],[' 
        + CONVERT(varchar, Name + ' (' + CONVERT(varchar, id) + ')', 255)
    FROM
		dbo.cmsPropertyType
	WHERE
		contentTypeId = @ContentTypeId
    ORDER BY
        '],[' 
        + CONVERT(varchar, Name + ' (' + CONVERT(varchar, id) + ')', 255)
    FOR XML PATH('')
), 1, 2, '') + ']'
--SELECT  @cols

DECLARE @query NVARCHAR(max)
SET @query = N'SELECT Id, ' + @cols + '
FROM
  (
		SELECT
			CONVERT(varchar, t.Name + '' ('' + CONVERT(varchar, t.id) + '')'', 255) As [PropId],
			contentNodeId As [Id],
			ISNULL(dataNvarchar, ISNULL(CONVERT(varchar, dataDate), ISNULL(CONVERT(varchar, dataInt), dataNtext))) As [Value]
		FROM
			dbo.cmsPropertyType t LEFT JOIN dbo.cmsPropertyData d ON t.id = d.propertytypeid
		WHERE
			contentTypeId = ' + CONVERT(varchar, @ContentTypeId) + ' 
) p
PIVOT
(
	MAX(Value) 
	FOR PropId IN ( '+ @cols +' )
) AS pvt
ORDER BY Id ASC'

--PRINT(@query)
EXECUTE(@query)</pre>
        </div>
        <img width="0" height="0" src="http://blogs.thesitedoctor.co.uk/test/aggbug.ashx?id=3c783a9f-6450-4b6b-a372-5bb8c9ca109f" />
      </body>
      <title>Download any Umbraco document type’s values as crosstab/Excel table</title>
      <guid isPermaLink="false">http://blogs.thesitedoctor.co.uk/test/PermaLink,guid,3c783a9f-6450-4b6b-a372-5bb8c9ca109f.aspx</guid>
      <link>http://blogs.thesitedoctor.co.uk/test/2010/11/09/DownloadAnyUmbracoDocumentTypesValuesAsCrosstabExcelTable.aspx</link>
      <pubDate>Tue, 09 Nov 2010 21:16:24 GMT</pubDate>
      <description>&lt;p&gt;
&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://blogs.thesitedoctor.co.uk/tim/images/Download-any-document-types-values-as-cr_ECF7/image.png" width="320" height="260" /&gt;In
a follow up to my post yesterday -&lt;a href="http://blogs.thesitedoctor.co.uk/tim/2010/11/08/Download+Umbraco+Content+Properties+Into+A+Crosstab+Table.aspx" target="_blank"&gt;How
to download Umbraco content properties into a crosstab table&lt;/a&gt; this is the follow
up SQL Script that makes it even easier to download any Umbraco document type into
Excel.
&lt;/p&gt;
&lt;p&gt;
This SQL Script is fairly simple, basically what it does is it gets the properties
associated with the specified document type and then pivots the values so you end
up with a table of data that looks like this:
&lt;/p&gt;
&lt;table border="0" cellspacing="0" cellpadding="2"&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th valign="top" width="20"&gt;
Id&lt;/th&gt;
&lt;th valign="top" width="20"&gt;
Property 1&lt;/th&gt;
&lt;th valign="top" width="20"&gt;
Property 2&lt;/th&gt;
&lt;th valign="top" width="20"&gt;
Property 3&lt;/th&gt;
&lt;th valign="top" width="237"&gt;
Property n&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="20"&gt;
123&lt;/td&gt;
&lt;td valign="top" width="20"&gt;
String&lt;/td&gt;
&lt;td valign="top" width="20"&gt;
Int&lt;/td&gt;
&lt;td valign="top" width="20"&gt;
Date&lt;/td&gt;
&lt;td valign="top" width="237"&gt;
xxx&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;How to use the script
&lt;/h2&gt;
&lt;p&gt;
All you need to do is set the parameter "@ContentTypeId" to the document type you
want (as in my &lt;a href="http://blogs.thesitedoctor.co.uk/tim/2010/11/08/Download+Umbraco+Content+Properties+Into+A+Crosstab+Table.aspx" target="_blank"&gt;previous
post&lt;/a&gt; you can get this by checking out the link on the document type).
&lt;/p&gt;
&lt;p&gt;
Once you set the id, just run the script and voila there's the data.
&lt;/p&gt;
&lt;p&gt;
If you run the code and get "Command(s) completed successfully" then you've not set
the id right so double check and try again.
&lt;/p&gt;
&lt;h2&gt;The Script
&lt;/h2&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:40c53f65-8da0-43c3-ba9d-5f15451a170e" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: sql;"&gt;DECLARE @cols NVARCHAR(max), @ContentTypeId int
SET @ContentTypeId = 1074

SELECT  @cols = STUFF(( 
	SELECT DISTINCT TOP 100 PERCENT
        '],[' 
        + CONVERT(varchar, Name + ' (' + CONVERT(varchar, id) + ')', 255)
    FROM
		dbo.cmsPropertyType
	WHERE
		contentTypeId = @ContentTypeId
    ORDER BY
        '],[' 
        + CONVERT(varchar, Name + ' (' + CONVERT(varchar, id) + ')', 255)
    FOR XML PATH('')
), 1, 2, '') + ']'
--SELECT  @cols

DECLARE @query NVARCHAR(max)
SET @query = N'SELECT Id, ' + @cols + '
FROM
  (
		SELECT
			CONVERT(varchar, t.Name + '' ('' + CONVERT(varchar, t.id) + '')'', 255) As [PropId],
			contentNodeId As [Id],
			ISNULL(dataNvarchar, ISNULL(CONVERT(varchar, dataDate), ISNULL(CONVERT(varchar, dataInt), dataNtext))) As [Value]
		FROM
			dbo.cmsPropertyType t LEFT JOIN dbo.cmsPropertyData d ON t.id = d.propertytypeid
		WHERE
			contentTypeId = ' + CONVERT(varchar, @ContentTypeId) + ' 
) p
PIVOT
(
	MAX(Value) 
	FOR PropId IN ( '+ @cols +' )
) AS pvt
ORDER BY Id ASC'

--PRINT(@query)
EXECUTE(@query)&lt;/pre&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://blogs.thesitedoctor.co.uk/test/aggbug.ashx?id=3c783a9f-6450-4b6b-a372-5bb8c9ca109f" /&gt;</description>
      <comments>http://blogs.thesitedoctor.co.uk/test/CommentView,guid,3c783a9f-6450-4b6b-a372-5bb8c9ca109f.aspx</comments>
      <category>SQL</category>
      <category>SQL Server</category>
      <category>The Site Doctor</category>
      <category>Umbraco</category>
      <category>Web Development</category>
    </item>
    <item>
      <trackback:ping>http://blogs.thesitedoctor.co.uk/test/Trackback.aspx?guid=b9a65412-9eeb-411a-b5b3-174acfd3be95</trackback:ping>
      <pingback:server>http://blogs.thesitedoctor.co.uk/test/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.thesitedoctor.co.uk/test/PermaLink,guid,b9a65412-9eeb-411a-b5b3-174acfd3be95.aspx</pingback:target>
      <dc:creator>Tim</dc:creator>
      <wfw:comment>http://blogs.thesitedoctor.co.uk/test/CommentView,guid,b9a65412-9eeb-411a-b5b3-174acfd3be95.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.thesitedoctor.co.uk/test/SyndicationService.asmx/GetEntryCommentsRss?guid=b9a65412-9eeb-411a-b5b3-174acfd3be95</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Have you ever needed to get a download of your Umbraco content nodes in a cross-tab
query e.g. download contact form data from Doc2Form? Using Umbraco's Contour product
makes this a breeze but what about older systems? Thankfully, it's not actually that
difficult.
</p>
        <p>
We have a contact us form on one of our sites which uses an old version of Doc2Form
which emails the customer details of the enquiry. One benefit is it also saves it
to the recycle bin as a document with the name: "RE: SYSTEM DATA: umbraco master root".
With that in mind, we can use SQL Server's PIVOT functionality to pull the data out
in a nicely formatted manner.
</p>
        <p>
Firstly you'll need to know the id's of the document type's properties, there are
numerous ways to do this:
</p>
        <h4>1. Just look at the cmsPropertyData table for a couple of content nodes (I could
spot the ones I was after fairly easily)
</h4>
        <h4> 
</h4>
        <h4>2. Query the cmsPropertyType table:
</h4>
        <p>
Find the contentTypeId of the document type -you can do this by hovering your mouse
over the document type in the tree and checking out the status bar (you can see the
contentTypeId in brackets in the bottom left -mine here is 1074):
</p>
        <p>
          <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.thesitedoctor.co.uk/tim/images/Download-Doc2Form-submissions-into-a-cro_E327/image.png" width="380" height="193" />
        </p>
        <p>
Once you have the contentTypeId of the document type, you can then get the ids of
all the properties you're after by replacing "xxx" with your property id in the following
script:
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:71eda8ba-092a-44b9-b9fc-6a45ae1d9b07" class="wlWriterEditableSmartContent">
          <pre class="brush: sql;">SELECT * FROM dbo.cmsPropertyType WHERE contentTypeId = xxx</pre>
        </div>
        <h4>3. Get it from the source of the document type editor
</h4>
        <p>
An alternative way is to examine the HTML of the Document Type editor. If you view
the source on the "Generic Properties" tab and scroll to the section you're interested
in (there'll be a h2 with the same name) you will find a ul that has the class of
"genericPropertyList".
</p>
        <p>
Each li of that ul will have the relevant id as part of it's id e.g. for a section
called "Enquiry Form" the id will be: "EnquiryFormContents_49" where "49" is the id
we're interested in. You can see mine (49, 50, 51 and 52 below):
</p>
        <p>
          <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.thesitedoctor.co.uk/tim/images/Download-Doc2Form-submissions-into-a-cro_E327/image_3.png" width="704" height="186" />
        </p>
        <p>
Once you have these ids to hand (mine were 49, 50, 51 and 52) you just need to update
the code below and run against your Umbraco database:
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:2f63fc8a-d1ea-42b9-b6ef-f5a410c9b989" class="wlWriterEditableSmartContent">
          <pre class="brush: sql;">SELECT
	contentNodeId As [Id], 
	[49] As [Name], 
	[50] As [Telephone], 
	[51] As [Email Address], 
	[52] As [Notes]
FROM
(
	SELECT contentNodeId, propertytypeid, ISNULL(dataNvarchar, dataNtext) As [Value]
	FROM dbo.cmsPropertyData
) As src
PIVOT (
	MAX(Value) 
	FOR propertytypeid in ([49], [50], [51], [52])
) aS pvt
WHERE [50] IS NOT NULL OR [51] IS NOT NULL
ORDER BY contentNodeId</pre>
        </div>
        <p>
 
</p>
        <p>
That will then produce some lovely formatted data for you, my example above produced:
</p>
        <table border="0" cellspacing="0" cellpadding="2">
          <thead>
            <tr>
              <th valign="top" width="100">
Id</th>
              <th valign="top" width="100">
Name</th>
              <th valign="top" width="100">
Telephone</th>
              <th valign="top" width="100">
Email Address</th>
              <th valign="top" width="100">
Notes</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td valign="top" width="100">
1154</td>
              <td valign="top" width="100">
Example</td>
              <td valign="top" width="100">
01234567890</td>
              <td valign="top" width="100">
                <a href="mailto:test@test.com">test@test.com</a>
              </td>
              <td valign="top" width="100">
Please contact me as soon as possible about your great site, thanks.</td>
            </tr>
          </tbody>
        </table>
        <p>
 
</p>
        <p>
It's also possible to automate this entire script so you don't need to find out the
property ids, I'll post that separately.
</p>
        <img width="0" height="0" src="http://blogs.thesitedoctor.co.uk/test/aggbug.ashx?id=b9a65412-9eeb-411a-b5b3-174acfd3be95" />
      </body>
      <title>Download Umbraco content properties into a crosstab table</title>
      <guid isPermaLink="false">http://blogs.thesitedoctor.co.uk/test/PermaLink,guid,b9a65412-9eeb-411a-b5b3-174acfd3be95.aspx</guid>
      <link>http://blogs.thesitedoctor.co.uk/test/2010/11/08/DownloadUmbracoContentPropertiesIntoACrosstabTable.aspx</link>
      <pubDate>Mon, 08 Nov 2010 16:37:19 GMT</pubDate>
      <description>&lt;p&gt;
Have you ever needed to get a download of your Umbraco content nodes in a cross-tab
query e.g. download contact form data from Doc2Form? Using Umbraco's Contour product
makes this a breeze but what about older systems? Thankfully, it's not actually that
difficult.
&lt;/p&gt;
&lt;p&gt;
We have a contact us form on one of our sites which uses an old version of Doc2Form
which emails the customer details of the enquiry. One benefit is it also saves it
to the recycle bin as a document with the name: "RE: SYSTEM DATA: umbraco master root".
With that in mind, we can use SQL Server's PIVOT functionality to pull the data out
in a nicely formatted manner.
&lt;/p&gt;
&lt;p&gt;
Firstly you'll need to know the id's of the document type's properties, there are
numerous ways to do this:
&lt;/p&gt;
&lt;h4&gt;1. Just look at the cmsPropertyData table for a couple of content nodes (I could
spot the ones I was after fairly easily)
&lt;/h4&gt;
&lt;h4&gt;&amp;#160;
&lt;/h4&gt;
&lt;h4&gt;2. Query the cmsPropertyType table:
&lt;/h4&gt;
&lt;p&gt;
Find the contentTypeId of the document type -you can do this by hovering your mouse
over the document type in the tree and checking out the status bar (you can see the
contentTypeId in brackets in the bottom left -mine here is 1074):
&lt;/p&gt;
&lt;p&gt;
&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.thesitedoctor.co.uk/tim/images/Download-Doc2Form-submissions-into-a-cro_E327/image.png" width="380" height="193" /&gt;
&lt;/p&gt;
&lt;p&gt;
Once you have the contentTypeId of the document type, you can then get the ids of
all the properties you're after by replacing "xxx" with your property id in the following
script:
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:71eda8ba-092a-44b9-b9fc-6a45ae1d9b07" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: sql;"&gt;SELECT * FROM dbo.cmsPropertyType WHERE contentTypeId = xxx&lt;/pre&gt;
&lt;/div&gt;
&lt;h4&gt;3. Get it from the source of the document type editor
&lt;/h4&gt;
&lt;p&gt;
An alternative way is to examine the HTML of the Document Type editor. If you view
the source on the "Generic Properties" tab and scroll to the section you're interested
in (there'll be a h2 with the same name) you will find a ul that has the class of
"genericPropertyList".
&lt;/p&gt;
&lt;p&gt;
Each li of that ul will have the relevant id as part of it's id e.g. for a section
called "Enquiry Form" the id will be: "EnquiryFormContents_49" where "49" is the id
we're interested in. You can see mine (49, 50, 51 and 52 below):
&lt;/p&gt;
&lt;p&gt;
&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.thesitedoctor.co.uk/tim/images/Download-Doc2Form-submissions-into-a-cro_E327/image_3.png" width="704" height="186" /&gt;
&lt;/p&gt;
&lt;p&gt;
Once you have these ids to hand (mine were 49, 50, 51 and 52) you just need to update
the code below and run against your Umbraco database:
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:2f63fc8a-d1ea-42b9-b6ef-f5a410c9b989" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: sql;"&gt;SELECT
	contentNodeId As [Id], 
	[49] As [Name], 
	[50] As [Telephone], 
	[51] As [Email Address], 
	[52] As [Notes]
FROM
(
	SELECT contentNodeId, propertytypeid, ISNULL(dataNvarchar, dataNtext) As [Value]
	FROM dbo.cmsPropertyData
) As src
PIVOT (
	MAX(Value) 
	FOR propertytypeid in ([49], [50], [51], [52])
) aS pvt
WHERE [50] IS NOT NULL OR [51] IS NOT NULL
ORDER BY contentNodeId&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
That will then produce some lovely formatted data for you, my example above produced:
&lt;/p&gt;
&lt;table border="0" cellspacing="0" cellpadding="2"&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th valign="top" width="100"&gt;
Id&lt;/th&gt;
&lt;th valign="top" width="100"&gt;
Name&lt;/th&gt;
&lt;th valign="top" width="100"&gt;
Telephone&lt;/th&gt;
&lt;th valign="top" width="100"&gt;
Email Address&lt;/th&gt;
&lt;th valign="top" width="100"&gt;
Notes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="100"&gt;
1154&lt;/td&gt;
&lt;td valign="top" width="100"&gt;
Example&lt;/td&gt;
&lt;td valign="top" width="100"&gt;
01234567890&lt;/td&gt;
&lt;td valign="top" width="100"&gt;
&lt;a href="mailto:test@test.com"&gt;test@test.com&lt;/a&gt;&lt;/td&gt;
&lt;td valign="top" width="100"&gt;
Please contact me as soon as possible about your great site, thanks.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
It's also possible to automate this entire script so you don't need to find out the
property ids, I'll post that separately.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.thesitedoctor.co.uk/test/aggbug.ashx?id=b9a65412-9eeb-411a-b5b3-174acfd3be95" /&gt;</description>
      <comments>http://blogs.thesitedoctor.co.uk/test/CommentView,guid,b9a65412-9eeb-411a-b5b3-174acfd3be95.aspx</comments>
      <category>Development</category>
      <category>SQL</category>
      <category>SQL Server</category>
      <category>Umbraco</category>
    </item>
    <item>
      <trackback:ping>http://blogs.thesitedoctor.co.uk/test/Trackback.aspx?guid=24a92c7d-a542-453a-ba32-20d44e192d8a</trackback:ping>
      <pingback:server>http://blogs.thesitedoctor.co.uk/test/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.thesitedoctor.co.uk/test/PermaLink,guid,24a92c7d-a542-453a-ba32-20d44e192d8a.aspx</pingback:target>
      <dc:creator>Tim</dc:creator>
      <wfw:comment>http://blogs.thesitedoctor.co.uk/test/CommentView,guid,24a92c7d-a542-453a-ba32-20d44e192d8a.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.thesitedoctor.co.uk/test/SyndicationService.asmx/GetEntryCommentsRss?guid=24a92c7d-a542-453a-ba32-20d44e192d8a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
After my last <a title="e-commerce package for Umbraco" href="http://www.ucommerce.dk" target="_blank">UCommerce</a> post
on <a href="http://blogs.thesitedoctor.co.uk/tim/2010/10/01/Deleting+Test+Orders+And+Baskets+From+UCommerce.aspx" target="_blank">how
to delete test orders and baskets from UCommerce</a>, Søren suggested I extended the
delete all baskets code to take into account when it was created. As my last code
was relating to deleting test orders/baskets (and so would want to get rid of them
all), I decided to post this one separately.
</p>
        <h2>Delete all baskets older than x days
</h2>
        <p>
To use this, all you need to do is change the @addedBefore parameter to whatever date/time
you want (or just adjust the –7 which represents seven days in the past.
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:45241e23-0c18-443a-941a-ce974b893ca9" class="wlWriterEditableSmartContent">
          <pre class="brush: sql;">--Delete all carts purchaseorders and associated data within x days
DECLARE @addedBefore smalldatetime
--By default the script deletes everything older than 7 days
SET @addedBefore = DATEADD(dd, -7, GETDATE())

BEGIN TRAN

UPDATE uCommerce_PurchaseOrder SET BillingAddressId = NULL WHERE OrderNumber IS NULL AND CreatedDate &lt;= @addedBefore
DELETE a FROM uCommerce_Shipment a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL AND b.CreatedDate &lt;= @addedBefore
DELETE a FROM uCommerce_OrderAddress a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL AND b.CreatedDate &lt;= @addedBefore
DELETE a FROM uCommerce_OrderProperty a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL AND b.CreatedDate &lt;= @addedBefore
DELETE a FROM uCommerce_OrderLine a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL AND b.CreatedDate &lt;= @addedBefore
DELETE a FROM uCommerce_Payment a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL AND b.CreatedDate &lt;= @addedBefore
DELETE a FROM uCommerce_OrderStatusAudit a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL AND b.CreatedDate &lt;= @addedBefore
DELETE FROM uCommerce_PurchaseOrder WHERE OrderNumber IS NULL AND CreatedDate &lt;= @addedBefore

--Uncomment this
--COMMIT TRAN

--And comment out this
ROLLBACK TRAN</pre>
        </div>
        <img width="0" height="0" src="http://blogs.thesitedoctor.co.uk/test/aggbug.ashx?id=24a92c7d-a542-453a-ba32-20d44e192d8a" />
      </body>
      <title>Delete all UCommerce baskets older than x days</title>
      <guid isPermaLink="false">http://blogs.thesitedoctor.co.uk/test/PermaLink,guid,24a92c7d-a542-453a-ba32-20d44e192d8a.aspx</guid>
      <link>http://blogs.thesitedoctor.co.uk/test/2010/10/04/DeleteAllUCommerceBasketsOlderThanXDays.aspx</link>
      <pubDate>Mon, 04 Oct 2010 09:14:31 GMT</pubDate>
      <description>&lt;p&gt;
After my last &lt;a title="e-commerce package for Umbraco" href="http://www.ucommerce.dk" target="_blank"&gt;UCommerce&lt;/a&gt; post
on &lt;a href="http://blogs.thesitedoctor.co.uk/tim/2010/10/01/Deleting+Test+Orders+And+Baskets+From+UCommerce.aspx" target="_blank"&gt;how
to delete test orders and baskets from UCommerce&lt;/a&gt;, Søren suggested I extended the
delete all baskets code to take into account when it was created. As my last code
was relating to deleting test orders/baskets (and so would want to get rid of them
all), I decided to post this one separately.
&lt;/p&gt;
&lt;h2&gt;Delete all baskets older than x days
&lt;/h2&gt;
&lt;p&gt;
To use this, all you need to do is change the @addedBefore parameter to whatever date/time
you want (or just adjust the –7 which represents seven days in the past.
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:45241e23-0c18-443a-941a-ce974b893ca9" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: sql;"&gt;--Delete all carts purchaseorders and associated data within x days
DECLARE @addedBefore smalldatetime
--By default the script deletes everything older than 7 days
SET @addedBefore = DATEADD(dd, -7, GETDATE())

BEGIN TRAN

UPDATE uCommerce_PurchaseOrder SET BillingAddressId = NULL WHERE OrderNumber IS NULL AND CreatedDate &amp;lt;= @addedBefore
DELETE a FROM uCommerce_Shipment a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL AND b.CreatedDate &amp;lt;= @addedBefore
DELETE a FROM uCommerce_OrderAddress a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL AND b.CreatedDate &amp;lt;= @addedBefore
DELETE a FROM uCommerce_OrderProperty a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL AND b.CreatedDate &amp;lt;= @addedBefore
DELETE a FROM uCommerce_OrderLine a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL AND b.CreatedDate &amp;lt;= @addedBefore
DELETE a FROM uCommerce_Payment a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL AND b.CreatedDate &amp;lt;= @addedBefore
DELETE a FROM uCommerce_OrderStatusAudit a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL AND b.CreatedDate &amp;lt;= @addedBefore
DELETE FROM uCommerce_PurchaseOrder WHERE OrderNumber IS NULL AND CreatedDate &amp;lt;= @addedBefore

--Uncomment this
--COMMIT TRAN

--And comment out this
ROLLBACK TRAN&lt;/pre&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://blogs.thesitedoctor.co.uk/test/aggbug.ashx?id=24a92c7d-a542-453a-ba32-20d44e192d8a" /&gt;</description>
      <comments>http://blogs.thesitedoctor.co.uk/test/CommentView,guid,24a92c7d-a542-453a-ba32-20d44e192d8a.aspx</comments>
      <category>Development</category>
      <category>eCommerce</category>
      <category>SQL</category>
      <category>SQL Server</category>
      <category>uCommerce</category>
      <category>Umbraco</category>
    </item>
    <item>
      <trackback:ping>http://blogs.thesitedoctor.co.uk/test/Trackback.aspx?guid=fcd3400c-32cd-4b96-819f-ce4adf0cab19</trackback:ping>
      <pingback:server>http://blogs.thesitedoctor.co.uk/test/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.thesitedoctor.co.uk/test/PermaLink,guid,fcd3400c-32cd-4b96-819f-ce4adf0cab19.aspx</pingback:target>
      <dc:creator>Tim</dc:creator>
      <wfw:comment>http://blogs.thesitedoctor.co.uk/test/CommentView,guid,fcd3400c-32cd-4b96-819f-ce4adf0cab19.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.thesitedoctor.co.uk/test/SyndicationService.asmx/GetEntryCommentsRss?guid=fcd3400c-32cd-4b96-819f-ce4adf0cab19</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Although Søren has posted a helpful post on how to <a href="http://www.publicvoid.dk/DeletingPurchaseOrdersAndBasketsFromTheDatabaseInUCommerce.aspx" target="_blank">delete
entire purchase orders from the database here</a>, we needed something a little less
“all or nothing” so put the below together.
</p>
        <h2>Delete a specific order id
</h2>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:c810ee8f-ccc4-4cc1-a251-bd161573c8f7" class="wlWriterEditableSmartContent">
          <pre class="brush: sql;">--Delete purchaseorders and associated data based on order id
DECLARE @OrderNumber nvarchar(50)
SET @OrderNumber = 'TEST-40'

BEGIN TRAN

UPDATE uCommerce_PurchaseOrder SET BillingAddressId = NULL WHERE OrderNumber = @OrderNumber
DELETE a FROM uCommerce_Shipment a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber
DELETE a FROM uCommerce_OrderAddress a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber
DELETE a FROM uCommerce_OrderProperty a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber
DELETE a FROM uCommerce_OrderLine a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber
DELETE a FROM uCommerce_Payment a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber
DELETE a FROM uCommerce_OrderStatusAudit a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber
DELETE FROM uCommerce_PurchaseOrder WHERE OrderNumber = @OrderNumber

--TODO: Expand this so it checks for other orders
--DELETE a FROM uCommerce_Address a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber
--DELETE a FROM uCommerce_Customer a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber

--Uncomment this
--COMMIT TRAN

--And comment out this
ROLLBACK TRAN</pre>
        </div>
        <br />
        <p>
 
</p>
        <p>
 
</p>
        <h2>Delete all baskets
</h2>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:9b400326-be37-4795-bd43-3a5fd26fa77d" class="wlWriterEditableSmartContent">
          <pre class="brush: sql;">--Delete all carts purchaseorders and associated data

BEGIN TRAN

UPDATE uCommerce_PurchaseOrder SET BillingAddressId = NULL WHERE OrderNumber IS NULL
DELETE a FROM uCommerce_Shipment a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL
DELETE a FROM uCommerce_OrderAddress a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL
DELETE a FROM uCommerce_OrderProperty a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL
DELETE a FROM uCommerce_OrderLine a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL
DELETE a FROM uCommerce_Payment a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL
DELETE a FROM uCommerce_OrderStatusAudit a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL
DELETE FROM uCommerce_PurchaseOrder WHERE OrderNumber IS NULL

--TODO: Expand this so it checks for other orders
--DELETE a FROM uCommerce_Address a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.NULL = @NULL
--DELETE a FROM uCommerce_Customer a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.NULL = @NULL


--Uncomment this
--COMMIT TRAN

--And comment out this
ROLLBACK TRAN</pre>
        </div>
        <br />
        <p>
 
</p>
        <p>
          <strong>Update:</strong> At the request of Søren, I’ve altered the delete all baskets
post so it allows you to delete all baskets older than a given date, see: <a href="http://blogs.thesitedoctor.co.uk/tim/2010/10/04/Delete+All+UCommerce+Baskets+Older+Than+X+Days.aspx" target="_blank">Delete
all UCommerce baskets older than x days</a></p>
        <img width="0" height="0" src="http://blogs.thesitedoctor.co.uk/test/aggbug.ashx?id=fcd3400c-32cd-4b96-819f-ce4adf0cab19" />
      </body>
      <title>Deleting test orders and baskets from uCommerce</title>
      <guid isPermaLink="false">http://blogs.thesitedoctor.co.uk/test/PermaLink,guid,fcd3400c-32cd-4b96-819f-ce4adf0cab19.aspx</guid>
      <link>http://blogs.thesitedoctor.co.uk/test/2010/10/01/DeletingTestOrdersAndBasketsFromUCommerce.aspx</link>
      <pubDate>Fri, 01 Oct 2010 11:53:43 GMT</pubDate>
      <description>&lt;p&gt;
Although Søren has posted a helpful post on how to &lt;a href="http://www.publicvoid.dk/DeletingPurchaseOrdersAndBasketsFromTheDatabaseInUCommerce.aspx" target="_blank"&gt;delete
entire purchase orders from the database here&lt;/a&gt;, we needed something a little less
“all or nothing” so put the below together.
&lt;/p&gt;
&lt;h2&gt;Delete a specific order id
&lt;/h2&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:c810ee8f-ccc4-4cc1-a251-bd161573c8f7" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: sql;"&gt;--Delete purchaseorders and associated data based on order id
DECLARE @OrderNumber nvarchar(50)
SET @OrderNumber = 'TEST-40'

BEGIN TRAN

UPDATE uCommerce_PurchaseOrder SET BillingAddressId = NULL WHERE OrderNumber = @OrderNumber
DELETE a FROM uCommerce_Shipment a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber
DELETE a FROM uCommerce_OrderAddress a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber
DELETE a FROM uCommerce_OrderProperty a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber
DELETE a FROM uCommerce_OrderLine a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber
DELETE a FROM uCommerce_Payment a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber
DELETE a FROM uCommerce_OrderStatusAudit a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber
DELETE FROM uCommerce_PurchaseOrder WHERE OrderNumber = @OrderNumber

--TODO: Expand this so it checks for other orders
--DELETE a FROM uCommerce_Address a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber
--DELETE a FROM uCommerce_Customer a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber = @OrderNumber

--Uncomment this
--COMMIT TRAN

--And comment out this
ROLLBACK TRAN&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;h2&gt;Delete all baskets
&lt;/h2&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:9b400326-be37-4795-bd43-3a5fd26fa77d" class="wlWriterEditableSmartContent"&gt;&lt;pre class="brush: sql;"&gt;--Delete all carts purchaseorders and associated data

BEGIN TRAN

UPDATE uCommerce_PurchaseOrder SET BillingAddressId = NULL WHERE OrderNumber IS NULL
DELETE a FROM uCommerce_Shipment a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL
DELETE a FROM uCommerce_OrderAddress a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL
DELETE a FROM uCommerce_OrderProperty a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL
DELETE a FROM uCommerce_OrderLine a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL
DELETE a FROM uCommerce_Payment a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL
DELETE a FROM uCommerce_OrderStatusAudit a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.OrderNumber IS NULL
DELETE FROM uCommerce_PurchaseOrder WHERE OrderNumber IS NULL

--TODO: Expand this so it checks for other orders
--DELETE a FROM uCommerce_Address a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.NULL = @NULL
--DELETE a FROM uCommerce_Customer a INNER JOIN uCommerce_PurchaseOrder b ON a.OrderId = b.OrderId WHERE b.NULL = @NULL


--Uncomment this
--COMMIT TRAN

--And comment out this
ROLLBACK TRAN&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Update:&lt;/strong&gt; At the request of Søren, I’ve altered the delete all baskets
post so it allows you to delete all baskets older than a given date, see: &lt;a href="http://blogs.thesitedoctor.co.uk/tim/2010/10/04/Delete+All+UCommerce+Baskets+Older+Than+X+Days.aspx" target="_blank"&gt;Delete
all UCommerce baskets older than x days&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.thesitedoctor.co.uk/test/aggbug.ashx?id=fcd3400c-32cd-4b96-819f-ce4adf0cab19" /&gt;</description>
      <comments>http://blogs.thesitedoctor.co.uk/test/CommentView,guid,fcd3400c-32cd-4b96-819f-ce4adf0cab19.aspx</comments>
      <category>Development</category>
      <category>eCommerce</category>
      <category>SQL</category>
      <category>SQL Server</category>
      <category>uCommerce</category>
      <category>Umbraco</category>
    </item>
    <item>
      <trackback:ping>http://blogs.thesitedoctor.co.uk/test/Trackback.aspx?guid=cf028a1d-0399-4388-82ad-dacfa9a673c2</trackback:ping>
      <pingback:server>http://blogs.thesitedoctor.co.uk/test/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.thesitedoctor.co.uk/test/PermaLink,guid,cf028a1d-0399-4388-82ad-dacfa9a673c2.aspx</pingback:target>
      <dc:creator>Tim</dc:creator>
      <wfw:comment>http://blogs.thesitedoctor.co.uk/test/CommentView,guid,cf028a1d-0399-4388-82ad-dacfa9a673c2.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.thesitedoctor.co.uk/test/SyndicationService.asmx/GetEntryCommentsRss?guid=cf028a1d-0399-4388-82ad-dacfa9a673c2</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
As some of my blog posts are a little out of date, I thought I would spend some time
updating the most popular ones. As I use this script on a regular basis and there
was an error with the original posting, I thought I'd update it with a "corrected"
version to get things started.
</p>
        <p>
If you want to see the original script, you can refer to <a href="http://blogs.thesitedoctor.co.uk/tim/2007/11/02/How+To+Search+Every+Table+And+Field+In+A+SQL+Server+Database.aspx">How
to search every table and field in a SQL Server Database</a>. This one's just fixed
:)
</p>
        <pre class="brush: sql;" name="code">CREATE PROC SearchAllTables
(
    @SearchStr nvarchar(100)
)
AS

BEGIN
DECLARE @SearchStr nvarchar(100)
SET @SearchStr = 'test'
    -- Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.
    -- Purpose: To search all columns of all tables for a given search string
    -- Written by: Narayana Vyas Kondreddi
    -- Site: http://vyaskn.tripod.com
    -- Tested on: SQL Server 7.0 and SQL Server 2000
    -- Date modified: 28th July 2002 22:50 GMT
    CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))

    SET NOCOUNT ON

    DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
    SET  @TableName = ''
    SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')

    WHILE @TableName IS NOT NULL
    
    BEGIN
        SET @ColumnName = ''
        SET @TableName = 
        (
            SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
            FROM     INFORMATION_SCHEMA.TABLES
            WHERE         TABLE_TYPE = 'BASE TABLE'
                AND    QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) &gt; @TableName
                AND    OBJECTPROPERTY(
                        OBJECT_ID(
                            QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
                             ), 'IsMSShipped'
                               ) = 0
        )

        WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
            
        BEGIN
            SET @ColumnName =
            (
                SELECT MIN(QUOTENAME(COLUMN_NAME))
                FROM     INFORMATION_SCHEMA.COLUMNS
                WHERE         TABLE_SCHEMA    = PARSENAME(@TableName, 2)
                    AND    TABLE_NAME    = PARSENAME(@TableName, 1)
                    AND    DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar', 'int', 'decimal')
                    AND    QUOTENAME(COLUMN_NAME) &gt; @ColumnName
            )
    
            IF @ColumnName IS NOT NULL
            
            BEGIN
                INSERT INTO #Results
                EXEC
                (
                    'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630) FROM ' + @TableName + ' (NOLOCK) ' +
                    ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
                )
            END
        END    
    END

    SELECT ColumnName, ColumnValue FROM #Results
END

DROP TABLE #Results</pre>
        <img width="0" height="0" src="http://blogs.thesitedoctor.co.uk/test/aggbug.ashx?id=cf028a1d-0399-4388-82ad-dacfa9a673c2" />
      </body>
      <title>Search every table and field in a SQL Server Database Updated</title>
      <guid isPermaLink="false">http://blogs.thesitedoctor.co.uk/test/PermaLink,guid,cf028a1d-0399-4388-82ad-dacfa9a673c2.aspx</guid>
      <link>http://blogs.thesitedoctor.co.uk/test/2010/02/19/SearchEveryTableAndFieldInASQLServerDatabaseUpdated.aspx</link>
      <pubDate>Fri, 19 Feb 2010 12:07:28 GMT</pubDate>
      <description>&lt;p&gt;
As some of my blog posts are a little out of date, I thought I would spend some time
updating the most popular ones. As I use this script on a regular basis and there
was an error with the original posting, I thought I'd update it with a &amp;quot;corrected&amp;quot;
version to get things started.
&lt;/p&gt;
&lt;p&gt;
If you want to see the original script, you can refer to &lt;a href="http://blogs.thesitedoctor.co.uk/tim/2007/11/02/How+To+Search+Every+Table+And+Field+In+A+SQL+Server+Database.aspx"&gt;How
to search every table and field in a SQL Server Database&lt;/a&gt;. This one's just fixed
:)
&lt;/p&gt;
&lt;pre class="brush: sql;" name="code"&gt;CREATE PROC SearchAllTables
(
    @SearchStr nvarchar(100)
)
AS

BEGIN
DECLARE @SearchStr nvarchar(100)
SET @SearchStr = 'test'
    -- Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.
    -- Purpose: To search all columns of all tables for a given search string
    -- Written by: Narayana Vyas Kondreddi
    -- Site: http://vyaskn.tripod.com
    -- Tested on: SQL Server 7.0 and SQL Server 2000
    -- Date modified: 28th July 2002 22:50 GMT
    CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))

    SET NOCOUNT ON

    DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
    SET  @TableName = ''
    SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')

    WHILE @TableName IS NOT NULL
    
    BEGIN
        SET @ColumnName = ''
        SET @TableName = 
        (
            SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
            FROM     INFORMATION_SCHEMA.TABLES
            WHERE         TABLE_TYPE = 'BASE TABLE'
                AND    QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) &amp;gt; @TableName
                AND    OBJECTPROPERTY(
                        OBJECT_ID(
                            QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
                             ), 'IsMSShipped'
                               ) = 0
        )

        WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
            
        BEGIN
            SET @ColumnName =
            (
                SELECT MIN(QUOTENAME(COLUMN_NAME))
                FROM     INFORMATION_SCHEMA.COLUMNS
                WHERE         TABLE_SCHEMA    = PARSENAME(@TableName, 2)
                    AND    TABLE_NAME    = PARSENAME(@TableName, 1)
                    AND    DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar', 'int', 'decimal')
                    AND    QUOTENAME(COLUMN_NAME) &amp;gt; @ColumnName
            )
    
            IF @ColumnName IS NOT NULL
            
            BEGIN
                INSERT INTO #Results
                EXEC
                (
                    'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630) FROM ' + @TableName + ' (NOLOCK) ' +
                    ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
                )
            END
        END    
    END

    SELECT ColumnName, ColumnValue FROM #Results
END

DROP TABLE #Results&lt;/pre&gt;&lt;img width="0" height="0" src="http://blogs.thesitedoctor.co.uk/test/aggbug.ashx?id=cf028a1d-0399-4388-82ad-dacfa9a673c2" /&gt;</description>
      <comments>http://blogs.thesitedoctor.co.uk/test/CommentView,guid,cf028a1d-0399-4388-82ad-dacfa9a673c2.aspx</comments>
      <category>SQL</category>
      <category>SQL Server</category>
      <category>Stored Procedure</category>
    </item>
  </channel>
</rss>