Queries for Orders


1. Orders placed by customers from 'UK' OR 'Germany', AND the order date is after '1997-01-01', AND the Freight is greater than 50, OR the order was handled by an employee whose TitleOfCourtesy is 'Dr.'.

SQL Server Query 1

            
 SELECT  
o.OrderID,
c.CompanyName,
c.Country,
o.OrderDate,
o.Freight,
e.FirstName,
e.LastName,
e.TitleOfCourtesy
FROM Orders o
JOIN Customers c ON o.CustomerID = c.CustomerID
JOIN Employees e ON o.EmployeeID = e.EmployeeID
WHERE
(
(c.Country = 'UK' OR c.Country = 'Germany') -- Customers from UK or Germany
AND o.OrderDate > '1997-01-01' -- Order placed after specific date
AND o.Freight > 50 -- Freight is expensive
)
OR
(e.TitleOfCourtesy = 'Dr.'); -- OR handled by an employee with 'Dr.' title

Create SQL query with SqlQueryBuilder 1

            
 var (sql1, parameters1) = new SqlQueryBuilder()  
.Select()
.Columns("o.OrderID"," c.CompanyName"," c.Country"," o.OrderDate"," o.Freight"," e.FirstName"," e.LastName"," e.TitleOfCourtesy")
.From("Orders", "o")
.Join(new List<IJoin>()
{
new INNERJOIN().TableName("Customers","c")
.On(new Column("o.CustomerID").Equale(new Column("c.CustomerID"))),
new INNERJOIN().TableName("Employees","e")
.On(new Column("o.EmployeeID").Equale(new Column("e.EmployeeID")))
})
.Where(
new Where().StartBracket()
.StartBracket(new Column("c.Country").Equale("UK")).OR(new Column("c.Country").Equale("Germany")).EndBracket()
.AND(new Column("o.OrderDate").GreaterThan("1997-01-01"))
.AND(new Column("o.Freight").GreaterThan(50))
.EndBracket().OR(new Column("e.TitleOfCourtesy").Equale("Dr."))
)
.Build();

Query build by SqlQueryBuilder 1

            
SELECT o.OrderID,
       c.CompanyName,
       c.Country,
       o.OrderDate,
       o.Freight,
       e.FirstName,
       e.LastName,
       e.TitleOfCourtesy
FROM Orders AS o
     INNER JOIN
     Customers AS c
     ON o.CustomerID = c.CustomerID
     INNER JOIN
     Employees AS e
     ON o.EmployeeID = e.EmployeeID
WHERE ((c.Country = @pMAIN_2507192101282688520
        OR c.Country = @pMAIN_2507192101282688521)
       AND o.OrderDate > @pMAIN_2507192101282688522
       AND o.Freight > @pMAIN_2507192101282688523)
      OR e.TitleOfCourtesy = @pMAIN_2507192101282688524;


            
        

Parameters (If used)

Name Value
@pMAIN_2507192101282688520 UK
@pMAIN_2507192101282688521 Germany
@pMAIN_2507192101282688522 1997-01-01
@pMAIN_2507192101282688523 50
@pMAIN_2507192101282688524 Dr.

Query Results 1:

  OrderID CompanyName Country OrderDate Freight FirstName LastName TitleOfCourtesy
