You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### A. Using the addition operator to calculate the total number of hours away from work for each employee.
55
55
This example finds the total number of hours away from work for each employee by adding the number of hours taken for vacation and the number of hours taken as sick leave.
### B. Using the addition operator to add days to date and time values
69
69
This example adds a number of days to a `datetime` date.
70
70
71
-
```
72
-
71
+
```sql
73
72
SET NOCOUNT ON
74
-
DECLARE @startdate datetime, @adddays int;
73
+
DECLARE @startdate DATETIME, @adddays INT;
75
74
SET @startdate ='January 10, 1900 12:00 AM';
76
75
SET @adddays =5;
77
76
SET NOCOUNT OFF;
@@ -92,8 +91,8 @@ Start Date Add Date
92
91
### C. Adding character and integer data types
93
92
The following example adds an **int** data type value and a character value by converting the character data type to **int**. If a character that is not valid exists in the **char** string, the [!INCLUDE[tsql](../../includes/tsql-md.md)] returns an error.
94
93
95
-
```
96
-
DECLARE @addvalue int;
94
+
```sql
95
+
DECLARE @addvalue INT;
97
96
SET @addvalue =15;
98
97
SELECT'125127'+ @addvalue;
99
98
```
@@ -112,7 +111,7 @@ SELECT '125127' + @addvalue;
112
111
### D: Using the addition operator to calculate the total number of hours away from work for each employee
113
112
The following example finds the total number of hours away from work for each employee by adding the number of hours taken for vacation and the number of hours taken as sick leave and sorts the results in ascending order.
The following example creates a stored procedure that determines whether all the components of a specified `SalesOrderID` in the [!INCLUDE[ssSampleDBnormal](../../includes/sssampledbnormal-md.md)] database can be manufactured in the specified number of days. The example uses a subquery to create a list of the number of `DaysToManufacture` values for all of the components of the specific `SalesOrderID`, and then confirms that all the `DaysToManufacture` are within the number of days specified.
66
65
67
-
```
66
+
```sql
68
67
-- Uses AdventureWorks
69
68
70
-
CREATE PROCEDURE DaysToBuild @OrderID int, @NumberOfDays int
69
+
CREATE PROCEDURE DaysToBuild @OrderID INT, @NumberOfDays INT
71
70
AS
72
71
IF
73
72
@NumberOfDays >= ALL
@@ -81,20 +80,19 @@ IF
81
80
PRINT 'All items for this order can be manufactured in specified number of days or less.'
82
81
ELSE
83
82
PRINT 'Some items for this order can''t be manufactured in specified number of days or less.' ;
84
-
85
83
```
86
84
87
85
To test the procedure, execute the procedure by using the `SalesOrderID 49080`, which has one component requiring `2` days and two components that require 0 days. The first statement below meets the criteria. The second query doesn't.
Copy file name to clipboardExpand all lines: docs/t-sql/language-elements/and-transact-sql.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,7 +63,7 @@ boolean_expression AND boolean_expression
63
63
### A. Using the AND operator
64
64
The following example selects information about employees who have both the title of `Marketing Assistant` and more than `41` vacation hours available.
The following examples show how to use AND in an IF statement. In the first statement, both `1 = 1` and `2 = 2` are true; therefore, the result is true. In the second example, the argument `2 = 17` is false; therefore, the result is false.
The equal sign (=) is the only [!INCLUDE[tsql](../../includes/tsql-md.md)] assignment operator. In the following example, the `@MyCounter` variable is created, and then the assignment operator sets `@MyCounter` to a value returned by an expression.
29
29
30
-
```
30
+
```sql
31
31
DECLARE @MyCounter INT;
32
32
SET @MyCounter =1;
33
33
```
34
34
35
35
The assignment operator can also be used to establish the relationship between a column heading and the expression that defines the values for the column. The following example displays the column headings `FirstColumnHeading` and `SecondColumnHeading`. The string `xyz` is displayed in the `FirstColumnHeading` column heading for all rows. Then, each product ID from the `Product` table is listed in the `SecondColumnHeading` column heading.
> Unless MS DTC is currently installed on the computer running the instance of the [!INCLUDE[ssDE](../../includes/ssde-md.md)], this example produces an error message. For more information about installing MS DTC, see the Microsoft Distributed Transaction Coordinator documentation.
Copy file name to clipboardExpand all lines: docs/t-sql/language-elements/begin-transaction-transact-sql.md
+6-7Lines changed: 6 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -111,7 +111,7 @@ BEGIN TRANSACTION starts a local transaction for the connection issuing the stat
111
111
112
112
BEGIN TRAN *new_name* WITH MARK can be nested within an already existing transaction that is not marked. Upon doing so, *new_name* becomes the mark name for the transaction, despite the name that the transaction may already have been given. In the following example, `M2` is the name of the mark.
113
113
114
-
```
114
+
```sql
115
115
BEGIN TRAN T1;
116
116
UPDATE table1 ...;
117
117
BEGIN TRAN M2 WITH MARK;
@@ -146,7 +146,7 @@ COMMIT TRAN T1;
146
146
147
147
This example uses AdventureWorks.
148
148
149
-
```
149
+
```sql
150
150
BEGIN TRANSACTION;
151
151
DELETEFROMHumanResources.JobCandidate
152
152
WHERE JobCandidateID =13;
@@ -158,9 +158,8 @@ COMMIT;
158
158
159
159
The following example shows the effect of rolling back a transaction. In this example, the ROLLBACK statement will roll back the INSERT statement, but the created table will still exist.
160
160
161
-
```
162
-
163
-
CREATE TABLE ValueTable (id int);
161
+
```sql
162
+
CREATETABLEValueTable (id INT);
164
163
BEGIN TRANSACTION;
165
164
INSERT INTO ValueTable VALUES(1);
166
165
INSERT INTO ValueTable VALUES(2);
@@ -173,7 +172,7 @@ ROLLBACK;
173
172
174
173
The following example shows how to name a transaction.
175
174
176
-
```
175
+
```sql
177
176
DECLARE @TranName VARCHAR(20);
178
177
SELECT @TranName ='MyTransaction';
179
178
@@ -191,7 +190,7 @@ GO
191
190
192
191
The following example shows how to mark a transaction. The transaction `CandidateDelete` is marked.
0 commit comments