shahf8604 commited on
Commit
8cb5fe4
·
1 Parent(s): c46ef0c

Push clinet original sql file for database schema

Browse files
data/client_database_script.sql ADDED
The diff for this file is too large to render. See raw diff
 
data/database_schema.txt DELETED
@@ -1,498 +0,0 @@
1
- USE [master]
2
- GO
3
-
4
- -- Create database
5
- CREATE DATABASE [FireRMS]
6
- GO
7
-
8
- USE [FireRMS]
9
- GO
10
-
11
- -- =============================================
12
- -- STEP 1: Create custom data types
13
- -- =============================================
14
- CREATE TYPE [dbo].[udtfdid] FROM [char](5) NULL
15
- GO
16
- CREATE TYPE [dbo].[udtlogical] FROM [bit] NULL
17
- GO
18
-
19
- -- =============================================
20
- -- STEP 2: Create lookup tables
21
- -- =============================================
22
- CREATE TABLE [dbo].[codes901](
23
- [code] [char](4) NOT NULL,
24
- [category] [varchar](30) NOT NULL,
25
- [descrip] [varchar](80) NULL,
26
- [sortorder] [int] NULL,
27
- [defaultitem] [bit] NULL DEFAULT ((0)),
28
- [inuse] [bit] NULL DEFAULT ((1)),
29
- CONSTRAINT [PK_codes901] PRIMARY KEY CLUSTERED ([code] ASC, [category] ASC)
30
- ) ON [PRIMARY]
31
- GO
32
-
33
- CREATE TABLE [dbo].[codesems](
34
- [code] [varchar](6) NOT NULL,
35
- [category] [varchar](30) NOT NULL,
36
- [descrip] [varchar](80) NULL,
37
- [sortorder] [int] NULL,
38
- [defaultitem] [bit] NULL DEFAULT ((0)),
39
- [inuse] [bit] NULL DEFAULT ((1)),
40
- CONSTRAINT [PK_codesems] PRIMARY KEY CLUSTERED ([code] ASC, [category] ASC)
41
- ) ON [PRIMARY]
42
- GO
43
-
44
- CREATE TABLE [dbo].[dptcodes](
45
- [code] [varchar](10) NOT NULL,
46
- [category] [varchar](30) NOT NULL,
47
- [descrip] [varchar](80) NULL,
48
- [sortorder] [int] NULL,
49
- [defaultitem] [bit] NULL DEFAULT ((0)),
50
- [inuse] [bit] NULL DEFAULT ((1)),
51
- CONSTRAINT [PK_dptcodes] PRIMARY KEY CLUSTERED ([code] ASC, [category] ASC)
52
- ) ON [PRIMARY]
53
- GO
54
-
55
- CREATE TABLE [dbo].[app_bas](
56
- [appcode] [char](8) NOT NULL,
57
- [apsid] [char](14) NULL,
58
- [apsexternal] [bit] NULL DEFAULT ((0)),
59
- [appdescription] [varchar](50) NULL,
60
- [apptype] [char](4) NULL,
61
- [appstatus] [char](1) NULL,
62
- [station] [char](30) NULL,
63
- [shift] [char](2) NULL,
64
- [inzul] [bit] NULL DEFAULT ((0)),
65
- [inzuldate] [datetime] NULL,
66
- [inzuloutdate] [datetime] NULL,
67
- [rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL DEFAULT (newsequentialid()),
68
- CONSTRAINT [PK_app_bas] PRIMARY KEY CLUSTERED ([appcode] ASC)
69
- ) ON [PRIMARY]
70
- GO
71
-
72
- -- =============================================
73
- -- STEP 3: Create main tables
74
- -- =============================================
75
- CREATE TABLE [dbo].[incident](
76
- [incidentkey] [char](14) NOT NULL,
77
- [incidentdate] [datetime] NULL,
78
- [incidentnumber] [char](10) NULL,
79
- [exposure] [char](3) NULL,
80
- [incidentstatus] [char](20) NULL,
81
- [reviewstatusflag] [bit] NOT NULL DEFAULT ((0)),
82
- [publicreleaseflag] [bit] NOT NULL DEFAULT ((0)),
83
- [completed] [bit] NOT NULL DEFAULT ((0)),
84
- [transactiontype] [char](4) NULL,
85
- [district] [char](10) NULL,
86
- [station] [char](30) NULL DEFAULT (''),
87
- [shift] [char](2) NULL,
88
- [incidenttype] [char](4) NOT NULL DEFAULT (''),
89
- [initialdispatchcode] [varchar](25) NULL,
90
- [mutualaidcode] [char](4) NOT NULL DEFAULT (''),
91
- [alarmdate] [datetime] NULL,
92
- [arrivaldate] [datetime] NULL,
93
- [didnotarriveflag] [bit] NOT NULL DEFAULT ((0)),
94
- [controlleddate] [datetime] NULL,
95
- [lastunitcleareddate] [datetime] NULL,
96
- [includemutualaidflag] [bit] NOT NULL DEFAULT ((0)),
97
- [madepartment] [char](30) NULL,
98
- [madeptincidentno] [char](9) NULL,
99
- [alarms] [int] NULL,
100
- [actiontaken1] [char](4) NULL,
101
- [actiontaken2] [char](4) NULL,
102
- [actiontaken3] [char](4) NULL,
103
- [apparatussuppression] [int] NULL DEFAULT ((0)),
104
- [apparatusems] [int] NULL DEFAULT ((0)),
105
- [apparatusother] [int] NULL DEFAULT ((0)),
106
- [personnelsuppression] [int] NULL DEFAULT ((0)),
107
- [personnelems] [int] NULL DEFAULT ((0)),
108
- [personnelother] [int] NULL DEFAULT ((0)),
109
- [lossproperty] [money] NULL,
110
- [losscontents] [money] NULL,
111
- [valueproperty] [money] NULL,
112
- [valuecontents] [money] NULL,
113
- [fatalfireservice] [int] NULL DEFAULT ((0)),
114
- [fatalother] [int] NULL DEFAULT ((0)),
115
- [nonfatalfireservice] [int] NULL DEFAULT ((0)),
116
- [nonfatalother] [int] NULL DEFAULT ((0)),
117
- [detector] [char](4) NULL,
118
- [hazardmaterialreleased] [char](4) NULL,
119
- [mixeduse] [char](4) NULL,
120
- [propertyuse] [char](4) NULL,
121
- [emsprovidedflag] [bit] NOT NULL DEFAULT ((0)),
122
- [casualtiesflag] [tinyint] NULL,
123
- [priorityresponseflag] [bit] NULL,
124
- [locationtype] [float] NULL DEFAULT ((1)),
125
- [censustract] [char](7) NULL DEFAULT (''),
126
- [numberormile] [char](8) NULL DEFAULT (''),
127
- [streetprefix] [char](2) NULL DEFAULT (''),
128
- [streethighway] [char](30) NULL,
129
- [streettype] [char](4) NULL DEFAULT (''),
130
- [streetsuffix] [char](2) NULL DEFAULT (''),
131
- [apartment] [char](15) NULL DEFAULT (''),
132
- [city] [char](20) NULL DEFAULT (''),
133
- [state] [char](2) NULL DEFAULT (''),
134
- [postalcode] [char](20) NULL DEFAULT (''),
135
- [crossstreetprefix] [char](2) NULL DEFAULT (''),
136
- [crossstreethighway] [char](30) NULL,
137
- [crossstreettype] [char](4) NULL DEFAULT (''),
138
- [crossstreetsuffix] [char](2) NULL DEFAULT (''),
139
- [directions] [varchar](max) NULL,
140
- [latitude] [char](20) NULL DEFAULT (''),
141
- [longitude] [char](20) NULL DEFAULT (''),
142
- [meridian] [char](20) NULL DEFAULT (''),
143
- [northsouth] [char](1) NULL DEFAULT (''),
144
- [eastwest] [char](1) NULL DEFAULT (''),
145
- [subsection] [char](4) NULL,
146
- [section] [int] NULL,
147
- [range] [int] NULL,
148
- [township] [decimal](5, 1) NULL,
149
- [compositeaddress] [char](50) NOT NULL DEFAULT (''),
150
- [MAAPPARATUSSUPPRESSION] [int] NULL,
151
- [MAAPPARATUSEMS] [int] NULL,
152
- [MAAPPARATUSOTHER] [int] NULL,
153
- [MAPERSONNELSUPPRESSION] [int] NULL,
154
- [MAPERSONNELEMS] [int] NULL,
155
- [MAPERSONNELOTHER] [int] NULL,
156
- [useoptionaltabs] [bit] NULL DEFAULT ((0)),
157
- [fdid_no] [char](5) NULL,
158
- [county] [varchar](20) NULL,
159
- [mappage] [char](20) NULL,
160
- [addressvalidated] [tinyint] NULL,
161
- [CADCompleted] [bit] NULL DEFAULT ((0)),
162
- [changedate] [datetime] NULL,
163
- [rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL DEFAULT (newsequentialid()),
164
- [LogComments] [varchar](max) NULL,
165
- [CO_Flag] [bit] NULL,
166
- [created] [datetime] NOT NULL DEFAULT (getdate()),
167
- [finaldispatchcode] [varchar](25) NULL,
168
- [responseTime] [varchar](20) NULL,
169
- [turnTime] [varchar](20) NULL,
170
- CONSTRAINT [PK_incident] PRIMARY KEY CLUSTERED ([incidentkey] ASC)
171
- ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
172
- GO
173
-
174
- CREATE TABLE [dbo].[apparatus](
175
- [apparatuskey] [char](14) NOT NULL,
176
- [incidentkey] [char](14) NOT NULL,
177
- [apsid] [char](14) NULL,
178
- [apparatusid] [char](8) NULL,
179
- [priorityresponseflag] [bit] NULL DEFAULT ((0)),
180
- [arrivaldate] [datetime] NULL,
181
- [scenedate] [datetime] NULL,
182
- [enroutedate] [datetime] NULL,
183
- [FACILITYDATE] [datetime] NULL,
184
- [cleardate] [datetime] NULL,
185
- [dispatchdate] [datetime] NULL,
186
- [cancelledenrouteflag] [bit] NULL DEFAULT ((0)),
187
- [numberpeople] [int] NULL DEFAULT ((0)),
188
- [usecode] [char](4) NULL,
189
- [actiontaken1] [char](4) NULL,
190
- [actiontaken2] [char](4) NULL,
191
- [actiontaken3] [char](4) NULL,
192
- [actiontaken4] [char](4) NULL,
193
- [apparatustype] [char](4) NULL,
194
- [amount1] [money] NULL,
195
- [amount2] [money] NULL,
196
- [fdid_no] [dbo].[udtfdid] NULL,
197
- [paramedicdispatch] [varchar](6) NULL,
198
- [firstarrivingunit] [dbo].[udtlogical] NULL DEFAULT ((0)),
199
- [inservicetime] [datetime] NULL,
200
- [respondfromquarters] [dbo].[udtlogical] NULL DEFAULT ((0)),
201
- [changedate] [datetime] NULL,
202
- [rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL DEFAULT (newsequentialid()),
203
- [Hydrant_IDNumber] [varchar](20) NULL,
204
- [Hydrant_Location] [varchar](116) NULL,
205
- [alarms] [char](10) NULL,
206
- [lLosap_credit] [bit] NULL DEFAULT ((1)),
207
- [emsrun] [bit] NULL,
208
- [emsrunnumber] [varchar](14) NULL,
209
- [lProcessEPCR] [bit] NULL,
210
- [nEPCRRun] [int] NULL,
211
- [stagingDate] [datetime] NULL,
212
- [isepcr] [bit] NULL,
213
- [unit_exc] [char](10) NULL,
214
- [aedType] [varchar](10) NULL,
215
- [OdometerOnScene] [decimal](12, 2) NULL,
216
- [OdometerDestination] [decimal](12, 2) NULL,
217
- [MileageTransport] [decimal](12, 2) NULL,
218
- [AtPatientSideTime] [datetime] NULL,
219
- [created] [datetime] NOT NULL DEFAULT (getdate()),
220
- [AerialDeviceUsed] [tinyint] NULL,
221
- [lNFIRSExported] [bit] NULL DEFAULT ((0)),
222
- [NFIRSExportedDate] [datetime] NULL,
223
- [iNFIRSSequence] [tinyint] NULL,
224
- [NFIRSTransactiontype] [char](1) NULL DEFAULT (''),
225
- [Hydrant_Used] [tinyint] NULL DEFAULT ((0)),
226
- [defaultdispatchcode] [varchar](25) NULL,
227
- [responseTime] [varchar](20) NULL,
228
- [turnTime] [varchar](20) NULL,
229
- CONSTRAINT [PK_apparatus] PRIMARY KEY CLUSTERED ([apparatuskey] ASC),
230
- CONSTRAINT [FK_apparatus_incident] FOREIGN KEY ([incidentkey]) REFERENCES [dbo].[incident]([incidentkey]),
231
- CONSTRAINT [FK_apparatus_appbas] FOREIGN KEY ([apparatusid]) REFERENCES [dbo].[app_bas]([appcode])
232
- ) ON [PRIMARY]
233
- GO
234
-
235
- CREATE TABLE [dbo].[personnel](
236
- [personnelkey] [char](14) NOT NULL,
237
- [incidentkey] [char](14) NOT NULL,
238
- [apparatuskey] [char](14) NULL,
239
- [pslid] [char](14) NULL,
240
- [personnelid] [char](9) NULL,
241
- [lastname] [char](25) NULL,
242
- [firstname] [char](25) NULL,
243
- [middleinitial] [char](1) NULL,
244
- [namesuffix] [char](4) NULL,
245
- [rank] [char](10) NULL,
246
- [actiontaken1] [char](4) NULL,
247
- [actiontaken2] [char](4) NULL,
248
- [actiontaken3] [char](4) NULL,
249
- [actiontaken4] [char](4) NULL,
250
- [amount1] [money] NULL,
251
- [amount2] [money] NULL,
252
- [changedate] [datetime] NULL,
253
- [rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL DEFAULT (newsequentialid()),
254
- [crole] [char](4) NULL,
255
- [lLosap_credit] [bit] NULL DEFAULT ((1)),
256
- [cAdditionalRole] [varchar](8) NULL,
257
- [AgencyID] [varchar](14) NULL,
258
- [AgencyDesc] [varchar](40) NULL,
259
- [AgencyCode] [varchar](8) NULL,
260
- [lNFIRSExported] [bit] NULL DEFAULT ((0)),
261
- [NFIRSExportedDate] [datetime] NULL,
262
- [iNFIRSSequence] [tinyint] NULL,
263
- [NFIRSTransactiontype] [char](1) NULL DEFAULT (''),
264
- CONSTRAINT [PK_personnel] PRIMARY KEY CLUSTERED ([personnelkey] ASC),
265
- CONSTRAINT [FK_personnel_incident] FOREIGN KEY ([incidentkey]) REFERENCES [dbo].[incident]([incidentkey]),
266
- CONSTRAINT [FK_personnel_apparatus] FOREIGN KEY ([apparatuskey]) REFERENCES [dbo].[apparatus]([apparatuskey])
267
- ) ON [PRIMARY]
268
- GO
269
-
270
- -- =============================================
271
- -- STEP 4: Create supplemental tables
272
- -- =============================================
273
- CREATE TABLE [dbo].[incidentsupplemental](
274
- [incidentkey] [char](14) NOT NULL,
275
- [call_out_requested_by] [varchar](50) NULL,
276
- [investigating_police] [varchar](10) NULL,
277
- [officer] [varchar](50) NULL,
278
- [badge_number] [varchar](20) NULL,
279
- [police_report_number] [varchar](20) NULL,
280
- [cause_of_emergency] [varchar](10) NULL,
281
- [coe_other] [varchar](100) NULL,
282
- [location_of_emergency] [varchar](10) NULL,
283
- [loe_other] [varchar](100) NULL,
284
- [obstruction] [varchar](10) NULL,
285
- [obstruction_other] [varchar](100) NULL,
286
- [no_services_performed] [bit] NULL DEFAULT ((0)),
287
- [extinguish_performed] [bit] NULL DEFAULT ((0)),
288
- [cleanup_performed] [bit] NULL DEFAULT ((0)),
289
- [extraction_performed] [bit] NULL DEFAULT ((0)),
290
- [first_aid_performed] [bit] NULL DEFAULT ((0)),
291
- [highway_damage] [bit] NULL DEFAULT ((0)),
292
- [private_damage] [bit] NULL DEFAULT ((0)),
293
- [city_damage] [bit] NULL DEFAULT ((0)),
294
- [other_damage] [bit] NULL DEFAULT ((0)),
295
- [other_damage_other] [varchar](100) NULL,
296
- [water_used] [bit] NULL DEFAULT ((0)),
297
- [water_used_quantity] [decimal](10,2) NULL,
298
- [foam_used] [bit] NULL DEFAULT ((0)),
299
- [foam_used_quantity] [decimal](10,2) NULL,
300
- [oilzorb_used] [bit] NULL DEFAULT ((0)),
301
- [oilzorb_used_quantity] [decimal](10,2) NULL,
302
- [other_used] [bit] NULL DEFAULT ((0)),
303
- [other_used_quantity] [decimal](10,2) NULL,
304
- [rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL DEFAULT (newsequentialid()),
305
- CONSTRAINT [PK_incidentsupplemental] PRIMARY KEY CLUSTERED ([incidentkey] ASC),
306
- CONSTRAINT [FK_incidentsupplemental_incident] FOREIGN KEY ([incidentkey]) REFERENCES [dbo].[incident]([incidentkey])
307
- ) ON [PRIMARY]
308
- GO
309
-
310
- CREATE TABLE [dbo].[carbonmonoxide](
311
- [incidentkey] [char](14) NOT NULL,
312
- [det_present] [bit] NULL DEFAULT ((0)),
313
- [det_type] [char](4) NULL,
314
- [det_pwrsply] [char](4) NULL,
315
- [det_operation] [char](4) NULL,
316
- [det_effective] [char](4) NULL,
317
- [det_failure] [char](4) NULL,
318
- [det_mfg] [varchar](50) NULL,
319
- [det_model] [varchar](50) NULL,
320
- [co_children] [int] NULL DEFAULT ((0)),
321
- [co_youths] [int] NULL DEFAULT ((0)),
322
- [co_adults] [int] NULL DEFAULT ((0)),
323
- [co_seniors] [int] NULL DEFAULT ((0)),
324
- [rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL DEFAULT (newsequentialid()),
325
- CONSTRAINT [PK_carbonmonoxide] PRIMARY KEY CLUSTERED ([incidentkey] ASC),
326
- CONSTRAINT [FK_carbonmonoxide_incident] FOREIGN KEY ([incidentkey]) REFERENCES [dbo].[incident]([incidentkey])
327
- ) ON [PRIMARY]
328
- GO
329
-
330
- CREATE TABLE [dbo].[authority](
331
- [incidentkey] [char](14) NOT NULL,
332
- [sequence] [char](1) NOT NULL,
333
- [personnelid] [char](9) NULL,
334
- [lastname] [char](25) NULL,
335
- [firstname] [char](25) NULL,
336
- [middleinitial] [char](1) NULL,
337
- [rank] [char](10) NULL,
338
- [assignment] [char](10) NULL,
339
- [authoritydate] [datetime] NULL,
340
- [rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL DEFAULT (newsequentialid()),
341
- CONSTRAINT [PK_authority] PRIMARY KEY CLUSTERED ([incidentkey] ASC, [sequence] ASC),
342
- CONSTRAINT [FK_authority_incident] FOREIGN KEY ([incidentkey]) REFERENCES [dbo].[incident]([incidentkey])
343
- ) ON [PRIMARY]
344
- GO
345
-
346
- -- =============================================
347
- -- STEP 5: Create indexes for performance
348
- -- =============================================
349
- CREATE INDEX [IX_incident_incidentnumber] ON [dbo].[incident]([incidentnumber])
350
- GO
351
- CREATE INDEX [IX_incident_incidentdate] ON [dbo].[incident]([incidentdate])
352
- GO
353
- CREATE INDEX [IX_incident_station] ON [dbo].[incident]([station])
354
- GO
355
- CREATE INDEX [IX_apparatus_incidentkey] ON [dbo].[apparatus]([incidentkey])
356
- GO
357
- CREATE INDEX [IX_apparatus_apparatusid] ON [dbo].[apparatus]([apparatusid])
358
- GO
359
- CREATE INDEX [IX_personnel_incidentkey] ON [dbo].[personnel]([incidentkey])
360
- GO
361
- CREATE INDEX [IX_personnel_apparatuskey] ON [dbo].[personnel]([apparatuskey])
362
- GO
363
-
364
- -- =============================================
365
- -- STEP 6: Create views
366
- -- =============================================
367
- CREATE VIEW [dbo].[vw_incident_summary] AS
368
- SELECT
369
- i.incidentkey,
370
- i.incidentnumber,
371
- i.exposure,
372
- i.incidentdate,
373
- i.incidenttype,
374
- ic.descrip AS incidenttype_descrip,
375
- i.incidentstatus,
376
- i.station,
377
- i.shift,
378
- i.alarmdate,
379
- i.arrivaldate,
380
- i.lastunitcleareddate,
381
- i.compositeaddress,
382
- i.city,
383
- i.state,
384
- i.emsprovidedflag,
385
- i.lossproperty + i.losscontents AS total_loss,
386
- (i.valueproperty + i.valuecontents) - (i.lossproperty + i.losscontents) AS value_saved,
387
- (SELECT COUNT(*) FROM apparatus a WHERE a.incidentkey = i.incidentkey) AS apparatus_count,
388
- (SELECT COUNT(*) FROM personnel p WHERE p.incidentkey = i.incidentkey) AS personnel_count
389
- FROM incident i
390
- LEFT JOIN codes901 ic ON ic.code = i.incidenttype AND ic.category = 'incident'
391
- GO
392
-
393
- CREATE VIEW [dbo].[vw_apparatus_details] AS
394
- SELECT
395
- a.apparatuskey,
396
- a.incidentkey,
397
- i.incidentnumber,
398
- a.apparatusid,
399
- ab.appdescription AS apparatus_description,
400
- a.apparatustype,
401
- at.descrip AS apparatustype_descrip,
402
- a.dispatchdate,
403
- a.arrivaldate,
404
- a.cleardate,
405
- a.usecode,
406
- CASE a.usecode
407
- WHEN '1' THEN 'Suppression'
408
- WHEN '2' THEN 'EMS'
409
- WHEN '3' THEN 'Other'
410
- ELSE 'Unknown'
411
- END AS usecode_descrip,
412
- a.numberpeople,
413
- a.firstarrivingunit,
414
- a.emsrun,
415
- a.emsrunnumber,
416
- a.responseTime,
417
- a.turnTime
418
- FROM apparatus a
419
- LEFT JOIN incident i ON i.incidentkey = a.incidentkey
420
- LEFT JOIN app_bas ab ON ab.appcode = a.apparatusid
421
- LEFT JOIN codes901 at ON at.code = a.apparatustype AND at.category = 'app_type'
422
- GO
423
-
424
- CREATE VIEW [dbo].[vw_personnel_details] AS
425
- SELECT
426
- p.personnelkey,
427
- p.incidentkey,
428
- i.incidentnumber,
429
- p.apparatuskey,
430
- a.apparatusid,
431
- p.personnelid,
432
- p.lastname + ', ' + p.firstname + ISNULL(' ' + p.middleinitial, '') + ISNULL(' ' + p.namesuffix, '') AS fullname,
433
- p.rank,
434
- r.descrip AS rank_descrip,
435
- p.crole,
436
- cr.descrip AS role_descrip,
437
- p.actiontaken1,
438
- at1.descrip AS actiontaken1_descrip,
439
- p.lLosap_credit
440
- FROM personnel p
441
- LEFT JOIN incident i ON i.incidentkey = p.incidentkey
442
- LEFT JOIN apparatus a ON a.apparatuskey = p.apparatuskey
443
- LEFT JOIN dptcodes r ON r.code = p.rank AND r.category = 'position'
444
- LEFT JOIN codes901 cr ON cr.code = p.crole AND cr.category = 'assign'
445
- LEFT JOIN codes901 at1 ON at1.code = p.actiontaken1 AND at1.category = 'action'
446
- GO
447
-
448
- -- =============================================
449
- -- STEP 7: Stored procedures
450
- -- =============================================
451
- CREATE PROCEDURE [dbo].[sp_GetIncidentByNumber]
452
- @IncidentNumber char(10)
453
- AS
454
- BEGIN
455
- SELECT * FROM incident WHERE incidentnumber = @IncidentNumber
456
- SELECT * FROM apparatus WHERE incidentkey IN (SELECT incidentkey FROM incident WHERE incidentnumber = @IncidentNumber)
457
- SELECT * FROM personnel WHERE incidentkey IN (SELECT incidentkey FROM incident WHERE incidentnumber = @IncidentNumber)
458
- END
459
- GO
460
-
461
- CREATE PROCEDURE [dbo].[sp_GetIncidentsByDateRange]
462
- @StartDate datetime,
463
- @EndDate datetime
464
- AS
465
- BEGIN
466
- SELECT * FROM incident
467
- WHERE incidentdate BETWEEN @StartDate AND @EndDate
468
- ORDER BY incidentdate DESC
469
- END
470
- GO
471
-
472
- CREATE PROCEDURE [dbo].[sp_GetApparatusResponseTimes]
473
- @IncidentKey char(14) = NULL,
474
- @StartDate datetime = NULL,
475
- @EndDate datetime = NULL
476
- AS
477
- BEGIN
478
- SELECT
479
- a.apparatusid,
480
- i.incidentnumber,
481
- a.dispatchdate,
482
- a.arrivaldate,
483
- a.cleardate,
484
- a.responseTime,
485
- a.turnTime,
486
- CASE
487
- WHEN a.dispatchdate IS NOT NULL AND a.arrivaldate IS NOT NULL
488
- THEN DATEDIFF(minute, a.dispatchdate, a.arrivaldate)
489
- ELSE NULL
490
- END AS response_minutes
491
- FROM apparatus a
492
- JOIN incident i ON i.incidentkey = a.incidentkey
493
- WHERE (@IncidentKey IS NULL OR a.incidentkey = @IncidentKey)
494
- AND (@StartDate IS NULL OR i.incidentdate >= @StartDate)
495
- AND (@EndDate IS NULL OR i.incidentdate <= @EndDate)
496
- ORDER BY i.incidentdate DESC
497
- END
498
- GO