问:
error while try to import xsd schema to excel
I have the following schema

```<code><?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="import">
  <xs:complexType>
    <xs:sequence>
        <xs:element name="node">
            <xs:complexType>
                    <xs:attribute name="action" type="xs:string" default="create"/>
                    <xs:attribute name="type" type="xs:string" default="document"/>
                    <xs:element name="location" type="xs:string"/>
                    <xs:element name="file" type="xs:string"/>
                    <xs:element name="title" type="xs:string">
                      <xs:complexType>
                            <xs:attribute name="language" type="xs:string" default="en"/>
                      </xs:complexType>
                    </xs:element>

                    <xs:element name="attribute">
                        <xs:complexType>
                            <xs:simpleContent>
                                <xs:extension>
                                    <xs:attribute name="name" use="required">
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:enumeration value="الجهة المرسل اليها"/>
                                                <xs:enumeration value="الجهة المرسلة للخطاب"/>
                                                <xs:enumeration value="الموضوع المختصر"/>
                                                <xs:enumeration value="تاريخ الحافظة"/>
                                                <xs:enumeration value="تاريخ المراسلة"/>
                                                <xs:enumeration value="رقم الخطاب الخاص بالجهة"/>
                                                <xs:enumeration value="رقم القرار"/>
                                                <xs:enumeration value="رقم المراسلة الخاص بالجهاز"/>
                                                <xs:enumeration value="عنوان الخطاب"/>
                                                <xs:enumeration value="كود المراسلة"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                </xs:extension>
                            </xs:simpleContent>
                        </xs:complexType>
                    </xs:element>

                    <xs:element name="category">
                      <xs:complexType>
                          <xs:sequence>
                                <xs:element ref="attribute" maxOccurs="unbounded"/>
                            </xs:sequence>
                        <xs:attribute name="name" type="xs:string"/>
                      </xs:complexType>
                    </xs:element>
            </xs:complexType>
        </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>
</code>```

when I tried to import it inside excel it gives me the following error

答:
You have several errors in your XSD:

Attribute declarations have to appear after the elements. Yes, it is one of the quirky "features" of XSD

Your elements in your complexType have to be in an xs:sequence.

