Posts

Showing posts from September, 2008

LINQ - C# Programming

Get DataSource In C# as in most programming languages a variable must be declared before it can be used. In a LINQ query, the from clause comes first in order to introduce the data source (customers) and the range variable (cust). //QEmp is an IEnumerable var QEmp = from e in Emp select e; Filter Probably the most common query operation is to apply a filter in the form of a Boolean expression. The filter causes the query to return only those elements for which the expression is true. The result is produced by using the where clause. The filter in effect specifies which elements to exclude from the source sequence. var QEmp = from e in Emp where e.Country == "India" select e ----AND Condition---- where e.Country == "India" && e.Name == "Ashvin" ----OR Condition---- where e.Country == "India" || e.Name == "Ashvin" Ordering The orderby clause will cause the elements in the

Parsing the comma separated values into a temporary table

(Works in both SQL Server 7.0 and 2000) Declare @OrderList varchar (500) set @OrderList = 'Order1,Order2,,Order3,,,Order4,Order5,' ; drop TABLE #TempList CREATE TABLE #TempList ( OrderID varchar (20) ) DECLARE @OrderID varchar (10), @Pos int SET @OrderList = LTRIM(RTRIM(@OrderList))+ ',' SET @Pos = CHARINDEX( ',' , @OrderList, 1) IF REPLACE(@OrderList, ',' , '' ) <> '' BEGIN WHILE @Pos > 0 BEGIN SET @OrderID = LTRIM(RTRIM( LEFT (@OrderList, @Pos - 1))) IF @OrderID <> '' BEGIN INSERT INTO #TempList (OrderID) VALUES (@OrderID) END SET @OrderList = RIGHT (@OrderList, LEN(@OrderList) - @Pos) SET @Pos = CHARINDEX( ',' , @OrderList, 1) END END SELECT * FROM #TempList t +-+-+-+-+-+ OUTPUT +-+-+-+-+-+ OrderID -------- -- Order1 Order2 Order3 Order4 Order5