Last Row of Table in SQL

Hi, Below is code which gives last row of table

SELECT TOP 1 * FROM TABLENAME
ORDER BY SOMEFIELD desc

Spliting a DataTable into two dataTable

If he following code will split a data table having some rows to the 2 data table with the number of rows provided by user. If your data table contain 50 rows and you want to split it into two data table then provide the datatable and number of rows as input parameter and it will return the dataset having two datatable.


private DataSet SplitDataTable(DataTable dt,int noOfRowsInTable)
{
DataSet ds = new DataSet();
try
{

ds.Tables.Add(dt.Clone());
ds.Tables[0].TableName = “FirstSet”;
ds.Tables.Add(dt.Clone());
ds.Tables[1].TableName = “SecondSet”;
if (dt != null)
{
if (dt.Rows.Count > noOfRowsInTable)
{
for (int i = 0; i < noOfRowsInTable; i++)
{
DataRow dr = ds.Tables[0].NewRow();
for (int k = 0; k < dt.Columns.Count; k++)
{
dr[k]= dt.Rows[i][k];
}
ds.Tables[0].Rows.Add(dr);
}
for (int j = noOfRowsInTable; j < dt.Rows.Count; j++)
{
DataRow dr1 = ds.Tables[1].NewRow();
for (int l = 0; l < dt.Columns.Count; l++)
{
dr1[l] = dt.Rows[j][l];
}
ds.Tables[1].Rows.Add(dr1);
}
}

}
return ds;
}

catch (Exception ex)
{
lblDate.Text = ex.Message;
return ds;
}

}

How to find the execution time of a stored procedure?

here are two options to find the execution time of the stored procedure,

First Option:
Get the current time before execution. Execute the stored procedure. Get the current time after execution. Manipulate the difference in times which will provide you the exact execution time.

declare @startproc datetime
declare @endproc datetime
declare @time integer
select @startproc = getdate()
exec VenkatProc(Your procedure name)
select @endproc = getdate()
select @time = DATEDIFF(second, @startproc, @endproc)
print str(@time)

Second Option:
Get Use profiler to get the exact time taken + split up period like, time taken by each query + time taken to read or write.

SQL Server 2008 – Enhancements in Date and Time Data Types

New data type related to date and time in sql server 2008.

Follow this link

http://blogs.msdn.com/manisblog/archive/2007/08/28/sql-server-2008-enhancements-in-date-and-time-data-types.aspx

Enable CLR integration in SQL 2005

Hello Friends,

Please folloe this liank and find how you can enable CLR integration in SQL Server 2005.

http://www.sqlclr.net/Articles/tabid/54/articleType/ArticleView/articleId/1/Enabling-CLR-in-SQL-Server.aspx

%d bloggers like this: