Billings on or before a specified date : datetime « Data Types « SQL Server / T-SQL Tutorial






4>
5>
6> create table Billings (
7>     BankerID           INTEGER,
8>     BillingNumber      INTEGER,
9>     BillingDate        datetime,
10>     BillingTotal       INTEGER,
11>     TermsID            INTEGER,
12>     BillingDueDate     datetime ,
13>     PaymentTotal       INTEGER,
14>     CreditTotal        INTEGER
15>
16> );
17> GO
1>
2> INSERT INTO Billings VALUES (1, 1, '2005-01-22', 165, 1,'2005-04-22',123,321);
3> GO

(1 rows affected)
1> INSERT INTO Billings VALUES (2, 2, '2001-02-21', 165, 1,'2002-02-22',123,321);
2> GO

(1 rows affected)
1> INSERT INTO Billings VALUES (3, 3, '2003-05-02', 165, 1,'2005-04-12',123,321);
2> GO

(1 rows affected)
1> INSERT INTO Billings VALUES (4, 4, '1999-03-12', 165, 1,'2005-04-18',123,321);
2> GO

(1 rows affected)
1> INSERT INTO Billings VALUES (5, 5, '2000-04-23', 165, 1,'2005-04-17',123,321);
2> GO

(1 rows affected)
1> INSERT INTO Billings VALUES (6, 6, '2001-06-14', 165, 1,'2005-04-18',123,321);
2> GO

(1 rows affected)
1> INSERT INTO Billings VALUES (7, 7, '2002-07-15', 165, 1,'2005-04-19',123,321);
2> GO

(1 rows affected)
1> INSERT INTO Billings VALUES (8, 8, '2003-08-16', 165, 1,'2005-04-20',123,321);
2> GO

(1 rows affected)
1> INSERT INTO Billings VALUES (9, 9, '2004-09-17', 165, 1,'2005-04-21',123,321);
2> GO

(1 rows affected)
1> INSERT INTO Billings VALUES (0, 0, '2005-10-18', 165, 1,'2005-04-22',123,321);
2> GO

(1 rows affected)
1>
2>
3> select * from Billings WHERE BillingDate <= '2002-05-31'
4> GO
BankerID    BillingNumber BillingDate             BillingTotal TermsID     BillingDueDate          PaymentTotal CreditTotal
----------- ------------- ----------------------- ------------ ----------- ----------------------- ------------ -----------
          2             2 2001-02-21 00:00:00.000          165           1 2002-02-22 00:00:00.000          123         321
          4             4 1999-03-12 00:00:00.000          165           1 2005-04-18 00:00:00.000          123         321
          5             5 2000-04-23 00:00:00.000          165           1 2005-04-17 00:00:00.000          123         321
          6             6 2001-06-14 00:00:00.000          165           1 2005-04-18 00:00:00.000          123         321

(4 rows affected)
1> drop table Billings;
2> GO








5.9.datetime
5.9.1.datetime type
5.9.2.Store the date and time for a change in a datetime format.
5.9.3.Billings on or before a specified date
5.9.4.A BETWEEN phrase with literal values
5.9.5.Using comperison operator with Date value
5.9.6.Between date
5.9.7.SET start_Date = GETDATE()
5.9.8.Use 'LIKE pattern' match with a date type value
5.9.9.An UPDATE statement that assigns new values to datetime column with string value
5.9.10.CAST(OrderDate AS varchar)
5.9.11.Specify date with string (OrderDate = '7/4/1996')
5.9.12.Performing Date Conversions
5.9.13.SELECT CONVERT(datetime, CONVERT( varchar(11), '2005-08-13 20:37:22.570', 101))
5.9.14.Add integer and float number to a date value
5.9.15.A SELECT statement that ignores date values
5.9.16.A SELECT statement that uses the CONVERT function to remove time values
5.9.17.A SELECT statement that uses the CAST function to remove time values
5.9.18.A SELECT statement that searches for month, day, and year components