Search This Blog

Friday, September 28, 2012

How to disable, enable and drop an Index in SQL?

-- Disable Index in table tblUser
ALTER INDEX IX_tblUser ON tblUser DISABLE;

-- Enable Index in table tblUser
ALTER INDEX IX_tblUser ON tblUser REBUILD;

--DROP Index from table tblUser
DROP INDEX IX_tblUser ON tblUser

Thursday, September 13, 2012

How to read content of a html page using c#

// Way 1
using System.Net;
//...
using (WebClient client = new WebClient ()) // WebClient class inherits IDisposable
{
// save content into a file client.DownloadFile("http://myweb.com/page.html", @"C:\localfile.html");

// Or you can get the file content without saving it:
string htmlCode = client.DownloadString("http://myweb.com/page.html");
//...
}
// Way 2
/***********Read From same Application************/
using System.IO;
StreamReader sr = new StreamReader(Server.MapPath("Status.htm"));
string strS = sr.ReadToEnd();


//Way 3
/***************Read From Secure Wdb Site***********************/
//Read from secure website 'https'

Dim strRptHtml As String
Dim objResponse As WebResponse
Dim objRequest As WebRequest = HttpWebRequest.Create(strURL + "status.htm") ''''https://newqa.nccecas.org/cecas/status.htm objResponse = objRequest.GetResponse()
Using sr1 As New StreamReader(objResponse.GetResponseStream())
strRptHtml = sr1.ReadToEnd()
sr1.Close()
End Using
objResponse.Close()

Tuesday, September 11, 2012

What is an alternative of CURSOR in SQL?

The alternative of CURSOR depends on what the developers want to perform.
On the basis of your task you can use the following to avoid cursor..
1. WHILE loop
2. User defined function
3. Temporary Table
4. Joined complex sql query etc..


Note: Sometimes the use of cusor becomes better than its' alternative. Because sometime alternative takes more execution time than cursor.

Ranking Functions in SQL.

There are four ranking funtion in SQL
1. RANK
2. NTILE
3. DENSE_RANK
4. ROW_NUMBER

See the example and output result set to know about these...
USE MyDatabase;
GO
SELECT p.FirstName, p.LastName
    ,ROW_NUMBER() OVER (ORDER BY a.PostalCode) AS "Row Number"
    ,RANK() OVER (ORDER BY a.PostalCode) AS Rank
    ,DENSE_RANK() OVER (ORDER BY a.PostalCode) AS "Dense Rank"
    ,NTILE(4) OVER (ORDER BY a.PostalCode) AS Quartile
    ,s.SalesYTD, a.PostalCode
FROM Sales.SalesPerson AS s 
    INNER JOIN Person.Person AS p 
        ON s.BusinessEntityID = p.BusinessEntityID
    INNER JOIN Person.Address AS a 
        ON a.AddressID = p.BusinessEntityID
WHERE TerritoryID IS NOT NULL 
    AND SalesYTD <> 0;

FirstName

LastName

Row Number

Rank

Dense Rank

Quartile

SalesYTD

PostalCode

Michael

Blythe

1

1

1

1

4557045.0459

98027

Linda

Mitchell

2

1

1

1

5200475.2313

98027

Jillian

Carson

3

1

1

1

3857163.6332

98027

Garrett

Vargas

4

1

1

1

1764938.9859

98027

Tsvi

Reiter

5

1

1

2

2811012.7151

98027

Shu

Ito

6

6

2

2

3018725.4858

98055

José

Saraiva

7

6

2

2

3189356.2465

98055

David

Campbell

8

6

2

3

3587378.4257

98055

Tete

Mensa-Annan

9

6

2

3

1931620.1835

98055

Lynn

Tsoflias

10

6

2

3

1758385.926

98055

Rachel

Valdez

11

6

2

4

2241204.0424

98055

Jae

Pak

12

6

2

4

5015682.3752

98055

Ranjit

Varkey Chudukatil

13

6

2

4

3827950.238

98055

How to generate serial number in sql without using identity column?

In sql, there is a method Row_Number() using which you can generate sr. no.

Example:

SELECT Row_Number() Over(Order by ID) AS SrNo , colmn1, colmn2....
FROM tblTemp

Output
SrNo Colmn1 Column2 ...
1 .. .. ..
2 .. .. ..
3 .. .. ..

Monday, September 10, 2012

Reverse For Loop in VB.net.

Reverse Loop
For i = 8 to 1 step -1

Next


Forward loop
For i = 8 to 1

Next