Hi Martin,
Thanks a lot for your reply. Nobody else has replied.
I have gone through great pains to re-write my queries from beginning to end using different methods to achieve high performance.
I must say I am satisfied I have eliminated all inefficiencies ... except indexing the SAP which isn't allowed! If I could index these, my queries would run much faster still.
I am thinking of a last recourse...
What if you could use views instead of original SAP Tables, and then index these views?
I have tried, but it seem that SQL Server still indexes the original SAP Tables instead of the views.
Even if I give the views column names different from the original tables, SQL Server indexes on the original tables.
For lack of time at the moment, I did not investigate further, as my queries are sufficiently fast.
But maybe you would like to try. If you find something interesting,please let me know.
You may like to know that most of the time I eliminated performance inefficiencies by avoiding temp tables, # or ## as much as possible and using CommonTable Expressions instead.
Also, if in the final steps, I need to copy to a table, I don't create the table first, and then copy everything to it.
Rather, I copy everything from the CTE directly to a table by using:
INSERT * INTO #Temp FROM CTE.
This copies both structure data into #Temp, without the overhead of creating #Temp.
Best Regards,
Leon Lai