-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathContractStart.sql
More file actions
61 lines (48 loc) · 1.96 KB
/
ContractStart.sql
File metadata and controls
61 lines (48 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
--Contract Start Date select * from dbaciscoimport
DECLARE @RowCount INT
SET @RowCount = (select count(c.warrantycontractstart) from inv_contracts a
inner join inv_ci b
on a.ci_id = b.request_id
inner join DBACiscoImport c
on c.Serial = b.atr_serial_number
WHERE c.ContractNumber is NOT NULL AND c.warrantyContractStart IS NOT NULL)
declare @contractStart table
(RowId int identity(1,1)
, contractStartDate datetime
, SerialNumber varchar(max)
, contractnumber varchar(max)
, request_id varchar(max))
INSERT INTO @contractStart
select c.warrantycontractStart, c.serial, c.contractnumber, b.request_id from inv_contracts a
inner join inv_ci b
on a.ci_id = b.request_id
inner join DBACiscoImport c
on c.Serial = b.atr_serial_number
WHERE c.ContractNumber is NOT NULL AND c.warrantyContractStart IS NOT NULL
-- Declare an iterator
DECLARE @I INT
-- Initialize the iterator
SET @I = 1
-- Loop through the rows of a table @myTable
WHILE (@I <= @RowCount)
BEGIN
--SELECT C536870914 FROM T595
DECLARE @Date datetime
Set @Date = (Select contractstartdate from @contractstart where rowid = @I)
DECLARE @SerialNumber varchar(max)
SET @SerialNumber = (SELECT serialnumber from @contractstart where rowid = @I)
DECLARE @RequestId varchar(max)
SET @RequestId = (SELECT request_id from @contractstart where rowid = @I)
DECLARE @ContractNumber varchar(max)
SET @ContractNumber = (SELECT ContractNumber from @contractstart where rowid = @I)
--Print CONVERT(VARCHAR, @Date, 120) + ' ' + @SerialNumber + ' ' + @RequestId + ' ' + @ContractNumber
UPDATE a
set C536870913 = (DATEDIFF(s, '1970-01-01 00:00:00', DATEADD(HH, 4, @date)))
FROM t595 a
inner join inv_ci b
on a.C536870950 = b.request_id
inner join DBACiscoImport c
on c.Serial = @SerialNumber
WHERE b.request_Id = @RequestId
SET @I = @I + 1
END