Skip to main content

Simple example for Pivot in SQL

In this Post I am going to explain pivot with a simple example.

In  general Pivot means a point on which a part rotates. In same thing applies,Here the Pivoting means making the column change to a row .
With out further defining I would like to demonstrate it with a simple example.
Figure above shows a table with two columns .Now I would like to change the columns to rows
 I have the procedure above  :
this is the result generated by above procedure .

Explaining the procedure:
The first line selects the data as the defined header after being pivoted .next selects the columns key and value  from the pivot table while the statement after pivot makes the value column as header and the key as data under the column.

I hope this Post would help the beginners who are new to the SQL and want to learn the basic syntax of pivot.
Thank you for reading .
Any suggestions regarding the post are welcome .

Comments

Popular posts from this blog

Using SqlDataAdapter to fill DataTable in c#

public DataTable List(string sql)         {             SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);             SqlCommand cmd = new SqlCommand(sql, con);             DataTable dt = new DataTable();             SqlDataAdapter da = new SqlDataAdapter(cmd);             try             {                              con.Open();                 da.Fill(dt);             }             finally             {                 con.Close();          ...

Connection String in ASP.NET With SQL Server

Connection string can be placed in web.config file found in root directory of the application from .NET 3.5 onward. connection string can be specified with an xml tag  <connectionStrings>  inside  <configuration>  section of web.config file. < connectionStrings > < add name = "myConnectionString" connectionString = "Data Source=databaseServerName; database=database-name; uid=sqlUserName;password=sqlPassword; Integrated Security =True|false|SSPI (any one options) ; " providerName = " System.Data.SqlClient System.Data.SqlClient" /> </ connectionStrings > We can use local database server of SQL Server by using Data Source= (LocalDb)\MSSQLLocalDB we can attach a local database file to the app_data directory by using the property AttachDBFilename=|DataDirectory|\appDatabaseName.mdf in the connection string Connection String can be ...