I have about 1,60,000 rows retrieved in 4 mins if I use following.
SELECT DISTINCT *
FROM
(ABOUT 10 TABLES WITH LEFT OUTER JOIN )
But I need to extract only about 25 columns with some basic operations on them. But my below query is taking forever to execute (beyond an hour).
Col1, Col2 etc, ColA, ColB etc represents columns. Also I need to have DISTINCT on them because that is the final version that I need.
SELECT DISTINCT
Col1, Col2,...Col23,
Table1.Description1 + Table1.Description2 as FinalDescription,
(CASE WHEN COLA = 'XX' THEN
cast(round(COLB,2) as numeric(10,2))
ELSE
cast(round(COLB*-1 ,2) as numeric(10,2))
END) AS 'Amount',
CASE WHEN ISNULL(COLC,'')=''
THEN COLD + 'TO' + COLE
WHEN SUBSTRING ( COLC ,1 , 3 )IN ('XY')
THEN COLD+','+ SUBSTRING (COLE ,5 , 12)
ELSE COLD + ','+ COLF
END as 'Custom_Column'
FROM
(ABOUT 10 TABLES WITH LEFT OUTER JOIN)
What should I do to improve the performance to get the columns in the format that I am interested in?