P
P
Pavel Karinin2018-06-19 09:17:12
Transact SQL
Pavel Karinin, 2018-06-19 09:17:12

Is grouping of selection conditions supported in MSSQL?

Not very strong in SQL and for the purposes of my own knowledge I created a small table (roughly)

CREATE TABLE [test]
(
    [id] int,
    [column_A] int,
    [column_B] bit,
    [column_C] int,
    [column_D] bit,
    [column_Z] bigint
);

from which it is necessary to make a selection according to a number of conditions, by analogy with mathematical grouping (through brackets) in order to indicate the priority of performing operations. those. something like this:
SELECT * FROM [test]
WHERE [column_Z] = 3 AND (([column_A] = 2 AND [column_B] <> 0) OR ([column_C] = 2 AND[ columnD] <> 1))

From the example, you can see that the query SELECTinvolves a selection in which the conditions are grouped. In a sense, this should declare (I think so) the order in which the conditions are checked, is it? ... or SQL itself determines this order to optimize query execution and therefore the grouping of conditions will not work, i.e. brackets are ignored. Wednesday - MSSQL 2016.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
D
d-stream, 2018-06-19
@pavelkarinin

Parentheses are naturally taken into account. But sql can implement the order of checks in its own way due to its knowledge of data insider.

S
Sergey, 2014-09-24
@saintbyte

Bitrix was specially created in such a way that only their developers understand what kind of heresy is written in the code, so that clients do not run to freelance

K
kell555, 2014-09-24
@kell555

Only one drawback - Bitrix

S
signalizator, 2014-09-24
@signalizator

This can theoretically be called code if you remove the html and bring it to PSR1|2 . The request /?_SERVER[DOCUMENT_ROOT]=/anydoes not return any errors? If so, then you still have a hole in the server settings.

D
dmitriy, 2014-09-24
@dmitriylanets

Using array parameters requires good documentation, otherwise maintaining such code can be very difficult.

K
Kirill, 2014-09-24
@kirill89

Why do you think he is bad? In fact, within the framework of the CMS you are using, it is completely generic code.
Apparently you should ask why Bitrix is ​​bad?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question