You can only have either a type=... attribute on you elements or an xs:complexType child (or xs:simpleType of course, but here it doesn't matter).

The xs:extensionrequires abaseattribute. I set it toxs:string`, guessing... change it if it doesn't fit.

I couldn't fix your last error which is a reference without a definition that is referred to:

Cannot resolve the name 'attribute' to a(n) 'element declaration' component.

in the line

```<code><xs:element ref="attribute" maxOccurs="unbounded"/>
</code>```

So a (mostly) fiex version of your XSD looks like

```<code><?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="import">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="node">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="location" type="xs:string"/>
                            <xs:element name="file" type="xs:string"/>
                            <xs:element name="title">
                                <xs:complexType>
                                    <xs:attribute name="language" type="xs:string" default="en"/>
                                </xs:complexType>
                            </xs:element>

                            <xs:element name="attribute">
                                <xs:complexType>
                                    <xs:simpleContent>
                                        <xs:extension base="xs:string">
                                            <xs:attribute name="name" use="required">
                                                <xs:simpleType>
                                                    <xs:restriction base="xs:string">
                                                        <xs:enumeration value="الجهة المرسل اليها"/>
                                                        <xs:enumeration value="الجهة المرسلة للخطاب"/>
                                                        <xs:enumeration value="الموضوع المختصر"/>
                                                        <xs:enumeration value="تاريخ الحافظة"/>
                                                        <xs:enumeration value="تاريخ المراسلة"/>
                                                        <xs:enumeration value="رقم الخطاب الخاص بالجهة"/>
                                                        <xs:enumeration value="رقم القرار"/>
                                                        <xs:enumeration value="رقم المراسلة الخاص بالجهاز"/>
                                                        <xs:enumeration value="عنوان الخطاب"/>
                                                        <xs:enumeration value="كود المراسلة"/>
                                                    </xs:restriction>
                                                </xs:simpleType>
                                            </xs:attribute>
                                        </xs:extension>
                                    </xs:simpleContent>
                                </xs:complexType>
                            </xs:element>

                            <xs:element name="category">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element ref="attribute" maxOccurs="unbounded"/>
                                    </xs:sequence>
                                    <xs:attribute name="name" type="xs:string"/>

                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                        <xs:attribute name="action" type="xs:string" default="create"/>
                        <xs:attribute name="type" type="xs:string" default="document"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>
</code>```

As said above, the problem with the line

```<code><xs:element ref="attribute" maxOccurs="unbounded"/>
</code>```

remains unsolved and I cannot infer a solution without the greater context, so I leave it to your expertise to fix that.

Body:
I have the following schema

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="import">
  <xs:complexType>
    <xs:sequence>
        <xs:element name="node">
            <xs:complexType>
                    <xs:attribute name="action" type="xs:string" default="create"/>
                    <xs:attribute name="type" type="xs:string" default="document"/>
                    <xs:element name="location" type="xs:string"/>
                    <xs:element name="file" type="xs:string"/>
                    <xs:element name="title" type="xs:string">
                      <xs:complexType>
                            <xs:attribute name="language" type="xs:string" default="en"/>
                      </xs:complexType>
                    </xs:element>

                    <xs:element name="attribute">
                        <xs:complexType>
                            <xs:simpleContent>
                                <xs:extension>
                                    <xs:attribute name="name" use="required">
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:enumeration value="الجهة المرسل اليها"/>
                                                <xs:enumeration value="الجهة المرسلة للخطاب"/>
                                                <xs:enumeration value="الموضوع المختصر"/>
                                                <xs:enumeration value="تاريخ الحافظة"/>
                                                <xs:enumeration value="تاريخ المراسلة"/>
                                                <xs:enumeration value="رقم الخطاب الخاص بالجهة"/>
                                                <xs:enumeration value="رقم القرار"/>
                                                <xs:enumeration value="رقم المراسلة الخاص بالجهاز"/>
                                                <xs:enumeration value="عنوان الخطاب"/>
                                                <xs:enumeration value="كود المراسلة"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                </xs:extension>
                            </xs:simpleContent>
                        </xs:complexType>
                    </xs:element>

                    <xs:element name="category">
                      <xs:complexType>
                          <xs:sequence>
                                <xs:element ref="attribute" maxOccurs="unbounded"/>
                            </xs:sequence>
                        <xs:attribute name="name" type="xs:string"/>
                      </xs:complexType>
                    </xs:element>
            </xs:complexType>
        </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>

when I tried to import it inside excel it gives me the following error

Body:
You have several errors in your XSD:

Attribute declarations have to appear after the elements. Yes, it is one of the quirky "features" of XSD

Your elements in your complexType have to be in an xs:sequence.

You can only have either a type=... attribute on you elements or an xs:complexType child (or xs:simpleType of course, but here it doesn't matter).

The xs:extensionrequires abaseattribute. I set it toxs:string`, guessing... change it if it doesn't fit.

I couldn't fix your last error which is a reference without a definition that is referred to:

Cannot resolve the name 'attribute' to a(n) 'element declaration' component.

in the line

<xs:element ref="attribute" maxOccurs="unbounded"/>

So a (mostly) fiex version of your XSD looks like

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="import">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="node">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="location" type="xs:string"/>
                            <xs:element name="file" type="xs:string"/>
                            <xs:element name="title">
                                <xs:complexType>
                                    <xs:attribute name="language" type="xs:string" default="en"/>
                                </xs:complexType>
                            </xs:element>

                            <xs:element name="attribute">
                                <xs:complexType>
                                    <xs:simpleContent>
                                        <xs:extension base="xs:string">
                                            <xs:attribute name="name" use="required">
                                                <xs:simpleType>
                                                    <xs:restriction base="xs:string">
                                                        <xs:enumeration value="الجهة المرسل اليها"/>
                                                        <xs:enumeration value="الجهة المرسلة للخطاب"/>
                                                        <xs:enumeration value="الموضوع المختصر"/>
                                                        <xs:enumeration value="تاريخ الحافظة"/>
                                                        <xs:enumeration value="تاريخ المراسلة"/>
                                                        <xs:enumeration value="رقم الخطاب الخاص بالجهة"/>
                                                        <xs:enumeration value="رقم القرار"/>
                                                        <xs:enumeration value="رقم المراسلة الخاص بالجهاز"/>
                                                        <xs:enumeration value="عنوان الخطاب"/>
                                                        <xs:enumeration value="كود المراسلة"/>
                                                    </xs:restriction>
                                                </xs:simpleType>
                                            </xs:attribute>
                                        </xs:extension>
                                    </xs:simpleContent>
                                </xs:complexType>
                            </xs:element>

                            <xs:element name="category">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element ref="attribute" maxOccurs="unbounded"/>
                                    </xs:sequence>
                                    <xs:attribute name="name" type="xs:string"/>

                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                        <xs:attribute name="action" type="xs:string" default="create"/>
                        <xs:attribute name="type" type="xs:string" default="document"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

As said above, the problem with the line

<xs:element ref="attribute" maxOccurs="unbounded"/>

remains unsolved and I cannot infer a solution without the greater context, so I leave it to your expertise to fix that.


来源: stackexchange

问:
Why is {a^nb^n | n <= 10} regular?
I understand that
{ an bn | n>=1 } is not regular using Pumping Lemma.

But then, how is { an bn | n<=10 } regular? I thought we couldn't store the number of a and b in an automata. And I couldn't verify it with pumping lemma too.

答:
Every language that has a finite number of strings as members is regular, because you can construct a finite automaton that accepts each of these strings.

You can prove it by just constructing the automaton. It has a finite number of states and by the Myhill–Nerode theorem all of the strings this automaton accepts belong to a regular language.

ContentLicense: CC BY-SA 4.0

Title: Why is {a^nb^n | n <= 10} regular?


问:
.Net core 3.1 worker service self contained publish failed in vs 2019
I have a .net core 3.1 worker service used as a windows service. The self contained publish fails in visual studio 2019.

Output:

```<code>1>------ Publish started: Project: RineService, Configuration: Release Any CPU ------
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Console 4.0.0 -> runtime.win.System.Console 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Detected package downgrade: System.Threading from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Console 4.0.0 -> runtime.win.System.Console 4.3.0 -> System.Threading (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Threading (>= 4.0.11)
1>Detected package downgrade: System.Diagnostics.Debug from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Diagnostics.Debug (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Diagnostics.Debug (>= 4.0.11)
1>Detected package downgrade: System.Runtime.Extensions from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Runtime.Extensions (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.Extensions (>= 4.1.0)
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Detected package downgrade: System.Threading from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Threading (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Threading (>= 4.0.11)
1>Detected package downgrade: System.Diagnostics.Debug from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Diagnostics.Debug (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Diagnostics.Debug (>= 4.0.11)
1>Detected package downgrade: System.IO.FileSystem from 4.3.0 to 4.0.1. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.IO.FileSystem (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.IO.FileSystem (>= 4.0.1)
1>Detected package downgrade: System.Net.NameResolution from 4.3.0 to 4.0.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Net.NameResolution (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Net.NameResolution (>= 4.0.0)
1>Detected package downgrade: System.Net.Primitives from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Net.Primitives (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> System.Net.Primitives (>= 4.0.11)
1>Detected package downgrade: System.Runtime.Extensions from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Runtime.Extensions (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.Extensions (>= 4.1.0)
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Detected package downgrade: System.Threading from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Threading (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Threading (>= 4.0.11)
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Diagnostics.Process 4.1.0 -> Microsoft.Win32.Primitives 4.0.1 -> runtime.win.Microsoft.Win32.Primitives 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.IO.FileSystem.Watcher 4.0.0 -> Microsoft.Win32.Primitives 4.0.1 -> runtime.win.Microsoft.Win32.Primitives 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Detected package downgrade: System.Runtime.Extensions from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.NameResolution 4.0.0 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Runtime.Extensions (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.Extensions (>= 4.1.0)
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.NameResolution 4.0.0 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Detected package downgrade: System.Threading from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.NameResolution 4.0.0 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Threading (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Threading (>= 4.0.11)
1>Detected package downgrade: System.Runtime.Extensions from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Requests 4.0.11 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Runtime.Extensions (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.Extensions (>= 4.1.0)
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Requests 4.0.11 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Detected package downgrade: System.Threading from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Requests 4.0.11 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Threading (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Threading (>= 4.0.11)
1>Detected package downgrade: System.Runtime.Extensions from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Runtime.Extensions (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.Extensions (>= 4.1.0)
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Detected package downgrade: System.Threading from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Threading (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Threading (>= 4.0.11)
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.NameResolution 4.0.0 -> System.Security.Principal.Windows 4.0.0 -> Microsoft.Win32.Primitives 4.0.1 -> runtime.win.Microsoft.Win32.Primitives 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Restore failed in 276.28 ms for C:\Users\Sadaqat.razzak1\Downloads\RineService (4)\RineService\RineService\RineService.csproj.
========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
</code>```

答:
If you are using Visual Studio 2022 and you reference another project with similar file names, VS2022 does not accept files with same name in 2 or more project. You must solve it like this:

Publish error: Found multiple publish output files with the same relative path

Body:
I have a .net core 3.1 worker service used as a windows service. The self contained publish fails in visual studio 2019.

Output:

1>------ Publish started: Project: RineService, Configuration: Release Any CPU ------
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Console 4.0.0 -> runtime.win.System.Console 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Detected package downgrade: System.Threading from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Console 4.0.0 -> runtime.win.System.Console 4.3.0 -> System.Threading (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Threading (>= 4.0.11)
1>Detected package downgrade: System.Diagnostics.Debug from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Diagnostics.Debug (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Diagnostics.Debug (>= 4.0.11)
1>Detected package downgrade: System.Runtime.Extensions from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Runtime.Extensions (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.Extensions (>= 4.1.0)
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Detected package downgrade: System.Threading from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Threading (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Threading (>= 4.0.11)
1>Detected package downgrade: System.Diagnostics.Debug from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Diagnostics.Debug (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Diagnostics.Debug (>= 4.0.11)
1>Detected package downgrade: System.IO.FileSystem from 4.3.0 to 4.0.1. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.IO.FileSystem (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.IO.FileSystem (>= 4.0.1)
1>Detected package downgrade: System.Net.NameResolution from 4.3.0 to 4.0.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Net.NameResolution (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Net.NameResolution (>= 4.0.0)
1>Detected package downgrade: System.Net.Primitives from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Net.Primitives (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> System.Net.Primitives (>= 4.0.11)
1>Detected package downgrade: System.Runtime.Extensions from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Runtime.Extensions (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.Extensions (>= 4.1.0)
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Detected package downgrade: System.Threading from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Threading (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Threading (>= 4.0.11)
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Diagnostics.Process 4.1.0 -> Microsoft.Win32.Primitives 4.0.1 -> runtime.win.Microsoft.Win32.Primitives 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.IO.FileSystem.Watcher 4.0.0 -> Microsoft.Win32.Primitives 4.0.1 -> runtime.win.Microsoft.Win32.Primitives 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Detected package downgrade: System.Runtime.Extensions from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.NameResolution 4.0.0 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Runtime.Extensions (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.Extensions (>= 4.1.0)
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.NameResolution 4.0.0 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Detected package downgrade: System.Threading from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.NameResolution 4.0.0 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Threading (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Threading (>= 4.0.11)
1>Detected package downgrade: System.Runtime.Extensions from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Requests 4.0.11 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Runtime.Extensions (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.Extensions (>= 4.1.0)
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Requests 4.0.11 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Detected package downgrade: System.Threading from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Requests 4.0.11 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Threading (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Threading (>= 4.0.11)
1>Detected package downgrade: System.Runtime.Extensions from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Runtime.Extensions (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.Extensions (>= 4.1.0)
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Detected package downgrade: System.Threading from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.Sockets 4.1.0 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Threading (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Threading (>= 4.0.11)
1>Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.
1> RineService -> log4net 2.0.8 -> System.Net.NameResolution 4.0.0 -> System.Security.Principal.Windows 4.0.0 -> Microsoft.Win32.Primitives 4.0.1 -> runtime.win.Microsoft.Win32.Primitives 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
1> RineService -> log4net 2.0.8 -> System.Runtime.InteropServices (>= 4.1.0)
1>Restore failed in 276.28 ms for C:\Users\Sadaqat.razzak1\Downloads\RineService (4)\RineService\RineService\RineService.csproj.
========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========


问:
SQL Choose a manager in whose department the total value of sales for 1990 is the highest
I have a hard time trying to figure out the way the tables Sales_order and Employees are connected.

The question is "How can I extract data on the manager with the highest value of sales for 1990 within his department if there is no common column between these tables?"

答:
join indirectly via customer to get manager_id</p>
```<code>select top 1 manager_id,sum(total)
from   salesorders so
join   customers cus on cus.customer_id = so.customer_id
join   employee emp on emp.employee_id = cus.salesperson_id
where  so.order_date between '1999-01-01' and '1999-12-31'
group  by manager_id
order sum(total) desc
</code>```

Body:
join indirectly via customer to get manager_id

select top 1 manager_id,sum(total)
from   salesorders so
join   customers cus on cus.customer_id = so.customer_id
join   employee emp on emp.employee_id = cus.salesperson_id
where  so.order_date between '1999-01-01' and '1999-12-31'
group  by manager_id
order sum(total) desc


问:
Django should connect to SQL Server
I am using PyCharm, Django and the MSSQL-Backend-Project.

I am working on my iMac, and in the local network there is a Microsoft SQL Server I would like to connect to.

I am not sure what credentials to use (IP, oder the HOST named below). However with first attempt I get a hole lot of errors. Which seams for me not to be a problem with the credentials, but with some installation error or something.

I already installed a ne virtual environment (a suggestions I found on google). But still not working.

Can anyone help me, where to start?

settings.py

```<code>DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    },

    'bnt': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'POS',
        'USER': 'l.bamberg',
        'PASSWORD': '****************',
        'HOST': 'BNTS20005\\SQL17STD',

        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
        },
    }
}
</code>```

Error message:

```<code>Traceback (most recent call last):
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/sql_server/pyodbc/base.py", line 11, in <module>
    import pyodbc as Database
ImportError: dlopen(/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so, 0x0002): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
  Referenced from: /Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so
  Reason: tried: '/usr/local/opt/unixodbc/lib/libodbc.2.dylib' (no such file), '/usr/local/lib/libodbc.2.dylib' (no such file), '/usr/lib/libodbc.2.dylib' (no such file)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/contrib/staticfiles/handlers.py", line 76, in __call__
    return self.application(environ, start_response)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 131, in __call__
    signals.request_started.send(sender=self.__class__, environ=environ)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 182, in send
    for receiver in self._live_receivers(sender)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 182, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/__init__.py", line 27, in reset_queries
    for conn in connections.all():
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 76, in all
    return [self[alias] for alias in self]
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 76, in <listcomp>
    return [self[alias] for alias in self]
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 62, in __getitem__
    conn = self.create_connection(alias)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/utils.py", line 204, in create_connection
    backend = load_backend(db['ENGINE'])
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/utils.py", line 111, in load_backend
    return import_module('%s.base' % backend_name)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/sql_server/pyodbc/base.py", line 13, in <module>
    raise ImproperlyConfigured("Error loading pyodbc module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading pyodbc module: dlopen(/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so, 0x0002): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
  Referenced from: /Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so
  Reason: tried: '/usr/local/opt/unixodbc/lib/libodbc.2.dylib' (no such file), '/usr/local/lib/libodbc.2.dylib' (no such file), '/usr/lib/libodbc.2.dylib' (no such file)
[05/Feb/2022 13:15:52] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/sql_server/pyodbc/base.py", line 11, in <module>
    import pyodbc as Database
ImportError: dlopen(/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so, 0x0002): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
  Referenced from: /Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so
  Reason: tried: '/usr/local/opt/unixodbc/lib/libodbc.2.dylib' (no such file), '/usr/local/lib/libodbc.2.dylib' (no such file), '/usr/lib/libodbc.2.dylib' (no such file)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/contrib/staticfiles/handlers.py", line 76, in __call__
    return self.application(environ, start_response)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 131, in __call__
    signals.request_started.send(sender=self.__class__, environ=environ)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 182, in send
    for receiver in self._live_receivers(sender)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 182, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/__init__.py", line 27, in reset_queries
    for conn in connections.all():
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 76, in all
    return [self[alias] for alias in self]
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 76, in <listcomp>
    return [self[alias] for alias in self]
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 62, in __getitem__
    conn = self.create_connection(alias)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/utils.py", line 204, in create_connection
    backend = load_backend(db['ENGINE'])
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/utils.py", line 111, in load_backend
    return import_module('%s.base' % backend_name)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/sql_server/pyodbc/base.py", line 13, in <module>
    raise ImproperlyConfigured("Error loading pyodbc module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading pyodbc module: dlopen(/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so, 0x0002): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
  Referenced from: /Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so
  Reason: tried: '/usr/local/opt/unixodbc/lib/libodbc.2.dylib' (no such file), '/usr/local/lib/libodbc.2.dylib' (no such file), '/usr/lib/libodbc.2.dylib' (no such file)
[05/Feb/2022 13:15:52] "GET /favicon.ico HTTP/1.1" 500 59```
```

答:
Just went on as @EgorWexler said and installed the libodbc Driver as followed:

```<code>/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=Y brew install msodbcsql17 mssql-tools
</code>```

That worked so far.

Title: Django should connect to SQL Server

Body:
I am using PyCharm, Django and the MSSQL-Backend-Project.

I am working on my iMac, and in the local network there is a Microsoft SQL Server I would like to connect to.

I am not sure what credentials to use (IP, oder the HOST named below). However with first attempt I get a hole lot of errors. Which seams for me not to be a problem with the credentials, but with some installation error or something.

I already installed a ne virtual environment (a suggestions I found on google). But still not working.

Can anyone help me, where to start?

settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    },

    'bnt': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'POS',
        'USER': 'l.bamberg',
        'PASSWORD': '****************',
        'HOST': 'BNTS20005\\SQL17STD',

        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
        },
    }
}

Error message:

Traceback (most recent call last):
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/sql_server/pyodbc/base.py", line 11, in <module>
    import pyodbc as Database
ImportError: dlopen(/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so, 0x0002): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
  Referenced from: /Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so
  Reason: tried: '/usr/local/opt/unixodbc/lib/libodbc.2.dylib' (no such file), '/usr/local/lib/libodbc.2.dylib' (no such file), '/usr/lib/libodbc.2.dylib' (no such file)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/contrib/staticfiles/handlers.py", line 76, in __call__
    return self.application(environ, start_response)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 131, in __call__
    signals.request_started.send(sender=self.__class__, environ=environ)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 182, in send
    for receiver in self._live_receivers(sender)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 182, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/__init__.py", line 27, in reset_queries
    for conn in connections.all():
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 76, in all
    return [self[alias] for alias in self]
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 76, in <listcomp>
    return [self[alias] for alias in self]
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 62, in __getitem__
    conn = self.create_connection(alias)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/utils.py", line 204, in create_connection
    backend = load_backend(db['ENGINE'])
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/utils.py", line 111, in load_backend
    return import_module('%s.base' % backend_name)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/sql_server/pyodbc/base.py", line 13, in <module>
    raise ImproperlyConfigured("Error loading pyodbc module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading pyodbc module: dlopen(/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so, 0x0002): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
  Referenced from: /Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so
  Reason: tried: '/usr/local/opt/unixodbc/lib/libodbc.2.dylib' (no such file), '/usr/local/lib/libodbc.2.dylib' (no such file), '/usr/lib/libodbc.2.dylib' (no such file)
[05/Feb/2022 13:15:52] "GET / HTTP/1.1" 500 59
Traceback (most recent call last):
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/sql_server/pyodbc/base.py", line 11, in <module>
    import pyodbc as Database
ImportError: dlopen(/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so, 0x0002): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
  Referenced from: /Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so
  Reason: tried: '/usr/local/opt/unixodbc/lib/libodbc.2.dylib' (no such file), '/usr/local/lib/libodbc.2.dylib' (no such file), '/usr/lib/libodbc.2.dylib' (no such file)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/contrib/staticfiles/handlers.py", line 76, in __call__
    return self.application(environ, start_response)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 131, in __call__
    signals.request_started.send(sender=self.__class__, environ=environ)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 182, in send
    for receiver in self._live_receivers(sender)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 182, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/__init__.py", line 27, in reset_queries
    for conn in connections.all():
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 76, in all
    return [self[alias] for alias in self]
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 76, in <listcomp>
    return [self[alias] for alias in self]
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/utils/connection.py", line 62, in __getitem__
    conn = self.create_connection(alias)
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/utils.py", line 204, in create_connection
    backend = load_backend(db['ENGINE'])
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/django/db/utils.py", line 111, in load_backend
    return import_module('%s.base' % backend_name)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/sql_server/pyodbc/base.py", line 13, in <module>
    raise ImproperlyConfigured("Error loading pyodbc module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading pyodbc module: dlopen(/Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so, 0x0002): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
  Referenced from: /Users/georghuber/Desktop/Waschhalle/venv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so
  Reason: tried: '/usr/local/opt/unixodbc/lib/libodbc.2.dylib' (no such file), '/usr/local/lib/libodbc.2.dylib' (no such file), '/usr/lib/libodbc.2.dylib' (no such file)
[05/Feb/2022 13:15:52] "GET /favicon.ico HTTP/1.1" 500 59```

Body:
Just went on as @EgorWexler said and installed the libodbc Driver as followed:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=Y brew install msodbcsql17 mssql-tools

That worked so far.


问:
Download files modified after given time with sftp in bash
I am writing a bash script that will get files from one directory of remote host.
Here, I want to get files that were modified after given time.

```<code>sftp userme@remote_host_addr:/somedirectoryonremoteserver
> mget
</code>```

Here, how can I pass the timing to sftp command to get only files whose modified time is greater than given time.

答:
It's rather difficult to implement this using the OpenSSH sftp client.

You would have to:

list the directory using ls -l command;

parse the results (in shell or other script) to find names and times;

filter the files you want;

generate another sftp script to download (get) the files you found.

A way easier and more reliable would be to give up on the command-line sftp. Instead, use your favorite scripting language (Python, Perl, PHP) and its native SFTP implementation.

For an example, see:

Download files from SFTP server that are older than 5 days using Python

Or use a more capable SFTP client.

Body:
I am writing a bash script that will get files from one directory of remote host.
Here, I want to get files that were modified after given time.

sftp userme@remote_host_addr:/somedirectoryonremoteserver
> mget

Here, how can I pass the timing to sftp command to get only files whose modified time is greater than given time.


问:
Combining two different Queries out put in one XML
I need to produce a report that will be emailed so I am using XML format. I an currently producing the mail below and now have been asked to add a summary to the top. My SQL XML knowledge is lacking when it comes to combining the results of two queries into one XML. I can provide a script to create a input table if you need it. Thanks in advance.

Sample Data

```<code>   DROP TABLE IF EXISTS [dbo].[temp_Matching_table2]

    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[temp_Matching_table2]
    (
        [Job_Num] [varchar](8) NULL,
        [Mail_Cat] [char](1) NULL,
        [Mail_Date] [date] NULL,
        [Mail_Class] [char](1) NULL,
        [TR_Scan_Date] [datetime] NOT NULL
    ) ON [PRIMARY]

    GO
    INSERT [dbo].[temp_Matching_table2]
        ([Job_Num], [Mail_Cat], [Mail_Date], [Mail_Class], [TR_Scan_Date])
    VALUES
        (NULL, NULL, NULL, NULL, CAST(N'2021-12-27T09:41:19.000' AS DateTime)),
        (NULL, NULL, NULL, NULL, CAST(N'2022-01-10T21:17:43.000' AS DateTime)),
        ( N'1Q22    ', N'T', CAST(N'2021-11-12' AS Date), N'3', CAST(N'2021-12-18T15:24:56.000' AS DateTime)),
        ( N'1Q22    ', N'T', CAST(N'2021-11-12' AS Date), N'3', CAST(N'2021-12-19T14:23:35.000' AS DateTime)),
        ( N'1Q22    ', N'T', CAST(N'2021-11-12' AS Date), N'3', CAST(N'2021-12-28T13:05:44.000' AS DateTime)),
        ( N'P102    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2021-12-21T00:16:48.000' AS DateTime)),
        ( N'P102    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2021-12-21T05:57:11.000' AS DateTime)),
        ( N'1A22    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2021-12-18T08:10:03.000' AS DateTime)),
        ( N'1A22    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2021-12-23T15:21:15.000' AS DateTime)),
        ( N'1A22    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2021-12-23T22:09:33.000' AS DateTime)),
        ( N'1A22    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2021-12-24T06:57:16.000' AS DateTime)),
        ( N'1A22    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2021-12-24T07:12:44.000' AS DateTime)),
        ( N'1A22    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2021-12-29T03:00:31.000' AS DateTime)),
        ( N'O683    ', N'P', CAST(N'2021-11-12' AS Date), N'3', CAST(N'2022-01-14T18:17:29.000' AS DateTime)),
        ( N'O683    ', N'P', CAST(N'2021-11-12' AS Date), N'3', CAST(N'2022-01-15T12:36:38.000' AS DateTime)),
        ( N'1B22    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2022-01-06T16:54:18.000' AS DateTime)),
        ( N'1B22    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2022-01-07T11:49:07.000' AS DateTime)),
        ( N'0107    ', N'C', CAST(N'2022-01-07' AS Date), N'3', CAST(N'2021-12-23T18:30:38.000' AS DateTime)),
        ( N'0107    ', N'C', CAST(N'2022-01-07' AS Date), N'3', CAST(N'2022-01-08T21:07:04.000' AS DateTime)),
        ( N'0107    ', N'C', CAST(N'2022-01-07' AS Date), N'3', CAST(N'2022-01-09T00:24:45.000' AS DateTime)),
        ( N'0107    ', N'C', CAST(N'2022-01-07' AS Date), N'3', CAST(N'2022-01-09T01:53:20.000' AS DateTime)),
        ( N'0107    ', N'C', CAST(N'2022-01-07' AS Date), N'3', CAST(N'2022-01-09T23:10:47.000' AS DateTime)),
        ( N'0107    ', N'C', CAST(N'2022-01-07' AS Date), N'3', CAST(N'2022-01-10T03:37:06.000' AS DateTime)),
        ( N'0107    ', N'C', CAST(N'2022-01-07' AS Date), N'3', CAST(N'2022-01-10T09:24:25.000' AS DateTime)),
        ( N'P896    ', N'P', CAST(N'2022-01-28' AS Date), N'3', CAST(N'2021-12-31T08:29:40.000' AS DateTime)),
        ( N'P896    ', N'P', CAST(N'2022-01-28' AS Date), N'3', CAST(N'2022-01-02T10:04:27.000' AS DateTime)),
        ( N'P896    ', N'P', CAST(N'2022-01-28' AS Date), N'3', CAST(N'2022-01-03T13:53:18.000' AS DateTime)),
        ( N'P896    ', N'P', CAST(N'2022-01-28' AS Date), N'3', CAST(N'2022-01-05T00:00:37.000' AS DateTime)),
        ( N'P896    ', N'P', CAST(N'2022-01-28' AS Date), N'3', CAST(N'2022-01-05T00:58:14.000' AS DateTime)),
        ( N'P896    ', N'P', CAST(N'2022-01-28' AS Date), N'3', CAST(N'2022-01-07T05:54:35.000' AS DateTime)),
        ( N'P896    ', N'P', CAST(N'2022-01-28' AS Date), N'3', CAST(N'2022-01-07T13:48:40.000' AS DateTime)); "

DROP TABLE IF EXISTS temp_UnMatching_Mail

SELECT * INTO dbo.temp_UnMatching_Mail FROM
    (
    SELECT 'PM' As RecType, Mail_Date,Job_Num,Mail_Cat,Mail_Class, COUNT(*) AS Total
      FROM dbo.temp_Matching_table
     WHERE Job_Num IS NOT NULL
       AND Mail_Date <= Cast(TR_Scan_Date AS Date)
     GROUP BY Mail_Date,Job_Num,Mail_Cat,Mail_Class
    UNION ALL
    SELECT 'FM' As RecType, Mail_Date,Job_Num,Mail_Cat,Mail_Class, COUNT(*) AS Total
      FROM dbo.temp_Matching_table
     WHERE Job_Num IS NOT NULL
       AND Mail_Date > Cast(TR_Scan_Date AS Date)
     GROUP BY Mail_Date,Job_Num,Mail_Cat,Mail_Class
    ) a
 ORDER BY RecType, Mail_Date, Job_Num, Mail_Cat, Mail_Class

    SELECT SUM(CASE WHEN JOB_NUM IS NULL THEN 1 ELSE 0 END) AS [Not_Found]
          ,SUM(CASE WHEN Mail_Date < Cast(TR_Scan_Date AS Date) THEN 1 ELSE 0 END) AS [Past_Mail_Date]
          ,SUM(CASE WHEN Mail_Date >= Cast(TR_Scan_Date AS Date) THEN 1 ELSE 0 END) AS [Future_Mail_Date]
          ,COUNT(*) AS Total
    FROM dbo.temp_Matching_table
    for xml auto, elements, type, root('Summary')

    SELECT
        oh.FileType,
        P.Mail_Date,
        P.Job_Num,
        P.Mail_Cat,
        P.Mail_Class,
        P.Total
    FROM [dbo].[Temp_UnMatching_Mail] P
    INNER JOIN
            (
            SELECT  RecType,
                    CASE RecType
                    WHEN 'FM' THEN 'Future Mail    '
                    WHEN 'PM' THEN 'Past Mail      '
                    END AS FileType
            FROM Temp_UnMatching_Mail
            GROUP BY RecType
            ) oh
    ON p.RecType = oh.RecType
    for xml auto, elements, type, root('History')
</code>```

答:
Ultimately the answer to combining two different queries is to use a outside select.

Select
(Query1 results), (Query2 Results)

```<code>if  exists  (
            SELECT 1
            FROM [dbo].[temp_UnMatching_Mail]
            )
begin
    SELECT
    (
    SELECT oh.FileType
          ,s.Not_Found
          ,s.Past_Mail_Date
          ,s.Future_Mail_Date
          ,s.Total
     FROM
        (SELECT SUM(CASE WHEN JOB_NUM IS NULL THEN 1 ELSE 0 END) AS [Not_Found]
               ,SUM(CASE WHEN Mail_Date < Cast(TR_Scan_Date AS Date) THEN 1 ELSE 0 END) AS [Past_Mail_Date]
               ,SUM(CASE WHEN Mail_Date >= Cast(TR_Scan_Date AS Date) THEN 1 ELSE 0 END) AS [Future_Mail_Date]
               ,COUNT(*) AS Total
        FROM dbo.temp_Matching_table2 ) S
    INNER JOIN
        (SELECT 'Unmatch to Mailing Breakdown' AS FileType ) oh
    ON 1 = 1

    for xml auto, elements, type, root('Summary')
    ),

    (
    SELECT
        oh.FileType,
        P.Mail_Date,
        P.Job_Num,
        P.Mail_Cat,
        P.Mail_Class,
        P.Total
    FROM [dbo].[temp_UnMatching_Mail] P
    INNER JOIN
            (
            SELECT  RecType,
                    CASE RecType
                    WHEN 'FM' THEN 'Unmatched Future Mail Dates (Mailed Early?) '
                    WHEN 'PM' THEN 'Unmatched Past Mail Dates (Missing History?) '
                    END AS FileType
            FROM temp_UnMatching_Mail
            GROUP BY RecType
            ) oh
    ON p.RecType = oh.RecType
    for xml auto, elements, type, root('History')
    )
    for xml path('Stats')
end

else    select cast('<NoRecords>No records available.</NoRecords>' as xml)
</code>```

Body:
I need to produce a report that will be emailed so I am using XML format. I an currently producing the mail below and now have been asked to add a summary to the top. My SQL XML knowledge is lacking when it comes to combining the results of two queries into one XML. I can provide a script to create a input table if you need it. Thanks in advance.

Sample Data

   DROP TABLE IF EXISTS [dbo].[temp_Matching_table2]

    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[temp_Matching_table2]
    (
        [Job_Num] [varchar](8) NULL,
        [Mail_Cat] [char](1) NULL,
        [Mail_Date] [date] NULL,
        [Mail_Class] [char](1) NULL,
        [TR_Scan_Date] [datetime] NOT NULL
    ) ON [PRIMARY]

    GO
    INSERT [dbo].[temp_Matching_table2]
        ([Job_Num], [Mail_Cat], [Mail_Date], [Mail_Class], [TR_Scan_Date])
    VALUES
        (NULL, NULL, NULL, NULL, CAST(N'2021-12-27T09:41:19.000' AS DateTime)),
        (NULL, NULL, NULL, NULL, CAST(N'2022-01-10T21:17:43.000' AS DateTime)),
        ( N'1Q22    ', N'T', CAST(N'2021-11-12' AS Date), N'3', CAST(N'2021-12-18T15:24:56.000' AS DateTime)),
        ( N'1Q22    ', N'T', CAST(N'2021-11-12' AS Date), N'3', CAST(N'2021-12-19T14:23:35.000' AS DateTime)),
        ( N'1Q22    ', N'T', CAST(N'2021-11-12' AS Date), N'3', CAST(N'2021-12-28T13:05:44.000' AS DateTime)),
        ( N'P102    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2021-12-21T00:16:48.000' AS DateTime)),
        ( N'P102    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2021-12-21T05:57:11.000' AS DateTime)),
        ( N'1A22    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2021-12-18T08:10:03.000' AS DateTime)),
        ( N'1A22    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2021-12-23T15:21:15.000' AS DateTime)),
        ( N'1A22    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2021-12-23T22:09:33.000' AS DateTime)),
        ( N'1A22    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2021-12-24T06:57:16.000' AS DateTime)),
        ( N'1A22    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2021-12-24T07:12:44.000' AS DateTime)),
        ( N'1A22    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2021-12-29T03:00:31.000' AS DateTime)),
        ( N'O683    ', N'P', CAST(N'2021-11-12' AS Date), N'3', CAST(N'2022-01-14T18:17:29.000' AS DateTime)),
        ( N'O683    ', N'P', CAST(N'2021-11-12' AS Date), N'3', CAST(N'2022-01-15T12:36:38.000' AS DateTime)),
        ( N'1B22    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2022-01-06T16:54:18.000' AS DateTime)),
        ( N'1B22    ', N'T', CAST(N'2021-12-27' AS Date), N'3', CAST(N'2022-01-07T11:49:07.000' AS DateTime)),
        ( N'0107    ', N'C', CAST(N'2022-01-07' AS Date), N'3', CAST(N'2021-12-23T18:30:38.000' AS DateTime)),
        ( N'0107    ', N'C', CAST(N'2022-01-07' AS Date), N'3', CAST(N'2022-01-08T21:07:04.000' AS DateTime)),
        ( N'0107    ', N'C', CAST(N'2022-01-07' AS Date), N'3', CAST(N'2022-01-09T00:24:45.000' AS DateTime)),
        ( N'0107    ', N'C', CAST(N'2022-01-07' AS Date), N'3', CAST(N'2022-01-09T01:53:20.000' AS DateTime)),
        ( N'0107    ', N'C', CAST(N'2022-01-07' AS Date), N'3', CAST(N'2022-01-09T23:10:47.000' AS DateTime)),
        ( N'0107    ', N'C', CAST(N'2022-01-07' AS Date), N'3', CAST(N'2022-01-10T03:37:06.000' AS DateTime)),
        ( N'0107    ', N'C', CAST(N'2022-01-07' AS Date), N'3', CAST(N'2022-01-10T09:24:25.000' AS DateTime)),
        ( N'P896    ', N'P', CAST(N'2022-01-28' AS Date), N'3', CAST(N'2021-12-31T08:29:40.000' AS DateTime)),
        ( N'P896    ', N'P', CAST(N'2022-01-28' AS Date), N'3', CAST(N'2022-01-02T10:04:27.000' AS DateTime)),
        ( N'P896    ', N'P', CAST(N'2022-01-28' AS Date), N'3', CAST(N'2022-01-03T13:53:18.000' AS DateTime)),
        ( N'P896    ', N'P', CAST(N'2022-01-28' AS Date), N'3', CAST(N'2022-01-05T00:00:37.000' AS DateTime)),
        ( N'P896    ', N'P', CAST(N'2022-01-28' AS Date), N'3', CAST(N'2022-01-05T00:58:14.000' AS DateTime)),
        ( N'P896    ', N'P', CAST(N'2022-01-28' AS Date), N'3', CAST(N'2022-01-07T05:54:35.000' AS DateTime)),
        ( N'P896    ', N'P', CAST(N'2022-01-28' AS Date), N'3', CAST(N'2022-01-07T13:48:40.000' AS DateTime)); "

DROP TABLE IF EXISTS temp_UnMatching_Mail

SELECT * INTO dbo.temp_UnMatching_Mail FROM
    (
    SELECT 'PM' As RecType, Mail_Date,Job_Num,Mail_Cat,Mail_Class, COUNT(*) AS Total
      FROM dbo.temp_Matching_table
     WHERE Job_Num IS NOT NULL
       AND Mail_Date <= Cast(TR_Scan_Date AS Date)
     GROUP BY Mail_Date,Job_Num,Mail_Cat,Mail_Class
    UNION ALL
    SELECT 'FM' As RecType, Mail_Date,Job_Num,Mail_Cat,Mail_Class, COUNT(*) AS Total
      FROM dbo.temp_Matching_table
     WHERE Job_Num IS NOT NULL
       AND Mail_Date > Cast(TR_Scan_Date AS Date)
     GROUP BY Mail_Date,Job_Num,Mail_Cat,Mail_Class
    ) a
 ORDER BY RecType, Mail_Date, Job_Num, Mail_Cat, Mail_Class

    SELECT SUM(CASE WHEN JOB_NUM IS NULL THEN 1 ELSE 0 END) AS [Not_Found]
          ,SUM(CASE WHEN Mail_Date < Cast(TR_Scan_Date AS Date) THEN 1 ELSE 0 END) AS [Past_Mail_Date]
          ,SUM(CASE WHEN Mail_Date >= Cast(TR_Scan_Date AS Date) THEN 1 ELSE 0 END) AS [Future_Mail_Date]
          ,COUNT(*) AS Total
    FROM dbo.temp_Matching_table
    for xml auto, elements, type, root('Summary')

    SELECT
        oh.FileType,
        P.Mail_Date,
        P.Job_Num,
        P.Mail_Cat,
        P.Mail_Class,
        P.Total
    FROM [dbo].[Temp_UnMatching_Mail] P
    INNER JOIN
            (
            SELECT  RecType,
                    CASE RecType
                    WHEN 'FM' THEN 'Future Mail    '
                    WHEN 'PM' THEN 'Past Mail      '
                    END AS FileType
            FROM Temp_UnMatching_Mail
            GROUP BY RecType
            ) oh
    ON p.RecType = oh.RecType
    for xml auto, elements, type, root('History')

Body:
Ultimately the answer to combining two different queries is to use a outside select.

Select
(Query1 results), (Query2 Results)

if  exists  (
            SELECT 1
            FROM [dbo].[temp_UnMatching_Mail]
            )
begin
    SELECT
    (
    SELECT oh.FileType
          ,s.Not_Found
          ,s.Past_Mail_Date
          ,s.Future_Mail_Date
          ,s.Total
     FROM
        (SELECT SUM(CASE WHEN JOB_NUM IS NULL THEN 1 ELSE 0 END) AS [Not_Found]
               ,SUM(CASE WHEN Mail_Date < Cast(TR_Scan_Date AS Date) THEN 1 ELSE 0 END) AS [Past_Mail_Date]
               ,SUM(CASE WHEN Mail_Date >= Cast(TR_Scan_Date AS Date) THEN 1 ELSE 0 END) AS [Future_Mail_Date]
               ,COUNT(*) AS Total
        FROM dbo.temp_Matching_table2 ) S
    INNER JOIN
        (SELECT 'Unmatch to Mailing Breakdown' AS FileType ) oh
    ON 1 = 1

    for xml auto, elements, type, root('Summary')
    ),

    (
    SELECT
        oh.FileType,
        P.Mail_Date,
        P.Job_Num,
        P.Mail_Cat,
        P.Mail_Class,
        P.Total
    FROM [dbo].[temp_UnMatching_Mail] P
    INNER JOIN
            (
            SELECT  RecType,
                    CASE RecType
                    WHEN 'FM' THEN 'Unmatched Future Mail Dates (Mailed Early?) '
                    WHEN 'PM' THEN 'Unmatched Past Mail Dates (Missing History?) '
                    END AS FileType
            FROM temp_UnMatching_Mail
            GROUP BY RecType
            ) oh
    ON p.RecType = oh.RecType
    for xml auto, elements, type, root('History')
    )
    for xml path('Stats')
end

else    select cast('<NoRecords>No records available.</NoRecords>' as xml)


问:
Not able to switch to popup window in pycahrm
```<code>    def switch_to_popup(self):
    my_popup = self.driver.find_element(By.XPATH, '//*[@id="a-popover-1"]')
    self.driver.switch_to(my_popup)
</code>```

Using the above function to switch to popup in the following url -> https://www.amazon.in/
but getting the following error -> TypeError: 'SwitchTo' object is not callable

Click on the following to get the popup manually -> https://prnt.sc/26bpmr0

答:
I'm not sure if switch_to is needed. The below allows you to click on the "Select your address" button and then input some postcode:</p>
```<code>def switch_to_popup():
driver.find_element_by_css_selector('.nav-a.nav-a-2.a-popover-trigger.a-declarative.nav-progressive-attribute').click()
time.sleep(2)
# Type a postcode
driver.find_element_by_id("GLUXZipUpdateInput").send_keys("Hello_")
</code>```

Body:
    def switch_to_popup(self):
    my_popup = self.driver.find_element(By.XPATH, '//*[@id="a-popover-1"]')
    self.driver.switch_to(my_popup)

Using the above function to switch to popup in the following url -> https://www.amazon.in/
but getting the following error -> TypeError: 'SwitchTo' object is not callable

Click on the following to get the popup manually -> https://prnt.sc/26bpmr0

Body:
I'm not sure if switch_to is needed. The below allows you to click on the "Select your address" button and then input some postcode:

def switch_to_popup():
driver.find_element_by_css_selector('.nav-a.nav-a-2.a-popover-trigger.a-declarative.nav-progressive-attribute').click()
time.sleep(2)
# Type a postcode
driver.find_element_by_id("GLUXZipUpdateInput").send_keys("Hello_")


问:
How to set default python3 to python 3.9 instead of python 3.8 in Ubuntu 20.04 LTS
I have installed Python 3.9 in the Ubuntu 20.04 LTS. Now the system has both Python 3.8 and Python 3.9.

```<code># which python
# which python3
/usr/bin/python3
# which python3.8
/usr/bin/python3.8
# which python3.9
/usr/bin/python3.9
# ls -alith /usr/bin/python3
12583916 lrwxrwxrwx 1 root root 9 Jul 19  2021 /usr/bin/python3 -> python3.8
</code>```

But the pip3 command will still install everything into the Python 3.8 directory.

```<code># pip3 install --upgrade --find-links file:///path/to/directory <...>
</code>```

I want to change that default pip3 behavior by updating the symbolic link /usr/bin/python3 to /usr/bin/python3.9.

How to do that?

```<code># update-alternatives --set python3 /usr/bin/python3.9
This command will not work as expected.
</code>```

Here is the pip3 info:

```<code># which pip3
/usr/bin/pip3
# ls -alith /usr/bin/pip3
12589712 -rwxr-xr-x 1 root root 367 Jul 13  2021 /usr/bin/pip3
# pip3 -V
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
#
</code>```

The alias command will not work:

```<code># alias python3=python3.9
# ls -alith /usr/bin/python3
12583916 lrwxrwxrwx 1 root root 9 Jul 19  2021 /usr/bin/python3 -> python3.8
</code>```

答:
You should be able to use python3.9 -m pip install <package> to run pip with a specific python version, in this case 3.9.

The full docs on this are here: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/

If you want python3 to point to python3.9 you could use the quick and dirty.

```<code>alias python3=python3.9
</code>```

EDIT:

Tried to recreate your problem,

```<code># which python3
/usr/bin/python3
# python3 --version
Python 3.8.10
# which python3.8
/usr/bin/python3.8
# which python3.9
/usr/bin/python3.9
</code>```

Then update the alternatives, and set new priority:

```<code># sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
# sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
# sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.9   2         auto mode
  1            /usr/bin/python3.8   2         manual mode
* 2            /usr/bin/python3.9   2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 0
</code>```

Check new version:

```<code># ls -alith /usr/bin/python3
3338 lrwxrwxrwx 1 root root 25 Feb  8 14:33 /usr/bin/python3 -> /etc/alternatives/python3
# python3 -V
Python 3.9.5
# ls -alith /usr/bin/pip3
48482 -rwxr-xr-x 1 root root 367 Jul 13  2021 /usr/bin/pip3
# pip3 -V
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.9)
</code>```

Hope this helps (tried it in wsl2 Ubuntu 20.04 LTS)

Body:
I have installed Python 3.9 in the Ubuntu 20.04 LTS. Now the system has both Python 3.8 and Python 3.9.

# which python
# which python3
/usr/bin/python3
# which python3.8
/usr/bin/python3.8
# which python3.9
/usr/bin/python3.9
# ls -alith /usr/bin/python3
12583916 lrwxrwxrwx 1 root root 9 Jul 19  2021 /usr/bin/python3 -> python3.8

But the pip3 command will still install everything into the Python 3.8 directory.

# pip3 install --upgrade --find-links file:///path/to/directory <...>

I want to change that default pip3 behavior by updating the symbolic link /usr/bin/python3 to /usr/bin/python3.9.

How to do that?

# update-alternatives --set python3 /usr/bin/python3.9
This command will not work as expected.

Here is the pip3 info:

# which pip3
/usr/bin/pip3
# ls -alith /usr/bin/pip3
12589712 -rwxr-xr-x 1 root root 367 Jul 13  2021 /usr/bin/pip3
# pip3 -V
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
#

The alias command will not work:

# alias python3=python3.9
# ls -alith /usr/bin/python3
12583916 lrwxrwxrwx 1 root root 9 Jul 19  2021 /usr/bin/python3 -> python3.8

Body:
You should be able to use python3.9 -m pip install <package> to run pip with a specific python version, in this case 3.9.

The full docs on this are here: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/

If you want python3 to point to python3.9 you could use the quick and dirty.

alias python3=python3.9

EDIT:

Tried to recreate your problem,

# which python3
/usr/bin/python3
# python3 --version
Python 3.8.10
# which python3.8
/usr/bin/python3.8
# which python3.9
/usr/bin/python3.9

Then update the alternatives, and set new priority:

# sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
# sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
# sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.9   2         auto mode
  1            /usr/bin/python3.8   2         manual mode
* 2            /usr/bin/python3.9   2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 0

Check new version:

# ls -alith /usr/bin/python3
3338 lrwxrwxrwx 1 root root 25 Feb  8 14:33 /usr/bin/python3 -> /etc/alternatives/python3
# python3 -V
Python 3.9.5
# ls -alith /usr/bin/pip3
48482 -rwxr-xr-x 1 root root 367 Jul 13  2021 /usr/bin/pip3
# pip3 -V
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.9)

Hope this helps (tried it in wsl2 Ubuntu 20.04 LTS)


问:
C# Datetime is increasing by 3 hours
My dates are being stored in sql server.

Windows server region and timezone are correct, but when I see the date in database it's increased by 3 hours, I think it is comming from some server configuration that is overriding, but don't know where else to look.

When I send date from local project to production database, it saves correctly, but when I use production website it doesn't.

Where else should I check to solve this?

答:
It depends on the codebase running your production portal.

Use Datetime as utc and cater for it accordingly. Or add DatetimeOffset and calculate the difference when needed.

If you still have the luxury of refactoring, I advise you to take a little dive into the Dates and time handling, get a solid understanding of it, then code accordingly, so it doesn't fire back on you in later stages or usages.

Title: C# Datetime is increasing by 3 hours


问:
How to test if a valid Method exists when params are involved
I have the following method:

```<code>    public MethodInfo FancyGetMethodInfo
         (object obj, string methodName, Type[] methodSignature)
    {
        return obj.GetType().GetMethod(methodName, methodSignature);
    }
</code>```

and for the sake of an example I have in my object I am passing the two methods

```<code>    public int Subtract(int a, int b) { return a - b; }

    public int Add(params int[] a) { return a.Sum(); }
</code>```

And when I execute the following lines I get these results:

```<code>        var SubMethod = FancyGetMethodInfo(obj, "Subtract",
                         new Type[] { typeof(int), typeof(int) });
        //I get a MethodInfo
        var AddMethod = FancyGetMethodInfo(obj, "Add",
                         new Type[] { typeof(int), typeof(int) });
        //I get a Null reference
</code>```

I'm sure this is because of the params in Add. Is there a clean way to get reference to my MethodInfo for my Add method given an arbitrary sized Type[] containing ints and only having access to the provided variables in my FancyGetMethodInfo method?

Edit:
More eloquently put by Jon Skeet, I want to perform the same binding as the C# compiler does in my method. it needs to work properly with subclasses, implicit casting, arbitrary length params, etc...

Also as requested, a relevant link here is: Determining if a parameter uses "params" using reflection in C#? which will get me as far as knowing that the method has a params.

答:
A params parameter is nothing more than syntactic sugar for a plain array.

```<code>    int Add(params int[] a)
</code>```

is equivalent form a CLR perspective to

```<code>    int Add(int[] a)
</code>```

the params modifier is simply C# syntactic sugar.

This means if you want to find you method using reflection you will need the following call:

```<code>var AddMethod = FancyGetMethodInfo(obj, "Add",
                         new Type[] { typeof(int[]) });
</code>```

if you further wan to test whether the method contains a params parameter you need to test if it has the ParamArrayAttribute applied to the last parameter of the method.

ContentLicense: CC BY-SA 3.0

Body:
I have the following method:

    public MethodInfo FancyGetMethodInfo
         (object obj, string methodName, Type[] methodSignature)
    {
        return obj.GetType().GetMethod(methodName, methodSignature);
    }

and for the sake of an example I have in my object I am passing the two methods

    public int Subtract(int a, int b) { return a - b; }

    public int Add(params int[] a) { return a.Sum(); }

And when I execute the following lines I get these results:

        var SubMethod = FancyGetMethodInfo(obj, "Subtract",
                         new Type[] { typeof(int), typeof(int) });
        //I get a MethodInfo
        var AddMethod = FancyGetMethodInfo(obj, "Add",
                         new Type[] { typeof(int), typeof(int) });
        //I get a Null reference

I'm sure this is because of the params in Add. Is there a clean way to get reference to my MethodInfo for my Add method given an arbitrary sized Type[] containing ints and only having access to the provided variables in my FancyGetMethodInfo method?

Edit:
More eloquently put by Jon Skeet, I want to perform the same binding as the C# compiler does in my method. it needs to work properly with subclasses, implicit casting, arbitrary length params, etc...

Also as requested, a relevant link here is: Determining if a parameter uses "params" using reflection in C#? which will get me as far as knowing that the method has a params.

Body:
A params parameter is nothing more than syntactic sugar for a plain array.

    int Add(params int[] a)

is equivalent form a CLR perspective to

    int Add(int[] a)

the params modifier is simply C# syntactic sugar.

This means if you want to find you method using reflection you will need the following call:

var AddMethod = FancyGetMethodInfo(obj, "Add",
                         new Type[] { typeof(int[]) });

if you further wan to test whether the method contains a params parameter you need to test if it has the ParamArrayAttribute applied to the last parameter of the method.


问:
Adding Ranking to Datatables
I am trying to calculate rank based on the total number of points in a datatable

The Javascript is getting the correct values and ranking correctly in the console, however it is not placing the value in the datatable

```<code> $(function() {

        var table=$('#points-table').DataTable({
            processing: true,
            serverSide: true,
            ajax: 'http://localhost/edpark/public/get/points',
            columns: [
                { data: 'rank', defaultContent: ''},
                { data: 'first_name'},
                { data: 'last_name'},
                { data: 'TotalPoints'},
            ],
                drawCallback: function () {
                api = this.api();
                var arr = api.columns(3).data()[0];  //get array of column 3 (extn)
                console.log(arr);
                var sorted = arr.slice().sort(function(a,b){return b-a});
                var ranks = arr.slice().map(function(v){ return sorted.indexOf(v)+1 });
                console.log(sorted);
                console.log(ranks);
                // interate through each row
                api.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
                    var data = this.data();
                    var rank = ranks[rowLoop];
                    data.rank = ranks[arr.indexOf(data.extn)];  //set the rank column = the array index of the extn in the ranked array
             } );
        api.rows().invalidate();
        }
        });
    })
</code>```

I have 3 rows in my dev table which have a total point of 60, 10, 5 which is being written into the console correctly, and being ranked 1,2,3

However in my table, the Rank field is still blank.

Thank you

Edit

Adding Requested HTML Code and Dataset

HTML

```<code>@extends('layouts.app')

@section('content')
<div class="container-fluid">
    @if(session()->has('success'))
        <div class="row">
            <div class="col-12 alert alert-success" role="alert">
                <strong>{{session()->get('success')}}</strong>
            </div>
        </div>
    @endif
    @if(session()->has('failure'))
        <div class="row">
            <div class="col-12 alert alert-danger" role="alert">
                <strong>{{session()->get('failure')}}</strong>
            </div>
        </div>
    @endif
    <div class="row">
        <div class="col-lg-12 col-sm-12">
            <div class="card">
                <div class="card-body">
                    <h3 class="text-center">Points Report</h3>

                    <div class="table-responsive">
                        <table class="table table-striped table-no-boreded table-hover" width="100%" id="points-table">
                            <thead class = "text-primary">
                            <h4> </h4>
                                <tr>
                                    <th class="text-center">Rank</th>
                                    <th class="text-center">First Name</th>
                                    <th class="text-center">Last Name</th>
                                    <th class="text-center">Total Points</th>
                                    <th width="10%"></th>
                                </tr>
                            </thead>
                            <tbody class = "text-center">
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@endsection
</code>```

Dataset

```<code>Member_id| Points | Reason |
    1        10       --
    5        60       --
    4        10       --
    1        -5       --
</code>```

Hope this helps

答:
When you perform an action such as adding or deleting a row, changing the sorting, filtering or paging characteristics of the table you'll want DataTables to update the display to reflect these changes.

api.draw() >>> This function is provided for that purpose

Title: Adding Ranking to Datatables

Body:
I am trying to calculate rank based on the total number of points in a datatable

The Javascript is getting the correct values and ranking correctly in the console, however it is not placing the value in the datatable

 $(function() {

        var table=$('#points-table').DataTable({
            processing: true,
            serverSide: true,
            ajax: 'http://localhost/edpark/public/get/points',
            columns: [
                { data: 'rank', defaultContent: ''},
                { data: 'first_name'},
                { data: 'last_name'},
                { data: 'TotalPoints'},
            ],
                drawCallback: function () {
                api = this.api();
                var arr = api.columns(3).data()[0];  //get array of column 3 (extn)
                console.log(arr);
                var sorted = arr.slice().sort(function(a,b){return b-a});
                var ranks = arr.slice().map(function(v){ return sorted.indexOf(v)+1 });
                console.log(sorted);
                console.log(ranks);
                // interate through each row
                api.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
                    var data = this.data();
                    var rank = ranks[rowLoop];
                    data.rank = ranks[arr.indexOf(data.extn)];  //set the rank column = the array index of the extn in the ranked array
             } );
        api.rows().invalidate();
        }
        });
    })

I have 3 rows in my dev table which have a total point of 60, 10, 5 which is being written into the console correctly, and being ranked 1,2,3

However in my table, the Rank field is still blank.

Thank you

Edit

Adding Requested HTML Code and Dataset

HTML

@extends('layouts.app')

@section('content')

    @if(session()->has('success'))

                {{session()->get('success')}}

    @endif
    @if(session()->has('failure'))

                {{session()->get('failure')}}

    @endif

Points Report

                                    Rank
                                    First Name
                                    Last Name
                                    Total Points

@endsection

Dataset

Member_id| Points | Reason |
    1        10       --
    5        60       --
    4        10       --
    1        -5       --

Hope this helps


问:
How to chomp lines in conditional statements in tf templates?
I'm doing this in a template:

```<code>%{ if myvar != "sss" }
bunch
of
text
%{ else }
some
other
text
%{ endif }
</code>```

This works but there is a new line where the if statement is. I could put the first line of the block of text on the same line but I don't consider this readable:

```<code>%{ if myvar != "sss" }bunch
of
text
%{ else }some
other
text%{ endif }
</code>```

In Go templates. I could do something like this to chomp the new lines:

```<code>%{- if myvar != "sss" }
bunch
of
text
%{- else }
some
other
text
%{- endif }
</code>```

How do you do this in tf?

答:
actually ~ in the end might cause you missconfiguration, when you try to create yaml file for example

```<code>foo:
  aaa: aaa
  %{ if enabled ~}
  bar:
    baz: ${baz}
  %{ endif ~}
  bbb: bbb
</code>```

gives you wron yaml like this:

```<code>> templatefile("sss.yaml", {enabled=true,baz="baz"})
foo:
  aaa: aaa
    bar:
    baz: baz
    bbb: bbb
</code>```

this one will return correct yaml but with new lins

```<code>foo:
  aaa: aaa
  %{ if enabled }
  bar:
    baz: ${baz}
  %{ endif }
  bbb: bbb
</code>```
```<code>> templatefile("sss.yaml", {enabled=true,baz="baz"})
foo:
  aaa: aaa

  bar:
    baz: baz

  bbb: bbb

</code>```

so to get correct file you have to plase ~ befo and after your expression

```<code>foo:
  aaa: aaa
  %{~ if enabled ~}
  bar:
    baz: ${baz}
  %{~ endif ~}
  bbb: bbb
</code>```
```<code>> templatefile("sss.yaml", {enabled=true,baz="baz"})
foo:
  aaa: aaa
  bar:
    baz: baz
  bbb: bbb
</code>```

Body:
I'm doing this in a template:

%{ if myvar != "sss" }
bunch
of
text
%{ else }
some
other
text
%{ endif }

This works but there is a new line where the if statement is. I could put the first line of the block of text on the same line but I don't consider this readable:

%{ if myvar != "sss" }bunch
of
text
%{ else }some
other
text%{ endif }

In Go templates. I could do something like this to chomp the new lines:

%{- if myvar != "sss" }
bunch
of
text
%{- else }
some
other
text
%{- endif }

How do you do this in tf?

Body:
actually ~ in the end might cause you missconfiguration, when you try to create yaml file for example

foo:
  aaa: aaa
  %{ if enabled ~}
  bar:
    baz: ${baz}
  %{ endif ~}
  bbb: bbb

gives you wron yaml like this:

> templatefile("sss.yaml", {enabled=true,baz="baz"})
foo:
  aaa: aaa
    bar:
    baz: baz
    bbb: bbb

this one will return correct yaml but with new lins

foo:
  aaa: aaa
  %{ if enabled }
  bar:
    baz: ${baz}
  %{ endif }
  bbb: bbb

> templatefile("sss.yaml", {enabled=true,baz="baz"})
foo:
  aaa: aaa

  bar:
    baz: baz

  bbb: bbb

so to get correct file you have to plase ~ befo and after your expression

foo:
  aaa: aaa
  %{~ if enabled ~}
  bar:
    baz: ${baz}
  %{~ endif ~}
  bbb: bbb

> templatefile("sss.yaml", {enabled=true,baz="baz"})
foo:
  aaa: aaa
  bar:
    baz: baz
  bbb: bbb