---
title: "How To Use Pivot In SQL Query."  
description: "How To Use Pivot In SQL Query."  
author: "Anonymous User"  
published: 2015-10-29  
updated: 2015-10-29  
canonical: https://www.mindstick.com/forum/33542/how-to-use-pivot-in-sql-query  
category: ".net"  
tags: ["sql server"]  
reading_time: 1 minute  

---

# How To Use Pivot In SQL Query.

Can [anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-anyone) please help me how to [solve this problem](https://answers.mindstick.com/qa/94681/my-google-assistant-shows-completely-different-search-results-from-what-i-ask-how-can-i-solve-this-problem).

## Replies

### Reply by Anonymous User

```
lets Step one create order table

create table [Order](
 OrderID int primary key identity(1,1),
 Orderdate datetime,
 amount decimal(10,2)
)
now select sample query from order table SELECT year(Orderdate) as [year], left(datename(month,Orderdate),3)as [month],
amount as Amount FROM [Order] as InvoiceResult
```

```

```

```
Now write pivot Query .

SELECT *
FROM (
    SELECT
        year(Orderdate) as [year],left(datename(month,Orderdate),3)as [month],
        amount as Amount
    FROM [Order]
) as s
PIVOT
(
    SUM(Amount)
    FOR [month] IN (jan, feb, mar, apr,
    may, jun, jul, aug, sep, oct, nov, dec)
)AS Result 
```


---

Original Source: https://www.mindstick.com/forum/33542/how-to-use-pivot-in-sql-query

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
