NinethSense oWnZ mE!: Praveen’s drawing book

Choose a Topic:

Fri
5
Oct '07

OVER and WITH in t-sql

OVER Clause

Determines the partitioning and ordering of the rowset before the associated window function is applied.
URL: http://msdn2.microsoft.com/en-us/library/ms189461.aspx


WITH

Specifies a temporary named result set, known as a common table expression (CTE). URL: http://msdn2.microsoft.com/en-us/library/ms175972.aspx


Below code demonstrates the creation of a temperory table and add a field new field which is an ID field of a sorted column

 
WITH temp_table AS
(
	SELECT *, (ROW_NUMBER() OVER (ORDER BY field_name)) AS row FROM table_name 
)
 
SELECT * FROM temp_table


The above code can also used for paging featuers ;) . Like MySQL’s LIMIT start, length.

 
SELECT * FROM temp_table WHERE row BETWEEN 10 AND 15



Useful, right?

Ref: Inspired from one of my friend Amit Benswal’s blog post
'

Dynamic varialbes from text file - PHP

This code snippet demonstrates how to read a resource file and convert them to php variables:

< ?_php
$arr = file(“resource.txt”);
foreach ($arr as $key => $value) {
	$arr = split(\t,$value); // tab delimeted. You can use any.
	$$arr[0] = $arr[1];
}
	
//Example - "name" is a word in text tile with ‘tab’ delimeted sample text. 
echo $name;
?>


Sample resource.txt file: (tab delimeted)
 
txt_title	hello world
txt_message	this is a message
name	Contact
The CodeProject Microsoft Developer Network Official ASP.NET Forums Microsoft .NET Framework Community Microsoft Most Valuable Professional Kidoos forums Microsoft Visual Studio Developer Home Professional Information Technology Solutions Microsoft Research Home Trivandrum Microsoft Users Group Community Website