Answer the question
In order to leave comments, you need to log in
Is there a sql query constructor?
There are several tables: Order, Events for the order, Documents for the order, Invoice, Invoice, etc. They are all somehow connected.
There was an idea to give the user a constructor so that he can select fields from the tables he is interested in, for example, he selects the Number, Date, Description fields from the Order and selects several events from the Events table: Issued, Received, Sent.
You will get the following report
No. | Date | Description | Decorated | Entered | Sent
1 | 17.08 | Ok | 01.09 | 05.09 | 06.09
In this case, on the back, I need to make a request for the Order table and make one join for the Events table.
Another client can select some fields from the Order and Documents table, in this case, under his "report" it will be necessary to make a join between the Order and Documents tables. The third one will want from three tables and will need its own joins.
Technically, I can make a hefty view in which I peredzhoin all the tables-participants. To have one source of data. But I don't like this option, because just joining a table of documents takes 3-5 seconds. And if the fields according to the documents are not used in the report, there will be extra time to get the data. Well, if we take into account all the joins, then the time increases to 20-25 seconds per request, which is unrealistically much.
Perhaps this is a normal option if you make some kind of pre-calculation view, or even allocate an entire table for this business with ready-made data (let it be duplicated), tell me, is there something like that in MS SQL Server?
If you go further, you can even use the analytics service (BI which, for example, fill in all the data in a tabular model, then the final queries will just fly. There will also be an additional transfer of data, this is a lag and an unclear load, I only stood on the edge with such things when someone did it.
Another option comes to mind, I just take StringBuilder and build a query for sql using if-s on the backend.
Like, if at least one field from the documents is selected, then I add a join to the documents. But writing an sql query in a string is also such an option.
Answer the question
In order to leave comments, you need to log in
is there something like that in MS SQL server?Creating Indexed Views .
Before starting such a business, ask the target audience a question. And it turns out that. This is not necessary for about a million reasons
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question