Posts

Showing posts from March, 2010

My Blogs Collection

http://www.davidhayden.com/blog/dave/archive/2006/12/21/QueryExpressionsAnonymousTypesLambaExpressions.aspx http://porwin-ebook.blogspot.com/search/label/Dot%20Net

Wildcard in Sql Server Select

the LIKE operator allows us to perform basic pattern-matching using wildcard characters. For Microsoft SQL Server, the wildcard characters are defined as follows: Wildcard Description _ (underscore) matches any single character % matches a string of one or more characters [ ] matches any single character within the specified range (e.g. [a-f]) or set (e.g. [abcdef]). [^] matches any single character not within the specified range (e.g. [^a-f]) or set (e.g. [^abcdef]). A few examples should help clarify these rules. WHERE FirstName LIKE '_im' finds all three-letter first names that end with 'im' (e.g. Jim, Tim). WHERE LastName LIKE '%stein' finds all employees whose last name ends with 'stein' WHERE LastName LIKE '%stein%' finds all employees whose last name includes 'stein' anywhere in the name. WHERE FirstName LIKE '[JT]im' finds three-letter first names that end with 'im' and begin

LINQ To SQL Examples

I have recently been using LINQ to accomplish much of my data abstraction and have found it very useful for building a robust ASP.Net application. Ultimately what LINQ to SQL does is it translates your C# code into a SQL query and returns an object or an object list instead of a dataset. This can be much easier to deal with than a dataset. I have run into a couple things that I didn’t expect so I thought I’d share. Inner Join with a ‘Where’ clause Usually when writing a SQL statement you start out with ‘SELECT’ then define what data to select, then you have ‘FROM’ clause in which you define where to get the data, then, if you have a ‘JOIN’ you would define your join and what tables to join. After that you would define your ‘WHERE’ clause and specify how you want to filter this data so it would look something like this: SELECT a . col1 , a . col2 , b . col1 , b . col2 FROM table1 a INNER JOIN table2 b ON a . ID = b . ID WHERE a . col1 > 0 Not so with LINQ to SQL. Ul