Contacts

The syntax is similar to the 1c request. Similar to the query conditions. The operator syntax description is similar to

43
NULL – missing values. Not to be confused with zero value! NULL is not a number, does not equal a space, an empty reference, or Undefined. NULL is a type-forming value, i.e. there is a type NULL and a single value of this type. NULL... 26
To generate and execute queries to database tables in the 1C platform, a special object of the Query programming language is used. This object is created by calling the New Request construct. Convenient request... 18
The article provides useful techniques when working with 1C v.8.2 queries, as well as information that is not so well known about the query language. I am not trying to give a complete description of the query language, but want to dwell only on... 12
I was faced with the task of selecting all payment documents and grouping them by document type! Having looked through all the housing and communal services and the Internet, I realized that there is no easy way to get the Document Type in the request: (I had to...

Despite all the shortcomings, text field search is still one of the most popular. We can find string data types everywhere - names, account numbers, addresses, as well as other information can be stored in this format. In queries in the built-in 1C language, for the convenience of developers, a special operator “LIKE” is used. This is one of the most used commands, so without a thorough knowledge of its syntax and capabilities, it will be difficult for a programmer to work.

Using the LIKE operator

Before using any operator in practice, you need to clearly understand its purpose, places of application and syntax. The purpose of using “LIKE” in a 1C request is to check for satisfaction of the condition presented as a template. The return value is a Boolean type - true or false - indicating whether the specified condition is true. The LIKE operator can be used in several places in a query:

  • In the block of conditions, indicated by the keyword “WHERE”;
  • In the design of Choice When Then Otherwise End;
  • Directly in the selection fields, as a result of field comparison.

The verification syntax is always the same and consists of 3 links. On the left is the text value that is being checked, then the “LIKE” operator itself, and on the right is the template that is being checked. To quickly and easily create templates, there are special symbols that make development easier:

  1. “%” is a sequence of any characters of arbitrary length. Used to search for individual words or numbers in a string;
  2. “_” – any single character. Intended to indicate the presence of a single character;
  3. “[...]” is a sequence of characters to compare with a character in a string. With the help of such a pattern, a match to any of the characters listed in brackets is checked. You can also specify a range of numbers or letters ([a-g], );
  4. “[^...]” is the opposite pattern to the previous one. The difference between the character specified in the line and those listed in brackets is checked.

To better understand and understand the principles of creating correct templates, let's look at some examples that are often encountered in the life of developers. The first is when we need to select from the nomenclature directory all items in the names of which the word “CUTTER” appears. In this case, we need to use LIKE in the query conditions:

SELECT Nomenclature.Name AS Name FROM Directory.Nomenclature AS Nomenclature WHERE Nomenclature.Name SIMILAR to "% CUTTER%"

If we remove both “%” symbols, the query will show a product whose name completely matches that specified in quotation marks. If we leave the template “CUTTER%” or “% CUTTER”, then the result will be a list of items ending or beginning, respectively, with a given combination of characters.


Let's look at a problem that can confuse novice programmers who do not know query syntax. Let’s say you need to find all items that have the “%” symbol in their names. Especially for cases when you need to search for reserved characters, there is a “special character” operator. #,\,/,~ and other characters can be used as a special character, after which any reserved characters will simply denote a sign.

SELECT Nomenclature.Name AS Name FROM Directory.Nomenclature AS Nomenclature WHERE Nomenclature.Name SIMILAR to "%#%" SPECIAL CHARACTER "#"

If you need to use a parameter in a search, then the variable in the query with the SIMILAR parameter is used using addition. Remember that the parameter must be a string type or you will need to convert it to a string in the request. This is a rather complicated operation and it is better to exclude it in advance.

SELECT Nomenclature.Name AS Name FROM Directory.Nomenclature AS Nomenclature WHERE Nomenclature.Name SIMILAR to "%" + &name + "%"

The SIMILAR function is applicable in all versions of the platform, starting from 8, and due to its applicability, 1C developers will not want to change it. Of course, text search always depends on the accuracy of the name entered, but it still remains one of the most common. In this regard, professional 1C developers need to study the use of SIMILAR with all its nuances.

LIKE- Operator for checking a string for similarity to a pattern. Analogue of LIKE in SQL.
Operator LIKE allows you to compare the value of the expression specified to the left of it with the pattern string specified to the right. The value of the expression must be of type string. If the value of the expression matches the pattern, the result of the operator will be TRUE, otherwise it will be FALSE.
The following characters in the template string are service characters and have a meaning different from the string character:
. % (percent): a sequence containing any number of arbitrary characters
. _ (underscore): one arbitrary character
. […] (one or more characters in square brackets): any single character listed inside the square brackets
An enumeration may contain ranges, for example a-z, meaning an arbitrary character included in the range, including the ends of the range.
. [^...] (in square brackets a negation sign followed by one or more characters): any single character other than those listed after the negation sign
Any other symbol means itself and does not carry any additional load.
If one of the listed characters needs to be written as itself, then it must be preceded by<Спецсимвол>. Myself<Спецсимвол>(any suitable character) is defined in the same statement after the SPECIAL CHARACTER keyword.
For example, pattern “%ABV[abvg]\_abv%” SPECIAL CHARACTER “\” means a substring consisting of a sequence of characters:
letters A; letters B; letters B; one digit; one of the letters a, b, c or d; underscore; letters a; letters b; letters v.
Moreover, this sequence can be preceded by an arbitrary set of characters.

Examples of using:
Code 1C v 8.x Procedure BankEndTextInput(Element, Text, Value, StandardProcessing)
StandardProcessing = False;
//Make a query with a search using a pattern like "%" +<Текст введенный пользователм в поле ввода> + "%"
Request = New Request;
Query.SetParameter("Name", "%" + Text + "%");
Query.Text = "SELECT
| Banks.Link
|FROM
| Directory.Banks HOW Banks
|WHERE
| Banks.Name SIMILAR &Name";

Result = Query.Run();
Selection = Result.Select();
If Result.Empty() Then
//Nothing found. Here you can display a message or do something else :)
Otherwise
//Get the results
tzResults = Result.Unload();
//Prepare a list of values ​​that will contain the found elements.
Value = New ValueList();
Value.LoadValues(tzResults.UnloadColumn("Link"));
endIf;
End of Procedure

It is necessary that the “Default Agreements” include only the Names of the Main Agreement, etc.:
Code 1C v 8.x Choice
When the Name is SIMILAR to “Agreement No.%” then “Agreement with number” // Any line starting with “Agreement No.” is suitable
When the Name is SIMILAR to "Main Agreement%[^А-яЁе"+Symbol(33)+"-"+Symbol(126)+"№"""+Symbols.PS+Symbols.Tab+Symbols.PF+Symbols.NPP+ Symbols.VTab+"]%" then "Default Contracts" // Any line starting with "Main Contract" is suitable
Otherwise "Other"
End Like Kind Of Contract

Information taken from the site



Did you like the article? Share it