<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ricardo Parente&#039;s Blog &#187; SQL</title>
	<atom:link href="http://ricardo.parente.us/category/database/sql-database/feed/" rel="self" type="application/rss+xml" />
	<link>http://ricardo.parente.us</link>
	<description>ColdFusion Developers Network</description>
	<lastBuildDate>Fri, 10 Feb 2012 17:13:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>SSAS: Forecast Video Tutorial</title>
		<link>http://ricardo.parente.us/2010/12/ssas-forecast-video-tutorial/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ssas-forecast-video-tutorial</link>
		<comments>http://ricardo.parente.us/2010/12/ssas-forecast-video-tutorial/#comments</comments>
		<pubDate>Mon, 13 Dec 2010 17:12:01 +0000</pubDate>
		<dc:creator>rparente</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[Forecast Tool]]></category>
		<category><![CDATA[SQL Server 2008]]></category>

		<guid isPermaLink="false">http://ricardo.parente.us/?p=4428</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="640" height="505" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/2SOr3wKf2sA?fs=1&amp;hl=en_US&amp;rel=0&amp;hd=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="640" height="505" src="http://www.youtube.com/v/2SOr3wKf2sA?fs=1&amp;hl=en_US&amp;rel=0&amp;hd=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://ricardo.parente.us/2010/12/ssas-forecast-video-tutorial/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Congratulations Pinal Dave for the 1500th Post</title>
		<link>http://ricardo.parente.us/2010/10/congratulations-pinal-dave-for-the-1500th-post/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=congratulations-pinal-dave-for-the-1500th-post</link>
		<comments>http://ricardo.parente.us/2010/10/congratulations-pinal-dave-for-the-1500th-post/#comments</comments>
		<pubDate>Thu, 14 Oct 2010 16:57:47 +0000</pubDate>
		<dc:creator>rparente</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL Authority]]></category>

		<guid isPermaLink="false">http://ricardo.parente.us/?p=3760</guid>
		<description><![CDATA[Pinal Dave, my SQL Guru, completed today 1500 posts on his blog SQLAuthority, with 20 million views in iyts 4th year. That&#8217;s amazing! Good job. He explains how he came up with the blog&#8217;s name on this article. Keep up the good work Pinal !]]></description>
			<content:encoded><![CDATA[<p>Pinal Dave, my SQL Guru, completed today 1500 posts on his blog <a title="http://blog.sqlauthority.com" href="http://blog.sqlauthority.com" target="_blank"><strong>SQLAuthority</strong></a>, with 20 million views in iyts 4th year.</p>
<p>That&#8217;s amazing! Good job.</p>
<p>He explains how he came up with the blog&#8217;s name on this <a title="http://blog.sqlauthority.com/2010/10/14/sql-server-1500-posts-a-milestone-original-of-blog-name-revealed/" href="http://blog.sqlauthority.com/2010/10/14/sql-server-1500-posts-a-milestone-original-of-blog-name-revealed/" target="_blank"><strong>article</strong></a>.</p>
<p>Keep up the good work Pinal !</p>
]]></content:encoded>
			<wfw:commentRss>http://ricardo.parente.us/2010/10/congratulations-pinal-dave-for-the-1500th-post/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ColdFusion &#8211; SQL: Dynamic Values in Order By Clause</title>
		<link>http://ricardo.parente.us/2010/10/coldfusion-sql-dynamic-values-in-order-by-clause/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=coldfusion-sql-dynamic-values-in-order-by-clause</link>
		<comments>http://ricardo.parente.us/2010/10/coldfusion-sql-dynamic-values-in-order-by-clause/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 16:41:31 +0000</pubDate>
		<dc:creator>rparente</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[RANK()]]></category>
		<category><![CDATA[row_number]]></category>
		<category><![CDATA[T-Sql]]></category>

		<guid isPermaLink="false">http://ricardo.parente.us/?p=3605</guid>
		<description><![CDATA[This week I had to write a stored procedure for retrieving real estate properties and use the data in a ColdFusion template with pagination.  I had the following input arguments: StartRow, EndRow, PriceFrom, PriceTo and SortBy. Since I use Fusebox, all parameters passed in the URL query string are converted to the scope &#8220;attributes&#8221;.  So, [...]]]></description>
			<content:encoded><![CDATA[<p>This week I had to write a stored procedure for retrieving real estate properties and use the data in a ColdFusion template with pagination.  I had the following input arguments: StartRow, EndRow, PriceFrom, PriceTo and SortBy.</p>
<p>Since I use Fusebox, all parameters passed in the URL query string are converted to the scope &#8220;attributes&#8221;.  So, here is the procedure call:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
</pre>
<pre>&lt;cfstoredproc procedure=&quot;dbo.pagination&quot; datasource=&quot;#application.mainDSN#&quot;&gt;
&lt;cfprocparam cfsqltype=&quot;cf_SQL_INTEGER&quot; value=&quot;#attributes.startRow#&quot;  /&gt;
&lt;cfprocparam cfsqltype=&quot;cf_SQL_INTEGER&quot; value=&quot;#attributes.endRow#&quot; /&gt;
&lt;cfprocparam cfsqltype=&quot;cf_SQL_INTEGER&quot; value=&quot;#attributes.priceFrom#&quot; null=&quot;#(not len(trim(attributes.priceFrom)))#&quot; /&gt;
&lt;cfprocparam cfsqltype=&quot;cf_SQL_INTEGER&quot; value=&quot;#attributes.sortBy#&quot; null=&quot;#(not len(trim(attributes.sortBy)))#&quot; /&gt;
&lt;cfprocresult name=&quot;qProps&quot; /&gt;
&lt;/cfstoredproc&gt;</pre>
</div>
<p><span id="more-3605"></span> You may have noticed that some parameters if not passed to this template, it will send a NULL value to the store procedure.</p>
<p>Since the SortBy parameter is dynamic and I need to retrieve only a subset of the query, I mean, the amount of records to fit one page, I could not use CTE because SQL Server does not allow the ORDER BY clause in the CTE (temporary table). Also, we needed to have a CASE statement in the ODER BY clause to allow dynamic sorting.</p>
<p>After such a pain in the neck, I did some research and found some examples on<strong> <a title="http://blog.sqlauthority.com/2007/07/17/sql-server-case-statement-in-order-by-clause-order-by-using-variable/" href="http://blog.sqlauthority.com/2007/07/17/sql-server-case-statement-in-order-by-clause-order-by-using-variable/" target="_blank">Pinal Dave</a></strong> blog &#8220;<a title="http://search.sqlauthority.com/" href="http://search.sqlauthority.com/" target="_blank"><strong>SQL Authority</strong></a>&#8220;. One of the comments on his article suggested the use of RANK(), and that was it, the solution for my problem.</p>
<p>Here is the stored procedure:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
</pre>
<pre>CREATE PROCEDURE [dbo].[Pagination]
@arg_startRow int
,   @arg_endRow int
,   @arg_priceFrom money = NULL
,   @arg_priceTo money = NULL
,   @arg_sortBy varchar(50) = NULL

AS
BEGIN
SET NOCOUNT ON;
DECLARE @temp table (
propertyUUID uniqueidentifier
,   price money
,   yearBuilt smallint
,   cityName nvarchar(50)
,   rowNum int
)
INSERT INTO @temp
SELECT
p.propertyUUID
,   p.price
,   p.yearBuilt
,   c.cityName
,   rowNum =
CASE
WHEN (@arg_sortBy = &#039;price ASC&#039;) THEN
ROW_NUMBER() OVER(ORDER BY p.price)
WHEN (@arg_sortBy = &#039;price DESC&#039;) THEN
ROW_NUMBER() OVER(ORDER BY p.price DESC)
-- default order
ELSE ROW_NUMBER() OVER(ORDER BY c.cityName)
END
FROM dbo.properties p
LEFT JOIN dbo.cities c ON c.cityCode = p.cityCode
WHERE p.isActive = 1
AND (@arg_priceFrom IS NULL OR p.price &gt;= @arg_priceFrom)
AND (@arg_priceTo IS NULL OR p.price &lt;= @arg_priceTo)
AND (@arg_cityName IS NULL OR c.cityName = @arg_cityName)
ORDER BY
CASE
WHEN @arg_sortBy = &#039;price ASC&#039; THEN
RANK() OVER(ORDER BY p.price)
WHEN @arg_sortBy = &#039;price DESC&#039; THEN
RANK() OVER(ORDER BY p.price DESC)
ELSE c.cityName
END

-- Now select only the number of rows passed from the pagination request
SELECT
propertyUUID
,   cityName
,   price
,   yearBuilt
FROM @temp
WHERE rowNum BETWEEN @arg_startRow AND @arg_endRow</pre>
</div>
<p>With that SP we can now paginate without losing the order by set by the url parameter.</p>
<p>Thanks Pinal Dave!</p>
]]></content:encoded>
			<wfw:commentRss>http://ricardo.parente.us/2010/10/coldfusion-sql-dynamic-values-in-order-by-clause/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SQL: Tips for Where Clause With Wildcards</title>
		<link>http://ricardo.parente.us/2010/10/sql-tips-for-where-clause-with-wildcards/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sql-tips-for-where-clause-with-wildcards</link>
		<comments>http://ricardo.parente.us/2010/10/sql-tips-for-where-clause-with-wildcards/#comments</comments>
		<pubDate>Sun, 03 Oct 2010 03:24:38 +0000</pubDate>
		<dc:creator>rparente</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[T-Sql]]></category>

		<guid isPermaLink="false">http://ricardo.parente.us/?p=3601</guid>
		<description><![CDATA[We, at the company,  had to find all cities in my city table which name were composed of more than one word and the last word should have only two characters, like &#8220;Berlin SO&#8221;, &#8220;Santa Fe&#8221;&#8230; Phillip Gagnon, our I.T. manager, showed us two simple ways to list them using wildcards: 1 2 3 SELECT [...]]]></description>
			<content:encoded><![CDATA[<p>We, at the company,  had to find all cities in my city table which name were composed of more than one word and the last word should have only two characters, like &#8220;Berlin SO&#8221;, &#8220;Santa Fe&#8221;&#8230;</p>
<p>Phillip Gagnon, our I.T. manager, showed us two simple ways to list them using wildcards:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
</pre>
<pre>SELECT cityID, cityName
FROM cities
WHERE right(cityName, 3) like &#039; __&#039;</pre>
</div>
<p>and another way:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
</pre>
<pre>SELECT cityID, cityName
FROM cities
WHERE right(cityName, 3) like &#039; %%&#039;</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://ricardo.parente.us/2010/10/sql-tips-for-where-clause-with-wildcards/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Microsoft SQL Server 2008 Service Pack 2</title>
		<link>http://ricardo.parente.us/2010/09/microsoft-sql-server-2008-service-pack-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=microsoft-sql-server-2008-service-pack-2</link>
		<comments>http://ricardo.parente.us/2010/09/microsoft-sql-server-2008-service-pack-2/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 16:40:30 +0000</pubDate>
		<dc:creator>rparente</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Microsoft SQL Server 2008]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Service Pack 2]]></category>

		<guid isPermaLink="false">http://ricardo.parente.us/?p=3590</guid>
		<description><![CDATA[Microsoft released the SQL 2008 Service Pack 2. You may download it here. Reference: Pinal Dave]]></description>
			<content:encoded><![CDATA[<p>Microsoft released the SQL 2008 Service Pack 2.</p>
<p>You may download it <a title="Microsoft SQL Server 2008 Service Pack 2" href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=8fbfc1de-d25e-4790-88b5-7dda1f1d4e17" target="_blank"><strong>here.</strong></a></p>
<p>Reference: <a title="Pinal Dave" href="http://blog.sqlauthority.com/2010/09/30/sql-server-microsoft-sql-server-2008-service-pack-2-download/?utm_source=feedburner&amp;utm_medium=feed&amp;utm_campaign=Feed%3A+SQLAuthority+%28Journey+to+SQL+Authority+with+Pinal+Dave%29" target="_blank"><strong>Pinal Dave</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://ricardo.parente.us/2010/09/microsoft-sql-server-2008-service-pack-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Convert String to a Table using CTE</title>
		<link>http://ricardo.parente.us/2009/12/convert-string-to-a-table-using-cte/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=convert-string-to-a-table-using-cte</link>
		<comments>http://ricardo.parente.us/2009/12/convert-string-to-a-table-using-cte/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 20:45:42 +0000</pubDate>
		<dc:creator>rparente</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[CTE]]></category>
		<category><![CDATA[MS SQL 2005]]></category>
		<category><![CDATA[string to table]]></category>

		<guid isPermaLink="false">http://ricardo.parente.us/?p=1290</guid>
		<description><![CDATA[I have found many solutions to pass a list parameter from ColdFusion to a stored procedure, and this one is a very simple and efficient way to convert a string to a table. Thanks to Amit Gaur posting to SQL ServerCentral. I modified his original function which returns only integers (forcing you to pass only [...]]]></description>
			<content:encoded><![CDATA[<p>I have found many solutions to pass a list parameter from ColdFusion to a stored procedure,<br />
and this one is a very simple and efficient way to convert a string to a table. Thanks to <strong>Amit Gaur</strong> posting to <a title="SQL Server Central" href="http://www.sqlservercentral.com/articles/CTE/67974/" target="_blank"><strong>SQL ServerCentral</strong></a>.</p>
<p>I modified his original function which returns only integers (forcing you to pass only a list of integers).</p>
<p>Suppose you pass the string &#8217;2A354,FB452,8896&#8242; in the argument @itemList as a list of item codes you want to retrieve from your inventory table.</p>
<p><span id="more-1290"></span></p>
<p>In your stored procedure you would have this query:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
</pre>
<pre>SELECT item, description, price
FROM inventory
WHERE item IN (SELECT item FROM strToTable(@itemList))</pre>
</div>
<p>Here is the function strToTable():</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre>
<pre>SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        Amit Gaur
-- Create date: July 25th 2008
-- Description:    Convert a string to a table
-- =============================================
CREATE FUNCTION [dbo].[strToTable]
(
@array varchar(max),
@del char(1)
)
RETURNS
@listTable TABLE
(
item int
)
AS
BEGIN

WITH rep (item,list) AS
(
SELECT SUBSTRING(@array,1,CHARINDEX(@del,@array,1) - 1) as item,
SUBSTRING(@array,CHARINDEX(@del,@array,1) + 1, LEN(@array)) + @del list

UNION ALL

SELECT SUBSTRING(list,1,CHARINDEX(@del,list,1) - 1) as item,
SUBSTRING(list,CHARINDEX(@del,list,1) + 1, LEN(list)) list
FROM rep
WHERE LEN(rep.list) &gt; 0
)
INSERT INTO @listTable
SELECT item FROM rep

RETURN
END

GO</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://ricardo.parente.us/2009/12/convert-string-to-a-table-using-cte/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Copying Stored Procedures to Another Server</title>
		<link>http://ricardo.parente.us/2009/09/copying-stored-procedures-to-another-server/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=copying-stored-procedures-to-another-server</link>
		<comments>http://ricardo.parente.us/2009/09/copying-stored-procedures-to-another-server/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 02:03:27 +0000</pubDate>
		<dc:creator>rparente</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://ricardo.parente.us/?p=947</guid>
		<description><![CDATA[We are constantly implementing new tasks and developing web sites for about 12 customers. We have a development server at our office and our live servers are at our datacenter. Many times we have to rewrite or modify stored procedures and then after testing, we need to copy them to the live server. To accomplish [...]]]></description>
			<content:encoded><![CDATA[<p>We are constantly implementing new tasks and developing web sites for about 12 customers. We have a development server at our office and our live servers are at our datacenter. Many times we have to rewrite or modify stored procedures and then after testing, we need to copy them to the live server.<br />
<span id="more-947"></span><br />
To accomplish this task we could normally script the SPs and copy the scripts to the live server, but that would take us a lot of time. The solution was written by our colleague <a title="Phillip Gagnon Blog" href="http://phillipgagnon.com" target="_blank"><strong>Phillip Gagnon</strong></a>, who wrote a piece of code to automate that task of copying from dev to live.<br />
I found it interesting and with his permission I&#8217;m posting it here.</p>
<p>Here is the code,you may call it <em>pushToLive.cfm</em>:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre>
<pre>&lt;cfparam name=&quot;url.devDsn&quot; default=&quot;myDevDSN&quot;&gt;
&lt;cfparam name=&quot;url.liveDsn&quot; default=&quot;myLiveDSN&quot;&gt;
&lt;cfparam name=&quot;url.output&quot; default=&quot;false&quot;&gt;
&lt;cfquery name=&quot;qProcs&quot; datasource=&quot;#devDsn#&quot;&gt;
     SELECT o.name, c.text
     FROM sysobjects o LEFT JOIN dbo.syscomments c ON o.id=c.id
     WHERE xType=&#039;P&#039; and category=0
&lt;/cfquery&gt;
&lt;cfoutput&gt;
There are #qProcs.recordCount# procedures to overwrite&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
&lt;cfflush&gt;
&lt;cfset i=1&gt;
&lt;cfloop query=&quot;qProcs&quot;&gt;
     &lt;cfquery datasource=&quot;#liveDsn#&quot;&gt;
          IF EXISTS(SELECT name FROM sysobjects WHERE name = &#039;#name#&#039; AND type = &#039;P&#039;)
               DROP PROCEDURE #name#
     &lt;/cfquery&gt;
     &lt;cfif url.output&gt;
          &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
          #text#
          &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
          &lt;cfflush&gt;
     &lt;/cfif&gt;
     &lt;cftry&gt;
          #i#. Writing #name#&lt;br /&gt;
          &lt;cfflush&gt;
          &lt;cfquery datasource=&quot;#liveDsn#&quot;&gt;
               #preserveSingleQuotes(text)#
          &lt;/cfquery&gt;
          &lt;cfcatch type=&quot;any&quot;&gt;
               &lt;h1 style=&quot;color:red;&quot;&gt;Error Writing #qProcs.name#&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
               #qProcs.text#&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
               &lt;cfdump var=&quot;#cfcatch#&quot;&gt;
          &lt;/cfcatch&gt;
     &lt;/cftry&gt;
     &lt;cfset i=i+1&gt;
&lt;/cfloop&gt;
&lt;br /&gt;
Done!&lt;br /&gt;
&lt;/cfoutput&gt;</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://ricardo.parente.us/2009/09/copying-stored-procedures-to-another-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Advanced SQL Injection</title>
		<link>http://ricardo.parente.us/2009/07/advanced-sql-injection/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=advanced-sql-injection</link>
		<comments>http://ricardo.parente.us/2009/07/advanced-sql-injection/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 03:44:27 +0000</pubDate>
		<dc:creator>rparente</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Amsterdam]]></category>
		<category><![CDATA[Black Hat Briefings]]></category>
		<category><![CDATA[Europe]]></category>
		<category><![CDATA[SQL Injection]]></category>

		<guid isPermaLink="false">http://ricardo.parente.us/?p=743</guid>
		<description><![CDATA[My friend Pedro Claudio posted a link on my Facebook Wall about this presentation made by Bernardo D. A. Guimarães at the Black Hat Briefings Europe, Amsterdam in April 2009. I found it interesting and here is the slide presentation: Advanced SQL injection to operating system full control (slides) View more documents from Bernardo Damele [...]]]></description>
			<content:encoded><![CDATA[<p>My friend Pedro Claudio posted a link on my Facebook Wall about this presentation made by <a title="Bernardo D. A. Guimaraes" href="http://www.slideshare.net/inquis" target="_blank"><strong>Bernardo D. A. Guimarães</strong></a> at the Black Hat Briefings Europe, Amsterdam in April 2009. I found it interesting and here is the slide presentation:</p>
<div id="__ss_1316179" style="width: 425px; text-align: left;"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" title="Advanced SQL injection to operating system full control (slides)" href="http://www.slideshare.net/inquis/advanced-sql-injection-to-operating-system-full-control-slides">Advanced SQL injection to operating system full control (slides)</a><object style="margin:0px" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=blackhat-europe-09-dameleag-advancedsqlinjection-slides-090420100219-phpapp02&amp;stripped_title=advanced-sql-injection-to-operating-system-full-control-slides" /><param name="allowfullscreen" value="true" /><embed style="margin:0px" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=blackhat-europe-09-dameleag-advancedsqlinjection-slides-090420100219-phpapp02&amp;stripped_title=advanced-sql-injection-to-operating-system-full-control-slides" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="font-size: 11px; font-family: tahoma,arial; height: 26px; padding-top: 2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">documents</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/inquis">Bernardo Damele a. g.</a>.</div>
</div>
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
]]></content:encoded>
			<wfw:commentRss>http://ricardo.parente.us/2009/07/advanced-sql-injection/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Convert Time To Decimal (SQL)</title>
		<link>http://ricardo.parente.us/2009/06/convert-time-to-decimal-sql/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=convert-time-to-decimal-sql</link>
		<comments>http://ricardo.parente.us/2009/06/convert-time-to-decimal-sql/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 14:34:13 +0000</pubDate>
		<dc:creator>rparente</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[convert time]]></category>
		<category><![CDATA[functions]]></category>

		<guid isPermaLink="false">http://ricardo.parente.us/?p=581</guid>
		<description><![CDATA[I was following the SQL list and came across a post from Jim Gotwald where he showed his solution to convert a time string into a decimal value (ex: &#8217;10:30&#8242; to 10.5). So I decided to write a custom function where you can either pass a complete date as a string or just the time [...]]]></description>
			<content:encoded><![CDATA[<p>I was following the SQL list and came across a post from <strong>Jim Gotwald</strong> where he showed his solution to convert a time string into a decimal value (ex: &#8217;10:30&#8242; to 10.5).</p>
<p>So I decided to write a custom function where you can either pass a complete date as a string or just the time and it will return a float value representing the time in decimal.</p>
<p>You may call the function like this:</p>
<p>select dbo.timeToDecimal(cast(getDate()) as varchar(20))<br />
select dbo.timeToDecimal(&#8217;2008-06-18 10:35:43&#8242;)<br />
select dbo.timeToDecimal(&#8217;06/18/2009 10:22:00&#8242;)<br />
select dbo.timeToDecimal(&#8217;10:42&#8242;)</p>
<p><span id="more-581"></span></p>
<p>Here is the function:<code><br />
SET ANSI_NULLS ON<br />
GO<br />
SET QUOTED_IDENTIFIER ON<br />
GO<br />
-- =============================================<br />
-- Author:        Ricardo Parente<br />
-- Create date: 2009-06-18<br />
-- Description:    I convert a time string to decimal<br />
-- Parameter: datetime string (varchar) or just a time string<br />
-- =============================================<br />
CREATE FUNCTION dbo.timeToDecimal<br />
(<br />
@timeToConvert varchar(25)<br />
)<br />
RETURNS float<br />
AS<br />
BEGIN<br />
DECLARE @Result float<br />
DECLARE @t varchar(5)<br />
SET @t = cast(datepart(hh,@timeToConvert) as varchar(2)) + ':' + cast(datepart(n,@timeToConvert) as varchar(2))<br />
SET @Result = CAST(DATEDIFF(N, '00:00', @t) AS FLOAT)/60<br />
RETURN @Result<br />
END<br />
GO<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://ricardo.parente.us/2009/06/convert-time-to-decimal-sql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Split List Table-Valued Function Reviewed</title>
		<link>http://ricardo.parente.us/2009/05/split-list-table-valued-function-reviewed/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=split-list-table-valued-function-reviewed</link>
		<comments>http://ricardo.parente.us/2009/05/split-list-table-valued-function-reviewed/#comments</comments>
		<pubDate>Mon, 04 May 2009 14:02:31 +0000</pubDate>
		<dc:creator>rparente</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[parse string]]></category>
		<category><![CDATA[split list]]></category>
		<category><![CDATA[SQL 2005]]></category>
		<category><![CDATA[SQL 2008]]></category>
		<category><![CDATA[table-valued function]]></category>
		<category><![CDATA[token]]></category>

		<guid isPermaLink="false">http://ricardo.parente.us/?p=512</guid>
		<description><![CDATA[In my previous post, I discussed the function used to split a string into a table of tokens. Very useful instead creating a cursor. Now, with SQL 2005/2008, it became easier and faster to do the same job using XML parsing. I found this function online, written by Jacob Sebastian which is much faster than my [...]]]></description>
			<content:encoded><![CDATA[<p>In my <strong><a title="Split List Table-Valued Function" href="http://ricardo.parente.us/?p=121" target="_blank">previous post</a><span style="font-weight: normal;">, I discussed the function used to split a string into a table of tokens. Very useful instead creating a cursor.</span></strong></p>
<p>Now, with SQL 2005/2008, it became easier and faster to do the same job using XML parsing.</p>
<p>I found this function online, written by <strong><a title="Jacob Sebastian" href="http://www.sqlservercentral.com/Authors/Articles/Jacob_Sebastian/212008/" target="_blank">Jacob Sebastian</a> </strong>which is much faster than my old one:<br />
<span id="more-512"></span><br />
<code>CREATE FUNCTION dbo.SplitString<br />
(<br />
   @str VARCHAR(MAX),<br />
   @delimeter CHAR(1)<br />
)<br />
   RETURNS @ret TABLE (Token VARCHAR(MAX)) AS<br />
   BEGIN<br />
      DECLARE @x XML<br />
      SET @x = '&lt;t&gt;' + REPLACE(@str, @delimeter, '&lt;/t&gt;&lt;t&gt;') + '&lt;/t&gt;'<br />
      INSERT INTO @ret<br />
      SELECT x.i.value('.', 'VARCHAR(MAX)') AS token<br />
      FROM @x.nodes('//t') x(i)<br />
      RETURN<br />
   END<br />
</code><br />
I used it to update a table, passing the list of values coming from a ColdFusion list and it was very fast. Here is a sample code:<br />
<code>USE [myDatabase]<br />
GO<br />
SET ANSI_NULLS ON<br />
GO<br />
SET QUOTED_IDENTIFIER ON<br />
GO<br />
CREATE PROCEDURE [dbo].[updateBooks]<br />
   @prodIdList varchar(max)<br />
,   @purchaseDate datetime<br />
,   @invoiceNo varchar(50)<br />
AS<br />
BEGIN<br />
   SET NOCOUNT ON;<br />
   update p set<br />
      p.invoiceNo = @invoiceNo<br />
   ,   p.lastPurchaseDate = @purchaseDate<br />
   from tbl_purchases p<br />
   inner join dbo.splitString(@prodIdList,',') temp on temp.token = p.prodId<br />
END<br />
</code><br />
The product ID list is passed in @prodIdList, and the inner join matches with p.prodId existing in the tbl_purchases table</p>
]]></content:encoded>
			<wfw:commentRss>http://ricardo.parente.us/2009/05/split-list-table-valued-function-reviewed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