1 10265 Blondesddsl père et fils France 7/25/1996 12:00:00 AM 55.2800 Andrew Fuller Dr.
2 10277 Morgenstern Gesundkost Germany 8/9/1996 12:00:00 AM 125.7700 Andrew Fuller Dr.
3 10280 Berglunds snabbköp Sweden 8/14/1996 12:00:00 AM 8.9800 Andrew Fuller Dr.
4 10295 Vins et alcools Chevalier France 9/2/1996 12:00:00 AM 1.1500 Andrew Fuller Dr.
5 10300 Magazzini Alimentari Riuniti Italy 9/9/1996 12:00:00 AM 17.6800 Andrew Fuller Dr.
6 10307 Lonesome Pine Restaurant USA 9/17/1996 12:00:00 AM 0.5600 Andrew Fuller Dr.
7 10312 Die Wandernde Kuh Germany 9/23/1996 12:00:00 AM 40.2600 Andrew Fuller Dr.
8 10313 QUICK-Stop Germany 9/24/1996 12:00:00 AM 1.9600 Andrew Fuller Dr.
9 10327 Folk och fä HB Sweden 10/11/1996 12:00:00 AM 63.3600 Andrew Fuller Dr.
10 10339 Mère Paillarde Canada 10/28/1996 12:00:00 AM 15.6600 Andrew Fuller Dr.
11 10345 QUICK-Stop Germany 11/4/1996 12:00:00 AM 249.0600 Andrew Fuller Dr.
12 10368 Ernst Handel Austria 11/29/1996 12:00:00 AM 101.9500 Andrew Fuller Dr.
13 10379 Que Delícia Brazil 12/11/1996 12:00:00 AM 45.0300 Andrew Fuller Dr.
14 10388 Seven Seas Imports UK 12/19/1996 12:00:00 AM 34.8600 Andrew Fuller Dr.
15 10392 Piccolo und mehr Austria 12/24/1996 12:00:00 AM 122.4600 Andrew Fuller Dr.
16 10398 Save-a-lot Markets USA 12/30/1996 12:00:00 AM 89.1600 Andrew Fuller Dr.
17 10404 Magazzini Alimentari Riuniti Italy 1/3/1997 12:00:00 AM 155.9700 Andrew Fuller Dr.
18 10407 Ottilies Käseladen Germany 1/7/1997 12:00:00 AM 91.4800 Andrew Fuller Dr.
19 10414 Familia Arquibaldo Brazil 1/14/1997 12:00:00 AM 21.4800 Andrew Fuller Dr.
20 10422 Franchi S.p.A. Italy 1/22/1997 12:00:00 AM 3.0200 Andrew Fuller Dr.
21 10451 QUICK-Stop Germany 2/19/1997 12:00:00 AM 189.0900 Margaret Peacock Mrs.
22 10457 Königlich Essen Germany 2/25/1997 12:00:00 AM 11.5700 Andrew Fuller Dr.
23 10462 Consolidated Holdings UK 3/3/1997 12:00:00 AM 6.1700 Andrew Fuller Dr.
24 10471 B's Beverages UK 3/11/1997 12:00:00 AM 45.5900 Andrew Fuller Dr.
25 10478 Victuailles en stock France 3/18/1997 12:00:00 AM 4.8100 Andrew Fuller Dr.
26 10487 Queen Cozinha Brazil 3/26/1997 12:00:00 AM 71.0700 Andrew Fuller Dr.
27 10502 Pericles Comidas clásicas Mexico 4/10/1997 12:00:00 AM 69.3200 Andrew Fuller Dr.
28 10513 Die Wandernde Kuh Germany 4/22/1997 12:00:00 AM 105.6500 Robert King Mr.
29 10515 QUICK-Stop Germany 4/23/1997 12:00:00 AM 204.4700 Andrew Fuller Dr.
30 10516 Hungry Owl All-Night Grocers Ireland 4/24/1997 12:00:00 AM 62.7800 Andrew Fuller Dr.
31 10523 Seven Seas Imports UK 5/1/1997 12:00:00 AM 77.6300 Robert King Mr.
32 10532 Eastern Connection UK 5/9/1997 12:00:00 AM 74.4600 Robert King Mr.
33 10536 Lehmanns Marktstand Germany 5/14/1997 12:00:00 AM 58.8800 Janet Leverling Ms.
34 10540 QUICK-Stop Germany 5/19/1997 12:00:00 AM 1007.6400 Janet Leverling Ms.
35 10541 Hanari Carnes Brazil 5/19/1997 12:00:00 AM 68.6500 Andrew Fuller Dr.
36 10547 Seven Seas Imports UK 5/23/1997 12:00:00 AM 178.4300 Janet Leverling Ms.
37 10549 QUICK-Stop Germany 5/27/1997 12:00:00 AM 171.2400 Steven Buchanan Mr.
38 10552 HILARION-Abastos Venezuela 5/29/1997 12:00:00 AM 83.2200 Andrew Fuller Dr.
39 10553 Wartian Herkku Finland 5/30/1997 12:00:00 AM 149.4900 Andrew Fuller Dr.
40 10554 Ottilies Käseladen Germany 5/30/1997 12:00:00 AM 120.9700 Margaret Peacock Mrs.
41 10556 Simons bistro Denmark 6/3/1997 12:00:00 AM 9.8000 Andrew Fuller Dr.
42 10557 Lehmanns Marktstand Germany 6/3/1997 12:00:00 AM 96.7200 Anne Dodsworth Ms.
43 10558 Around the Horn UK 6/4/1997 12:00:00 AM 72.9700 Nancy Davolio Ms.
44 10561 Folk och fä HB Sweden 6/6/1997 12:00:00 AM 242.2100 Andrew Fuller Dr.
45 10563 Ricardo Adocicados Brazil 6/10/1997 12:00:00 AM 60.4300 Andrew Fuller Dr.
46 10575 Morgenstern Gesundkost Germany 6/20/1997 12:00:00 AM 127.3400 Steven Buchanan Mr.
47 10580 Ottilies Käseladen Germany 6/26/1997 12:00:00 AM 75.8900 Margaret Peacock Mrs.
48 10583 Wartian Herkku Finland 6/30/1997 12:00:00 AM 7.2800 Andrew Fuller Dr.
49 10588 QUICK-Stop Germany 7/3/1997 12:00:00 AM 194.6700 Andrew Fuller Dr.
50 10593 Lehmanns Marktstand Germany 7/9/1997 12:00:00 AM 174.2000 Robert King Mr.
51 10595 Ernst Handel Austria 7/10/1997 12:00:00 AM 96.7800 Andrew Fuller Dr.
52 10615 Wilman Kala Finland 7/30/1997 12:00:00 AM 0.7500 Andrew Fuller Dr.
53 10620 Laughing Bacchus Wine Cellars Canada 8/5/1997 12:00:00 AM 0.9400 Andrew Fuller Dr.
54 10623 Frankenversand Germany 8/7/1997 12:00:00 AM 97.1800 Laura Callahan Ms.
55 10653 Frankenversand Germany 9/2/1997 12:00:00 AM 93.2500 Nancy Davolio Ms.
56 10657 Save-a-lot Markets USA 9/4/1997 12:00:00 AM 352.6900 Andrew Fuller Dr.
57 10658 QUICK-Stop Germany 9/5/1997 12:00:00 AM 364.1500 Margaret Peacock Mrs.
58 10663 Bon app' France 9/10/1997 12:00:00 AM 113.1500 Andrew Fuller Dr.
59 10669 Simons bistro Denmark 9/15/1997 12:00:00 AM 24.3900 Andrew Fuller Dr.
60 10670 Frankenversand Germany 9/16/1997 12:00:00 AM 203.4800 Margaret Peacock Mrs.
61 10673 Wilman Kala Finland 9/18/1997 12:00:00 AM 22.7600 Andrew Fuller Dr.
62 10676 Tortuga Restaurante Mexico 9/22/1997 12:00:00 AM 2.0100 Andrew Fuller Dr.
63 10683 Du monde entier France 9/26/1997 12:00:00 AM 4.4000 Andrew Fuller Dr.
64 10684 Ottilies Käseladen Germany 9/26/1997 12:00:00 AM 145.6300 Janet Leverling Ms.
65 10686 Piccolo und mehr Austria 9/30/1997 12:00:00 AM 96.5000 Andrew Fuller Dr.
66 10691 QUICK-Stop Germany 10/3/1997 12:00:00 AM 810.0500 Andrew Fuller Dr.
67 10692 Alfreds Futterkiste Germany 10/3/1997 12:00:00 AM 61.0200 Margaret Peacock Mrs.
68 10694 QUICK-Stop Germany 10/6/1997 12:00:00 AM 398.3600 Laura Callahan Ms.
69 10717 Frankenversand Germany 10/24/1997 12:00:00 AM 59.2500 Nancy Davolio Ms.
70 10718 Königlich Essen Germany 10/27/1997 12:00:00 AM 170.8800 Nancy Davolio Ms.
71 10727 Reggiani Caseifici Italy 11/3/1997 12:00:00 AM 89.9000 Andrew Fuller Dr.
72 10734 Gourmet Lanchonetes Brazil 11/7/1997 12:00:00 AM 1.6300 Andrew Fuller Dr.
73 10737 Vins et alcools Chevalier France 11/11/1997 12:00:00 AM 7.7900 Andrew Fuller Dr.
74 10738 Spécialités du monde France 11/12/1997 12:00:00 AM 2.9100 Andrew Fuller Dr.
75 10749 Island Trading UK 11/20/1997 12:00:00 AM 61.5300 Margaret Peacock Mrs.
76 10752 North/South UK 11/24/1997 12:00:00 AM 1.3900 Andrew Fuller Dr.
77 10766 Ottilies Käseladen Germany 12/5/1997 12:00:00 AM 157.5500 Margaret Peacock Mrs.
78 10768 Around the Horn UK 12/8/1997 12:00:00 AM 146.3200 Janet Leverling Ms.
79 10772 Lehmanns Marktstand Germany 12/10/1997 12:00:00 AM 91.2800 Janet Leverling Ms.
80 10779 Morgenstern Gesundkost Germany 12/16/1997 12:00:00 AM 58.1300 Janet Leverling Ms.
81 10780 LILA-Supermercado Venezuela 12/16/1997 12:00:00 AM 42.1300 Andrew Fuller Dr.
82 10781 Wartian Herkku Finland 12/17/1997 12:00:00 AM 73.1600 Andrew Fuller Dr.
83 10787 La maison d'Asie France 12/19/1997 12:00:00 AM 249.9300 Andrew Fuller Dr.
84 10798 Island Trading UK 12/26/1997 12:00:00 AM 2.3300 Andrew Fuller Dr.
85 10800 Seven Seas Imports UK 12/26/1997 12:00:00 AM 137.4400 Nancy Davolio Ms.
86 10805 The Big Cheese USA 12/30/1997 12:00:00 AM 237.3400 Andrew Fuller Dr.
87 10808 Old World Delicatessen USA 1/1/1998 12:00:00 AM 45.5300 Andrew Fuller Dr.
88 10810 Laughing Bacchus Wine Cellars Canada 1/1/1998 12:00:00 AM 4.3300 Andrew Fuller Dr.
89 10815 Save-a-lot Markets USA 1/5/1998 12:00:00 AM 14.6200 Andrew Fuller Dr.
90 10817 Königlich Essen Germany 1/6/1998 12:00:00 AM 306.0700 Janet Leverling Ms.
91 10819 Cactus Comidas para llevar Argentina 1/7/1998 12:00:00 AM 19.7600 Andrew Fuller Dr.
92 10825 Drachenblut Delikatessen Germany 1/9/1998 12:00:00 AM 79.2500 Nancy Davolio Ms.
93 10829 Island Trading UK 1/13/1998 12:00:00 AM 154.7200 Anne Dodsworth Ms.
94 10832 La maison d'Asie France 1/14/1998 12:00:00 AM 43.2600 Andrew Fuller Dr.
95 10833 Ottilies Käseladen Germany 1/15/1998 12:00:00 AM 71.4900 Michael Suyama Mr.
96 10835 Alfreds Futterkiste Germany 1/15/1998 12:00:00 AM 69.5300 Nancy Davolio Ms.
97 10845 QUICK-Stop Germany 1/21/1998 12:00:00 AM 212.9800 Laura Callahan Ms.
98 10846 Suprêmes délices Belgium 1/22/1998 12:00:00 AM 56.4600 Andrew Fuller Dr.
99 10853 Blauer See Delikatessen Germany 1/27/1998 12:00:00 AM 53.8300 Anne Dodsworth Ms.
100 10858 La corne d'abondance France 1/29/1998 12:00:00 AM 52.5100 Andrew Fuller Dr.
101 10859 Frankenversand Germany 1/29/1998 12:00:00 AM 76.1000 Nancy Davolio Ms.
102 10862 Lehmanns Marktstand Germany 1/30/1998 12:00:00 AM 53.2300 Laura Callahan Ms.
103 10865 QUICK-Stop Germany 2/2/1998 12:00:00 AM 348.1400 Andrew Fuller Dr.
104 10869 Seven Seas Imports UK 2/4/1998 12:00:00 AM 143.2800 Steven Buchanan Mr.
105 10893 Königlich Essen Germany 2/18/1998 12:00:00 AM 77.7800 Anne Dodsworth Ms.
106 10912 Hungry Owl All-Night Grocers Ireland 2/26/1998 12:00:00 AM 580.9100 Andrew Fuller Dr.
107 10915 Tortuga Restaurante Mexico 2/27/1998 12:00:00 AM 3.5100 Andrew Fuller Dr.
108 10919 LINO-Delicateses Venezuela 3/2/1998 12:00:00 AM 19.8000 Andrew Fuller Dr.
109 10933 Island Trading UK 3/6/1998 12:00:00 AM 54.1500 Michael Suyama Mr.
110 10939 Magazzini Alimentari Riuniti Italy 3/10/1998 12:00:00 AM 76.3300 Andrew Fuller Dr.
111 10949 Bottom-Dollar Markets Canada 3/13/1998 12:00:00 AM 74.4400 Andrew Fuller Dr.
112 10962 QUICK-Stop Germany 3/19/1998 12:00:00 AM 275.7900 Laura Callahan Ms.
113 10967 Toms Spezialitäten Germany 3/23/1998 12:00:00 AM 62.2200 Andrew Fuller Dr.
114 10971 France restauration France 3/24/1998 12:00:00 AM 121.8200 Andrew Fuller Dr.
115 10982 Bottom-Dollar Markets Canada 3/27/1998 12:00:00 AM 14.0100 Andrew Fuller Dr.
116 10983 Save-a-lot Markets USA 3/27/1998 12:00:00 AM 657.5400 Andrew Fuller Dr.
117 10985 Hungry Owl All-Night Grocers Ireland 3/30/1998 12:00:00 AM 91.5100 Andrew Fuller Dr.
118 10987 Eastern Connection UK 3/31/1998 12:00:00 AM 185.4800 Laura Callahan Ms.
119 10989 Que Delícia Brazil 3/31/1998 12:00:00 AM 34.7600 Andrew Fuller Dr.
120 10990 Ernst Handel Austria 4/1/1998 12:00:00 AM 117.6100 Andrew Fuller Dr.
121 10994 Vaffeljernet Denmark 4/2/1998 12:00:00 AM 65.5300 Andrew Fuller Dr.
122 10999 Ottilies Käseladen Germany 4/3/1998 12:00:00 AM 96.3500 Michael Suyama Mr.
123 11000 Rattlesnake Canyon Grocery USA 4/6/1998 12:00:00 AM 55.1200 Andrew Fuller Dr.
124 11001 Folk och fä HB Sweden 4/6/1998 12:00:00 AM 197.3000 Andrew Fuller Dr.
125 11005 Wilman Kala Finland 4/7/1998 12:00:00 AM 0.7500 Andrew Fuller Dr.
126 11009 Godos Cocina Típica Spain 4/8/1998 12:00:00 AM 59.1100 Andrew Fuller Dr.
127 11010 Reggiani Caseifici Italy 4/9/1998 12:00:00 AM 28.7100 Andrew Fuller Dr.
128 11012 Frankenversand Germany 4/9/1998 12:00:00 AM 242.9500 Nancy Davolio Ms.
129 11013 Romero y tomillo Spain 4/9/1998 12:00:00 AM 32.9900 Andrew Fuller Dr.
130 11014 LINO-Delicateses Venezuela 4/10/1998 12:00:00 AM 23.6000 Andrew Fuller Dr.
131 11015 Santé Gourmet Norway 4/10/1998 12:00:00 AM 4.6200 Andrew Fuller Dr.
132 11020 Ottilies Käseladen Germany 4/14/1998 12:00:00 AM 43.3000 Andrew Fuller Dr.
133 11021 QUICK-Stop Germany 4/14/1998 12:00:00 AM 297.1800 Janet Leverling Ms.
134 11023 B's Beverages UK 4/14/1998 12:00:00 AM 123.8300 Nancy Davolio Ms.
135 11024 Eastern Connection UK 4/15/1998 12:00:00 AM 74.3600 Margaret Peacock Mrs.
136 11028 Königlich Essen Germany 4/16/1998 12:00:00 AM 29.5900 Andrew Fuller Dr.
137 11032 White Clover Markets USA 4/17/1998 12:00:00 AM 606.1900 Andrew Fuller Dr.
138 11035 Suprêmes délices Belgium 4/20/1998 12:00:00 AM 0.1700 Andrew Fuller Dr.
139 11036 Drachenblut Delikatessen Germany 4/20/1998 12:00:00 AM 149.4700 Laura Callahan Ms.
140 11042 Comércio Mineiro Brazil 4/22/1998 12:00:00 AM 29.9900 Andrew Fuller Dr.
141 11046 Die Wandernde Kuh Germany 4/23/1998 12:00:00 AM 71.6400 Laura Callahan Ms.
142 11053 Piccolo und mehr Austria 4/27/1998 12:00:00 AM 53.0500 Andrew Fuller Dr.
143 11056 Eastern Connection UK 4/28/1998 12:00:00 AM 278.9600 Laura Callahan Ms.
144 11059 Ricardo Adocicados Brazil 4/29/1998 12:00:00 AM 85.8000 Andrew Fuller Dr.
145 11060 Franchi S.p.A. Italy 4/30/1998 12:00:00 AM 10.9800 Andrew Fuller Dr.
146 11070 Lehmanns Marktstand Germany 5/5/1998 12:00:00 AM 136.0000 Andrew Fuller Dr.
147 11073 Pericles Comidas clásicas Mexico 5/5/1998 12:00:00 AM 24.9500 Andrew Fuller Dr.