<?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>Avivo Tech Blog &#187; SQL</title>
	<atom:link href="http://tech.avivo.si/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech.avivo.si</link>
	<description>Solving problems</description>
	<lastBuildDate>Tue, 24 Jan 2012 14:46:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Transact SQL paging Store Procedure &#8211; LINQ Skip Take alternative</title>
		<link>http://tech.avivo.si/2011/04/transact-sql-paging-store-procedure-linq-skip-take-alternative/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=transact-sql-paging-store-procedure-linq-skip-take-alternative</link>
		<comments>http://tech.avivo.si/2011/04/transact-sql-paging-store-procedure-linq-skip-take-alternative/#comments</comments>
		<pubDate>Mon, 25 Apr 2011 08:03:10 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[linq skip take alternative]]></category>
		<category><![CDATA[ms sql server]]></category>
		<category><![CDATA[paging in t-sql]]></category>
		<category><![CDATA[store procedure]]></category>
		<category><![CDATA[transact sql]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1307</guid>
		<description><![CDATA[This Transact-SQL Store Procedure allows you to do paging on your SQL table by providing only two parameters: Current page Record to display per page It returns chosen records and also total count as output parameter if you need to display this information or calculate how many pages you have in paging control. CREATE PROCEDURE [...]]]></description>
			<content:encoded><![CDATA[<p>This Transact-SQL Store Procedure allows you to do paging on your SQL table by providing only two parameters:</p>
<ul>
<li> Current page</li>
<li> Record to display per page</li>
</ul>
<p>It returns chosen records and also total count as output parameter if you need to display this information or calculate how many pages you have in paging control.</p>
<pre class="sql">CREATE PROCEDURE [dbo].[YourProcedureName]
  @CurrentPage int,
  @RecordsPerPage int,
  @Count int OUTPUT
AS
BEGIN
  -- The number of rows affected by the different commands
  -- does not interest the application, so turn NOCOUNT ON
  SET NOCOUNT ON

  -- Determine the first record and last record
  DECLARE @FirstRecord int, @LastRecord int

  SELECT @FirstRecord = (@CurrentPage - 1) * @RecordsPerPage
  SELECT @LastRecord = (@CurrentPage * @RecordsPerPage + 1)
  SET @Count = (SELECT COUNT(*) FROM YourTable);

  WITH TempResult as
  (
    SELECT	ROW_NUMBER() OVER(ORDER BY Field1 DESC) as RowNumber,
            Field1,
            Field2
    FROM    YourTable
  )
  SELECT  TOP (@LastRecord - 1) *
  FROM    TempResult
  WHERE   RowNumber &gt; @FirstRecord AND
          RowNumber &lt; @LastRecord

  -- Turn NOCOUNT back OFF
  SET NOCOUNT OFF
END</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/04/transact-sql-paging-store-procedure-linq-skip-take-alternative/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LINQ Max and Min functions upgraded</title>
		<link>http://tech.avivo.si/2011/04/linq-max-and-min-functions-upgraded/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=linq-max-and-min-functions-upgraded</link>
		<comments>http://tech.avivo.si/2011/04/linq-max-and-min-functions-upgraded/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 09:00:06 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[datacontext]]></category>
		<category><![CDATA[first]]></category>
		<category><![CDATA[firstordefault]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[linq min function throws an exception]]></category>
		<category><![CDATA[max]]></category>
		<category><![CDATA[min]]></category>
		<category><![CDATA[min linq function throws an exception]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1266</guid>
		<description><![CDATA[Classic LINQ Max and Min functions have the same problem as First function &#8211; exception can occur, so we use FirstOrDefault which returns null instead of exception. So, this is how you can extend Min and Max functions into MinOrDefault and MaxOrDefault; public static class IEnumerableExtensions { public static int MinOrDefault(this IEnumerable source, Func selector, [...]]]></description>
			<content:encoded><![CDATA[<p>Classic LINQ <strong>Max </strong>and <strong>Min </strong>functions have the same problem as <strong>First </strong>function &#8211; exception can occur, so we use <strong>FirstOrDefault </strong>which returns <strong>null </strong>instead of exception.</p>
<p>So, this is how you can extend <strong>Min </strong>and <strong>Max </strong>functions into <strong>MinOrDefault </strong>and <strong>MaxOrDefault</strong>;</p>
<pre class="csharp">
public static class IEnumerableExtensions
{
  public static int MinOrDefault<TSource>(this IEnumerable<TSource> source,
    Func<TSource, int> selector, int defaultValue)
  {
    if (source.Any<TSource>())
      return source.Min<TSource>(selector);

    return defaultValue;
  }

  public static int MaxOrDefault<TSource>(this IEnumerable<TSource> source,
    Func<TSource, int> selector, int defaultValue)
  {
    if (source.Any<TSource>())
      return source.Max<TSource>(selector);

    return defaultValue;
  }
}
</pre>
<p>&nbsp;</p>
<p><strong>Usage example:</strong></p>
<pre class="csharp">
  YourDataContext db = new YourDataContext();
  int maxVisits = db.SomeEntityTables.MaxOrDefault(x => x.SomeFieldYouSearchForMaximum, 0);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/04/linq-max-and-min-functions-upgraded/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>String or binary data would be truncated. The statement has been terminated.</title>
		<link>http://tech.avivo.si/2010/12/string-or-binary-data-would-be-truncated-the-statement-has-been-terminated/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=string-or-binary-data-would-be-truncated-the-statement-has-been-terminated</link>
		<comments>http://tech.avivo.si/2010/12/string-or-binary-data-would-be-truncated-the-statement-has-been-terminated/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 12:33:38 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[ms sql server]]></category>
		<category><![CDATA[store procedures]]></category>
		<category><![CDATA[String or binary data would be truncated]]></category>
		<category><![CDATA[string would be truncated]]></category>
		<category><![CDATA[t-sql]]></category>
		<category><![CDATA[The statement has been terminated]]></category>
		<category><![CDATA[transact sql]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1082</guid>
		<description><![CDATA[If this is not a problem for you that some long string will be truncated and you don&#8217;t want SQL to send you this error just use at the beginning of your StoreProcedure this statement: SET ANSI_WARNINGS OFF]]></description>
			<content:encoded><![CDATA[<p>If this is not a problem for you that some long string will be truncated and you don&#8217;t want SQL to send you this error just use at the beginning of your StoreProcedure this statement:</p>
<pre class=sql>
SET ANSI_WARNINGS OFF
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2010/12/string-or-binary-data-would-be-truncated-the-statement-has-been-terminated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to clear recent servers list in MS SQL 2005 Management Studio?</title>
		<link>http://tech.avivo.si/2010/08/how-to-clear-recent-servers-list-in-ms-sql-2005-management-studio/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-clear-recent-servers-list-in-ms-sql-2005-management-studio</link>
		<comments>http://tech.avivo.si/2010/08/how-to-clear-recent-servers-list-in-ms-sql-2005-management-studio/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 21:19:40 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[clear recent ms sql servers list in server name drop down list]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[ms sql server 2005]]></category>
		<category><![CDATA[smss]]></category>
		<category><![CDATA[sql server management studio]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=559</guid>
		<description><![CDATA[So, you have Microsoft SQL Server 2005 Management Studio (SSMS) and when trying to connect &#8220;Server name&#8221; drop down list is filled with sensitive data: To clear this list, all you have to do is delete this file: C:\Documents and Settings\&#60;user&#62;\Application Data\Microsoft\Microsoft SQL Server\90\Tools\Shell\mru.dat. Just remember, once you delete that file all of your previous [...]]]></description>
			<content:encoded><![CDATA[<p>So, you have Microsoft SQL Server 2005 Management Studio (SSMS) and when trying to connect &#8220;Server name&#8221; drop down list is filled with sensitive data:<br />
<img class="alignnone size-full wp-image-560" title="sql-server-recent-list" src="http://tech.avivo.si/wp-content/uploads/2010/08/sql-server-recent-list.jpg" alt="" width="640" height="441" /></p>
<p>To clear this list, all you have to do is delete this file:<br />
C:\Documents and Settings\&lt;user&gt;\Application Data\Microsoft\Microsoft SQL Server\90\Tools\Shell\mru.dat.</p>
<p>Just remember, once you delete that file all of your previous connections will be lost. So make sure that you have any necessary IP addresses, usernames, and passwords that you&#8217;ll need to reconnect to your favorite/most used SQL Servers.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2010/08/how-to-clear-recent-servers-list-in-ms-sql-2005-management-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regular Expression Replace in SQL 2005 (via the CLR)</title>
		<link>http://tech.avivo.si/2010/02/regular-expression-replace-in-sql-2005-via-the-clr/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=regular-expression-replace-in-sql-2005-via-the-clr</link>
		<comments>http://tech.avivo.si/2010/02/regular-expression-replace-in-sql-2005-via-the-clr/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 11:28:06 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[clr]]></category>
		<category><![CDATA[create custom sql function from c#]]></category>
		<category><![CDATA[ms sql server]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[regular expressions replace in sql 2005 and 2008]]></category>
		<category><![CDATA[replace string with regex in sql]]></category>
		<category><![CDATA[t-sql]]></category>
		<category><![CDATA[transact sql]]></category>
		<category><![CDATA[write sql store procedure from c#]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=450</guid>
		<description><![CDATA[Excellent post for achieving great SQL productivity. I had to do some data clean up the other day, and really needed some regular expression replacements to do the job. Since .NET has a great RegularExpressions namespace, and since SQL 2005 allows you to integrate .NET CLR functions in your T-SQL code, I thought I&#8217;d go [...]]]></description>
			<content:encoded><![CDATA[<p>Excellent <a href="http://weblogs.sqlteam.com/jeffs/archive/2007/04/27/SQL-2005-Regular-Expression-Replace.aspx" target="_blank">post</a> for achieving great SQL productivity.</p>
<p>I had to do some data clean up the other day, and really needed some <a href="http://en.wikipedia.org/wiki/Regular_expression" target="_blank">regular expression</a> replacements to do the job.</p>
<p>Since .NET has a great <a href="http://msdn2.microsoft.com/en-us/library/system.text.regularexpressions.aspx" target="_blank">RegularExpressions namespace</a>, and since SQL 2005 allows you to integrate .NET CLR functions in your T-SQL code, I thought I&#8217;d go ahead and experiment with creating a RegExReplace() function.</p>
<p>I am not so sure that I recommend using a function like this in production (there&#8217;s lots of <a href="http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/celko-on-sql-clr-database-design-is-a-totally-different-skill-from-application-development.aspx" target="_blank">pros and cons</a> of CLR integration in SQL databases), but for data cleaning or quick tasks or just learning how to use new features or technology, it is very interesting and easy to do.  All you need is a SQL Server 2005 database (<a href="http://msdn.microsoft.com/vstudio/express/sql/download/" target="_self">Express</a> is fine) and Visual Studio 2005.</p>
<p>Open up Visual Studio 2005 and create a new SQL Server Project, and after giving it a name and location, you will be prompted to connect to the SQL Server 2005 database in which you&#8217;d like to add your code.</p>
<p>Once the project is created, choose Project-&gt;Add User Defined Function, and name the .cs file anything you like, such as &#8220;RegExFunction.cs&#8221;.</p>
<p>Once the file has been added to your project, open it up and paste in the following code (changes made to the original template are in bold):</p>
<pre class="charp">using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Text.RegularExpressions;

public partial class UserDefinedFunctions
{
	[Microsoft.SqlServer.Server.SqlFunction(IsDeterministic=true,IsPrecise=true)]
	public static SqlString RegExReplace(SqlString expression,
                 SqlString pattern, SqlString replace)
	{
	  if (expression.IsNull || pattern.IsNull || replace.IsNull)
	  	return SqlString.Null;

	  Regex r = new Regex(pattern.ToString());

	  return new SqlString(r.Replace(expression.ToString(), replace.ToString()));
	}
};</pre>
<p>It&#8217;s really quite simple; within the class definition, just define public static methods that accept and return SQLTypes, and if those methods are marked with the SqlFunction attribute, when deployed they become available in your database code as T-SQL User-Defined Functions!  Quite cool.</p>
<p>In this example, our function is accepting 3 SQLString parameters, and if any are null, we return null.  If they are all legit, we construct a RegEx object from the pattern passed in, do the replace, and return the result.  Note that this will not be especially efficient, since the RegEx object is created and destroyed for each call, but it does work and it is interesting at the very least to play around with.  You might also want to experiment with other options, such as ignoring whitespace or case sensitivity, provided by the RegEx class.  This particular code is very basic, and doesn&#8217;t handle error checking or anything like that, you may wish to make improvements or optimizations in your own implementation.</p>
<p>Now that your code is ready to go, choose Build-&gt;Deploy Solution.   If all goes well, your assembly and new function have been deployed to your SQL database!</p>
<p>There is one final thing you must do before you can use the function, and that is configure your server to allow CLR code to execute, if it hasn&#8217;t been configured already. To do this, you must execute the following T-SQL statement:</p>
<pre class="sql">
--ENABLE CLR FUNCTIONS AND PROCEDURES FROM C#
sp_configure 'clr enabled',1
GO
RECONFIGURE
GO
</pre>
<p>Once that is complete, you can now use your new function like any other User Defined T-SQL function.  For example,</p>
<pre class="sql">select dbo.RegExReplace('Remove1All3Letters7','[a-zA-Z]','')

-------------------------
137

(1 row(s) affected)</pre>
<p>Now you can do a standard Regular Expression Replacement within your database directly, for example as an UPDATE:</p>
<pre class="sql">UPDATE MessyTable
SET MessyColumn = dbo.RegExReplace(MessyColumn, ... , ....)
WHERE ...</pre>
<p>Here&#8217;s my two cents on using CLR code in a database: If the code is purely a generic function or tool that has nothing specific to do with your data, and it fits and works logically in a database querying language, and there is no way to efficiently implement that code in T-SQL, then it may be worthwhile to implement that function via the CLR.  This is a pretty good example.   A bad example would be a .NET function that returns a CustomerName when passed a customerID, or something along those lines.  That&#8217;s just my take on things, for what it&#8217;s worth.</p>
<p>So, use wisely and have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2010/02/regular-expression-replace-in-sql-2005-via-the-clr/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Regular Expressions in SQL Store Procedures (Transact SQL or T-SQL)</title>
		<link>http://tech.avivo.si/2010/02/regular-expressions-in-sql-store-procedures-transact-sql-or-t-sql/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=regular-expressions-in-sql-store-procedures-transact-sql-or-t-sql</link>
		<comments>http://tech.avivo.si/2010/02/regular-expressions-in-sql-store-procedures-transact-sql-or-t-sql/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 10:58:06 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[custom functions]]></category>
		<category><![CDATA[ms sql server]]></category>
		<category><![CDATA[regular expressions in ms sql store procedures]]></category>
		<category><![CDATA[reqular expressions]]></category>
		<category><![CDATA[search text]]></category>
		<category><![CDATA[t-sql]]></category>
		<category><![CDATA[transact sql]]></category>
		<category><![CDATA[upgrade sql]]></category>
		<category><![CDATA[using reqular expressions in sql server]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=443</guid>
		<description><![CDATA[We have found nice explanation how you can upgrade Transact-SQL to work with Regular Expressions First, you need to create this SQL functions for regular expressions: CREATE FUNCTION [dbo].[FindRegularExpression] ( @source varchar(5000), @regexp varchar(1000), @ignorecase bit = 0 ) RETURNS bit AS BEGIN DECLARE @hr integer DECLARE @objRegExp integer DECLARE @objMatches integer DECLARE @objMatch integer [...]]]></description>
			<content:encoded><![CDATA[<p>We have found <a title="Regular Expressions in MS SQL" href="http://www.sqlteam.com/article/regular-expressions-in-t-sql" target="_blank">nice explanation</a> how you can upgrade Transact-SQL to work with Regular Expressions</p>
<h3><strong>First, you need to create this SQL functions for regular expressions:</strong></h3>
<pre class="sql">CREATE FUNCTION [dbo].[FindRegularExpression]
	(
		@source varchar(5000),
		@regexp varchar(1000),
		@ignorecase bit = 0
	)
RETURNS bit
AS
BEGIN
	DECLARE @hr integer
	DECLARE @objRegExp integer
	DECLARE @objMatches integer
	DECLARE @objMatch integer
	DECLARE @count integer
	DECLARE @results bit

	EXEC @hr = sp_OACreate 'VBScript.RegExp', @objRegExp OUTPUT
	IF @hr &lt;&gt; 0 BEGIN
		SET @results = 0
		RETURN @results
	END
	EXEC @hr = sp_OASetProperty @objRegExp, 'Pattern', @regexp
	IF @hr &lt;&gt; 0 BEGIN
		SET @results = 0
		RETURN @results
	END
	EXEC @hr = sp_OASetProperty @objRegExp, 'Global', false
	IF @hr &lt;&gt; 0 BEGIN
		SET @results = 0
		RETURN @results
	END
	EXEC @hr = sp_OASetProperty @objRegExp, 'IgnoreCase', @ignorecase
	IF @hr &lt;&gt; 0 BEGIN
		SET @results = 0
		RETURN @results
	END
	EXEC @hr = sp_OAMethod @objRegExp, 'Test', @results OUTPUT, @source
	IF @hr &lt;&gt; 0 BEGIN
		SET @results = 0
		RETURN @results
	END
	EXEC @hr = sp_OADestroy @objRegExp
	IF @hr &lt;&gt; 0 BEGIN
		SET @results = 0
		RETURN @results
	END
RETURN @results
END</pre>
<h3><strong>This is an example to test it:</strong></h3>
<pre class="sql">DECLARE @intLength AS INTEGER
DECLARE @vchRegularExpression AS VARCHAR(50)
DECLARE @vchSourceString as VARCHAR(50)
DECLARE @vchSourceString2 as VARCHAR(50)
DECLARE @bitHasNoSpecialCharacters as BIT

-- Initialize variables
SET @vchSourceString = 'Test one This is a test!!'
SET @vchSourceString2 = 'Test two This is a test'

-- Our regular expression should read as:
-- [a-zA-Z ]{}
-- eg. [a-zA-Z ]{10}  ...  For a string of 10 characters

-- Get the length of the string
SET @intLength = LEN(@vchSourceString)

-- Set the completed regular expression
SET @vchRegularExpression = '[a-zA-Z ]{' + CAST(@intLength as varchar) + '}'

-- get whether or not there are any special characters
SET @bitHasNoSpecialCharacters = dbo.FindRegularExpression(
   @vchSourceString, @vchRegularExpression,0)

PRINT @vchSourceString
IF @bitHasNoSpecialCharacters = 1 BEGIN
	PRINT 'No special characters.'
END ELSE BEGIN
	PRINT 'Special characters found.'
END

PRINT '---'

-- Get the length of the string
SET @intLength = LEN(@vchSourceString2)

-- Set the completed regular expression
SET @vchRegularExpression = '[a-zA-Z ]{' + CAST(@intLength as varchar) + '}'

-- get whether or not there are any special characters
SET @bitHasNoSpecialCharacters = dbo.FindRegularExpression(
   @vchSourceString2, @vchRegularExpression,0)

PRINT @vchSourceString2
IF @bitHasNoSpecialCharacters = 1 BEGIN
	PRINT 'No special characters.'
END ELSE BEGIN
	PRINT 'Special characters found.'
END

GO</pre>
<h3><strong>If you got an error message you need to activate SQL server property with the code bellow this message:</strong></h3>
<p><span style="color: #ff0000;">Msg 15281, Level 16, State 1, Line 22<br />
SQL Server blocked access to procedure &#8216;sys.sp_OACreate&#8217; of component &#8216;Ole Automation Procedures&#8217; because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of &#8216;Ole Automation Procedures&#8217; by using sp_configure. For more information about enabling &#8216;Ole Automation Procedures&#8217;, see &#8220;Surface Area Configuration&#8221; in SQL Server Books Online.</span><br />
Test one This is a test!!<br />
Special characters found.<br />
&#8212;<br />
<span style="color: #ff0000;">Msg 15281, Level 16, State 1, Line 40<br />
SQL Server blocked access to procedure &#8216;sys.sp_OACreate&#8217; of component &#8216;Ole Automation Procedures&#8217; because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of &#8216;Ole Automation Procedures&#8217; by using sp_configure. For more information about enabling &#8216;Ole Automation Procedures&#8217;, see &#8220;Surface Area Configuration&#8221; in SQL Server Books Online.</span><br />
Test two This is a test<br />
Special characters found.</p>
<h3><strong>In order to get rid or red text (error) do this to enable this function (</strong><strong>sp_OACreate &#8216;VBScript.RegExp&#8217;) :</strong></h3>
<pre class="sql">sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2010/02/regular-expressions-in-sql-store-procedures-transact-sql-or-t-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ORDER BY parameter (conditional)</title>
		<link>http://tech.avivo.si/2010/02/order-by-parameter-conditional/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=order-by-parameter-conditional</link>
		<comments>http://tech.avivo.si/2010/02/order-by-parameter-conditional/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 16:39:20 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[ms sql server]]></category>
		<category><![CDATA[order by]]></category>
		<category><![CDATA[order by parameter]]></category>
		<category><![CDATA[sort by]]></category>
		<category><![CDATA[sorting]]></category>
		<category><![CDATA[t-sql]]></category>
		<category><![CDATA[transact sql]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=438</guid>
		<description><![CDATA[This scripts shows how you can sort by some parameter in Transact SQL: DECLARE @SortOrder tinyint SET @SortOrder = 2 SELECT CompanyName, ContactName, ContactTitle FROM Customers ORDER BY CASE WHEN @SortOrder = 1 THEN CompanyName WHEN @SortOrder = 2 THEN ContactName ELSE ContactTitle END]]></description>
			<content:encoded><![CDATA[<p>This scripts shows how you can sort by some parameter in Transact SQL:</p>
<pre class="sql">
DECLARE @SortOrder tinyint
SET @SortOrder = 2

SELECT CompanyName,
       ContactName,
       ContactTitle
FROM Customers
ORDER BY CASE WHEN @SortOrder = 1 THEN CompanyName
              WHEN @SortOrder = 2 THEN ContactName
              ELSE ContactTitle
         END
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2010/02/order-by-parameter-conditional/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Last index of string (char) in MS SQL Transact SQL</title>
		<link>http://tech.avivo.si/2010/02/last-index-of-string-char-in-ms-sql-transact-sql/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=last-index-of-string-char-in-ms-sql-transact-sql</link>
		<comments>http://tech.avivo.si/2010/02/last-index-of-string-char-in-ms-sql-transact-sql/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 13:15:31 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[find last occurence of character]]></category>
		<category><![CDATA[last indef of]]></category>
		<category><![CDATA[last index of string in transact sql]]></category>
		<category><![CDATA[LastIndexOf]]></category>
		<category><![CDATA[ms sql server]]></category>
		<category><![CDATA[t-sql]]></category>
		<category><![CDATA[transact sql]]></category>
		<category><![CDATA[user function]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=429</guid>
		<description><![CDATA[It would be fine to have this system function, and because we don&#8217;t this can be a replacement. Note: additional checking can be added. You can also create your function for this. This is only logic. This example shows how to get file extension. DECLARE @Filename nvarchar(255), @OnlyName nvarchar(255), @Extension nvarchar(255), @Pos int SET @Filename [...]]]></description>
			<content:encoded><![CDATA[<p>It would be fine to have this system function, and because we don&#8217;t this can be a replacement.</p>
<p>Note: additional checking can be added. You can also create your function for this. This is only logic.</p>
<p>This example shows how to get file extension.</p>
<pre class="sql">
DECLARE @Filename nvarchar(255),
	     @OnlyName nvarchar(255),
	     @Extension nvarchar(255),
	     @Pos int

SET @Filename = 'this.is.my.filename.with.dots.jpg'

SELECT @Pos = CASE (CHARINDEX('.', @Filename))
		        WHEN 0 THEN -1
			ELSE LEN(@Filename) - CHARINDEX('.', REVERSE(@Filename)) +1
		      END
SET	@Extension = SUBSTRING(@Filename, @Pos, LEN(@Filename))
SET	@OnlyName = SUBSTRING(@Filename, 1, @Pos-1)

SELECT @Filename AS [Filename], @Pos AS Position,
           @OnlyName AS OnlyName, @Extension AS Extension
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2010/02/last-index-of-string-char-in-ms-sql-transact-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

