Posts

Showing posts from 2019

SQL Pivot

SELECT Item, imitdesc, 'Price' as Val,[2018-1],[2018-2],[2018-3],[2018-4],[2018-5],[2018-6],[2018-7],[2018-8],[2018-9],[2018-10],[2018-11],[2018-12],[2019-1],[2019-2],[2019-3],[2019-4],[2019-5],[2019-6],[2019-7],[2019-8],[2019-9],[2019-10],[2019-11],[2019-12] FROM ( SELECT Item, imitdesc, isnull(UPrice,0) as UPrice, cast(MYear as varchar) + '-' + cast(Mmonth as varchar) as Mmonth--, --isnull(GRNQty,0)-isnull(IssueQty,0) as Amount FROM #TempCons ) as s PIVOT ( SUM(UPrice) FOR [Mmonth] IN ([2018-1],[2018-2],[2018-3],[2018-4],[2018-5],[2018-6],[2018-7],[2018-8],[2018-9],[2018-10],[2018-11],[2018-12],[2019-1],[2019-2],[2019-3],[2019-4],[2019-5],[2019-6],[2019-7],[2019-8],[2019-9],[2019-10],[2019-11],[2019-12]) )AS pvt

Insert Records to SQl Temp Table

SELECT * INTO # TempTable FROM OriginalTable

Remove Line Breaks SQL

To remove these SQL line breaks, use the SQL Server replace function. Indeed, the CHAR(13) and CHAR(10) specific codes represent the characters of the line breaks,and then replace them with a space or a comma, for example. This time, the copy paste gives us this result. REPLACE( I.DelAddress ,CHAR(13)+CHAR(10),' ')