I have a query which is following.
select
a,
b,
c,
CAST(d as bigint) as d,
e,
document_cat,
g,
h,
i,
fiscal_year,
k,
l,
m,
n,
account,
p,
q,
r,
s,
t,
u,
v,
CONVERT(date, CONCAT(i,'01')) as [CalDate],
CASE when r='' then CONCAT(d,'-', [account],'-','X','-',[fiscal_year],'-',p)
else CONCAT(d,'-',[account],'-',[subsidiary],'-',[fiscal_year],'-',p)
end as [UQID],
CASE when r='' then [account] else CONCAT([account],'-',[r]) end as [GL]
FROM
Ledger
WHERE [company]=123456
AND (document_cat= 'CAT A' or document_cat= 'CAT B' or document_cat= 'CAT C'.....'CAT I'
)
AND (fiscal_year]=2018 or fiscal_year =2019)
AND account BETWEEN 400000 and 999999
It is an extremely slow query.
Can you please advise how to make this fast.
I am not the DBA and I only have access to the views.
The column types are following
+--------------+-----------+
| Name | Data_Type |
+--------------+-----------+
| a | varchar |
| b | datetime |
| c | numeric |
| d | varchar |
| e | int |
| document_cat | varchar |
| g | varchar |
| i | numeric |
| fiscal_year | numeric |
| k | date |
| l | date |
| m | varchar |
| n | varchar |
| account | varchar |
| p | tinyint |
| q | varchar |
| r | varchar |
| s | varchar |
| t | varchar |
| u | varchar |
| v | varchar |
| h | varchar |
| company | varchar |
+--------------+-----------+
This is an edit to the original question. I have edited the code to include more detailed code and more details about the data type pf the columns used in this code.