<?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; ms sql server</title>
	<atom:link href="http://tech.avivo.si/tag/ms-sql-server/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>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>Remove items from List using LINQ</title>
		<link>http://tech.avivo.si/2010/11/remove-items-from-list-using-linq/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=remove-items-from-list-using-linq</link>
		<comments>http://tech.avivo.si/2010/11/remove-items-from-list-using-linq/#comments</comments>
		<pubDate>Wed, 24 Nov 2010 18:13:52 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[collections]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[ms sql server]]></category>
		<category><![CDATA[Remove items from list using linq]]></category>
		<category><![CDATA[remove items in runtime]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=821</guid>
		<description><![CDATA[Typical scenario: you got your list of items from database but you want to remove some items from it (items that match additional criterion). It is simple as this (i.e. assuming that your list is named yourItems): yourItems.RemoveAll(x => x.ItemPropertyId != null);]]></description>
			<content:encoded><![CDATA[<p>Typical scenario: you got your list of items from database but you want to remove some items from it (items that match additional criterion).</p>
<p>It is simple as this (i.e. assuming that your list is named <strong>yourItems</strong>):</p>
<pre class=csharp>
yourItems.RemoveAll(x => x.ItemPropertyId != null);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2010/11/remove-items-from-list-using-linq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Database cannot be upgraded because it is read-only or has read-only files. Make the database or files writeable, and rerun recovery.</title>
		<link>http://tech.avivo.si/2010/04/database-cannot-be-upgraded-because-it-is-read-only-or-has-read-only-files-make-the-database-or-files-writeable-and-rerun-recovery/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=database-cannot-be-upgraded-because-it-is-read-only-or-has-read-only-files-make-the-database-or-files-writeable-and-rerun-recovery</link>
		<comments>http://tech.avivo.si/2010/04/database-cannot-be-upgraded-because-it-is-read-only-or-has-read-only-files-make-the-database-or-files-writeable-and-rerun-recovery/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 11:59:29 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[System administration]]></category>
		<category><![CDATA[and rerun recovery]]></category>
		<category><![CDATA[attach database]]></category>
		<category><![CDATA[cannot be attached]]></category>
		<category><![CDATA[Database cannot be upgraded because it is read-only or has read-only files. Make the database or files writeable]]></category>
		<category><![CDATA[mdf and ldf]]></category>
		<category><![CDATA[ms sql server]]></category>
		<category><![CDATA[restore database]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=480</guid>
		<description><![CDATA[If you have faced this problem when trying to attach your MSSQL database just copy MDF and LDF file to some directory where MS SQL service has full rights. It is usually something like this c:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Backup]]></description>
			<content:encoded><![CDATA[<p>If you have faced this problem when trying to attach your MSSQL database just copy MDF and LDF file to some directory where MS SQL service has full rights. It is usually something like this</p>
<p><strong>c:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Backup</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2010/04/database-cannot-be-upgraded-because-it-is-read-only-or-has-read-only-files-make-the-database-or-files-writeable-and-rerun-recovery/feed/</wfw:commentRss>
		<slash:comments>1</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>
		<item>
		<title>Saving Changes is Not Permitted?</title>
		<link>http://tech.avivo.si/2009/12/saving-changes-is-not-permitted/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=saving-changes-is-not-permitted</link>
		<comments>http://tech.avivo.si/2009/12/saving-changes-is-not-permitted/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 15:44:39 +0000</pubDate>
		<dc:creator>developer</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[2008]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[ms sql server]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[ntext]]></category>
		<category><![CDATA[Saving Changes is Not Permitted]]></category>
		<category><![CDATA[studio]]></category>
		<category><![CDATA[text field]]></category>
		<category><![CDATA[transact sql]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=252</guid>
		<description><![CDATA[We tried to add new ntext nullable column in MS SQL table.  We were quite surprised to get the following error message: Saving changes is not permitted.  The changes you have made require the following tables to be dropped and re-created.  You have either made changes to a table that can’t be re-created or enabled [...]]]></description>
			<content:encoded><![CDATA[<p>We tried to add new <strong>ntext </strong>nullable column in MS SQL table.  We were quite surprised to get the following error message:</p>
<p><a href="http://codeslammer.files.wordpress.com/2008/10/image15.png"><img style="border-width: 0pt;" src="http://codeslammer.files.wordpress.com/2008/10/image-thumb15.png?w=471&amp;h=117" border="0" alt="image" width="471" height="117" /></a></p>
<blockquote><p><em>Saving changes is not permitted.  The changes you have made require the following tables to be dropped and re-created.  You have either made changes to a table that can’t be re-created or enabled the option Prevent saving changes that require the table to be re-created.</em></p></blockquote>
<p>It wouldn’t let us add an “Allow Nulls” column?  That just seemed absurd.</p>
<p>Apparently, this is now the default behavior for any of the following changes to a table:</p>
<ul>
<li>Adding a new column to the middle of the table</li>
<li>Dropping a column</li>
<li>Changing column nullability</li>
<li>Changing the order of the columns</li>
<li>Changing the data type of a column</li>
</ul>
<p>In order to prevent this default behavior, you simply need to uncheck a box in the table designer options using the <strong>Tools -&gt; Options</strong> menu item</p>
<p><a href="http://codeslammer.files.wordpress.com/2008/10/image16.png"><img style="border: 0pt none ;" src="http://codeslammer.files.wordpress.com/2008/10/image-thumb16.png?w=244&amp;h=108" border="0" alt="image" width="244" height="108" /></a></p>
<p>Expand the <strong>Designers</strong> section to display the <strong>Table and Database Designers</strong> options.</p>
<p><a href="http://codeslammer.files.wordpress.com/2008/10/image17.png"><img style="border: 0pt none ;" src="http://codeslammer.files.wordpress.com/2008/10/image-thumb17.png?w=470&amp;h=258" border="0" alt="image" width="470" height="258" /></a></p>
<blockquote><p>To change this behavior, just <strong>uncheck</strong> the “<strong>Prevent saving changes that require table re-creation</strong>” checkbox.</p></blockquote>
<p>Original article was published at <a href="http://codeslammer.wordpress.com/2008/10/19/saving-changes-is-not-permitted/" target="_blank">http://codeslammer.wordpress.com/2008/10/19/saving-changes-is-not-permitted/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2009/12/saving-changes-is-not-permitted/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MS SQL Server Connection Strings</title>
		<link>http://tech.avivo.si/2009/10/ms-sql-server-connection-strings/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ms-sql-server-connection-strings</link>
		<comments>http://tech.avivo.si/2009/10/ms-sql-server-connection-strings/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 20:16:37 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[System administration]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[connection string]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[ms sql server]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.sweetucan.com/?p=167</guid>
		<description><![CDATA[Standard Security Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword; Standard Security alternative syntax Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False; Trusted Connection Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI; Trusted Connection alternative syntax Server=myServerAddress;Database=myDataBase;Trusted_Connection=True; Connecting to an SQL Server instance Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=True; Trusted Connection from a CE device Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;User ID=myDomain\myUsername;Password=myPassword;]]></description>
			<content:encoded><![CDATA[<p><strong>Standard Security</strong><br />
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;</p>
<p><strong>Standard Security alternative syntax</strong><br />
Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;</p>
<p><strong>Trusted Connection</strong><br />
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;</p>
<p><strong>Trusted Connection alternative syntax</strong><br />
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;</p>
<p><strong>Connecting to an SQL Server instance </strong><br />
Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=True;</p>
<p><strong>Trusted Connection from a CE device</strong><br />
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;User ID=myDomain\myUsername;Password=myPassword;</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2009/10/ms-sql-server-connection-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

