Archive for the ‘T-SQL’ Category

T-SQL regular expressions on MS SQL 2005

Tuesday, April 29th, 2008

One of the most anticipated features of SQL Server 2005 is the integration of the .Net CLR into the SQL Server engine. This article is going how write .Net code and use it in SQL Server 2005. As an example I am going to write a function for regular expression search.

SQL Server 2005 hosts the .Net CLR and will load and execute DLLs, which can also be referred to as assemblies. Assemblies maybe created in C# or VB.Net.
(more…)

Truncate time part of DateTime in T-SQL

Thursday, April 3rd, 2008

Often you may want to query an SQL table in MS SQL Server where there has been data entered by using getdate(). Getdate() will store the data like the resut of the follwing T-SQL statement.

SELECT GetDate()
GO
(more…)

MS SQL 2005 Recursive Queries Example

Friday, March 7th, 2008

Lets take as an example following table:

cmsPage

PageId ParrentPageId

6 NULL
44 6
50 44
51 44
52 6

Lets find all children of page with PageId 44
(more…)

Extraction of information from xml database field

Thursday, March 6th, 2008

During development you might find some objects are stored in database as single xml string (ASP.NET Profiles).

For examle:
<?xml version=”1.0″ encoding=”utf-16″?>
<Address xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=”http://www.w3.org/2001/XMLSchema” AddressID=”0″ UserName=”" FirstName=”Joe” LastName=”Stevens” Phone=”" Email=”" Address1=”1235 West Lane” Address2=”" City=”Miami” StateOrRegion=”FL” Zip=”33179″ Country=”" CreatedOn=”2007-08-17T23:52:10″ CreatedBy=”" ModifiedOn=”2007-08-17T23:52:10″ ModifiedBy=”">
</Address>

If you need to extract specific information from this field you can use xml paths.
(more…)