· 5 years ago · Oct 17, 2020, 01:18 AM
1USE [master]
2GO
3/****** Object: Database [ChamplainCharityLLC] Script Date: 10/16/2020 7:31:03 PM ******/
4CREATE DATABASE [ChamplainCharityLLC]
5 CONTAINMENT = NONE
6 ON PRIMARY
7( NAME = N'ChamplainCharityLLC', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\ChamplainCharityLLC.mdf' , SIZE = 5312KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
8 LOG ON
9( NAME = N'ChamplainCharityLLC_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\ChamplainCharityLLC_log.ldf' , SIZE = 6400KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
10GO
11ALTER DATABASE [ChamplainCharityLLC] SET COMPATIBILITY_LEVEL = 100
12GO
13IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
14begin
15EXEC [ChamplainCharityLLC].[dbo].[sp_fulltext_database] @action = 'enable'
16end
17GO
18ALTER DATABASE [ChamplainCharityLLC] SET ANSI_NULL_DEFAULT OFF
19GO
20ALTER DATABASE [ChamplainCharityLLC] SET ANSI_NULLS OFF
21GO
22ALTER DATABASE [ChamplainCharityLLC] SET ANSI_PADDING OFF
23GO
24ALTER DATABASE [ChamplainCharityLLC] SET ANSI_WARNINGS OFF
25GO
26ALTER DATABASE [ChamplainCharityLLC] SET ARITHABORT OFF
27GO
28ALTER DATABASE [ChamplainCharityLLC] SET AUTO_CLOSE OFF
29GO
30ALTER DATABASE [ChamplainCharityLLC] SET AUTO_SHRINK OFF
31GO
32ALTER DATABASE [ChamplainCharityLLC] SET AUTO_UPDATE_STATISTICS ON
33GO
34ALTER DATABASE [ChamplainCharityLLC] SET CURSOR_CLOSE_ON_COMMIT OFF
35GO
36ALTER DATABASE [ChamplainCharityLLC] SET CURSOR_DEFAULT GLOBAL
37GO
38ALTER DATABASE [ChamplainCharityLLC] SET CONCAT_NULL_YIELDS_NULL OFF
39GO
40ALTER DATABASE [ChamplainCharityLLC] SET NUMERIC_ROUNDABORT OFF
41GO
42ALTER DATABASE [ChamplainCharityLLC] SET QUOTED_IDENTIFIER OFF
43GO
44ALTER DATABASE [ChamplainCharityLLC] SET RECURSIVE_TRIGGERS OFF
45GO
46ALTER DATABASE [ChamplainCharityLLC] SET DISABLE_BROKER
47GO
48ALTER DATABASE [ChamplainCharityLLC] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
49GO
50ALTER DATABASE [ChamplainCharityLLC] SET DATE_CORRELATION_OPTIMIZATION OFF
51GO
52ALTER DATABASE [ChamplainCharityLLC] SET TRUSTWORTHY OFF
53GO
54ALTER DATABASE [ChamplainCharityLLC] SET ALLOW_SNAPSHOT_ISOLATION OFF
55GO
56ALTER DATABASE [ChamplainCharityLLC] SET PARAMETERIZATION SIMPLE
57GO
58ALTER DATABASE [ChamplainCharityLLC] SET READ_COMMITTED_SNAPSHOT OFF
59GO
60ALTER DATABASE [ChamplainCharityLLC] SET HONOR_BROKER_PRIORITY OFF
61GO
62ALTER DATABASE [ChamplainCharityLLC] SET RECOVERY FULL
63GO
64ALTER DATABASE [ChamplainCharityLLC] SET MULTI_USER
65GO
66ALTER DATABASE [ChamplainCharityLLC] SET PAGE_VERIFY CHECKSUM
67GO
68ALTER DATABASE [ChamplainCharityLLC] SET DB_CHAINING OFF
69GO
70ALTER DATABASE [ChamplainCharityLLC] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
71GO
72ALTER DATABASE [ChamplainCharityLLC] SET TARGET_RECOVERY_TIME = 0 SECONDS
73GO
74ALTER DATABASE [ChamplainCharityLLC] SET DELAYED_DURABILITY = DISABLED
75GO
76USE [ChamplainCharityLLC]
77GO
78/****** Object: User [NT AUTHORITY\NETWORK SERVICE] Script Date: 10/16/2020 7:31:03 PM ******/
79CREATE USER [NT AUTHORITY\NETWORK SERVICE] FOR LOGIN [NT AUTHORITY\NETWORK SERVICE] WITH DEFAULT_SCHEMA=[dbo]
80GO
81/****** Object: Schema [Foodshelf] Script Date: 10/16/2020 7:31:03 PM ******/
82CREATE SCHEMA [Foodshelf]
83GO
84/****** Object: Schema [Inventory] Script Date: 10/16/2020 7:31:03 PM ******/
85CREATE SCHEMA [Inventory]
86GO
87/****** Object: Schema [Maintenance] Script Date: 10/16/2020 7:31:03 PM ******/
88CREATE SCHEMA [Maintenance]
89GO
90/****** Object: Schema [Message] Script Date: 10/16/2020 7:31:03 PM ******/
91CREATE SCHEMA [Message]
92GO
93/****** Object: Schema [Person] Script Date: 10/16/2020 7:31:03 PM ******/
94CREATE SCHEMA [Person]
95GO
96/****** Object: Schema [Signature] Script Date: 10/16/2020 7:31:03 PM ******/
97CREATE SCHEMA [Signature]
98GO
99/****** Object: Schema [SSN] Script Date: 10/16/2020 7:31:03 PM ******/
100CREATE SCHEMA [SSN]
101GO
102/****** Object: Schema [Volunteer] Script Date: 10/16/2020 7:31:03 PM ******/
103CREATE SCHEMA [Volunteer]
104GO
105/****** Object: Rule [NoYesMaybe] Script Date: 10/16/2020 7:31:03 PM ******/
106CREATE RULE [dbo].[NoYesMaybe]
107AS
108@choice IN (0, 1, 2);
109
110GO
111/****** Object: Rule [YesNo] Script Date: 10/16/2020 7:31:03 PM ******/
112CREATE RULE [dbo].[YesNo]
113AS
114@list in (0,1)
115
116GO
117/****** Object: Rule [YesNoMaybe] Script Date: 10/16/2020 7:31:03 PM ******/
118CREATE RULE [dbo].[YesNoMaybe]
119AS
120@list in (0,1,2)
121
122GO
123/****** Object: Rule [GroceriesOrBreadProduce] Script Date: 10/16/2020 7:31:03 PM ******/
124CREATE RULE [Foodshelf].[GroceriesOrBreadProduce]
125AS
126@list in (0,1)
127
128GO
129/****** Object: XmlSchemaCollection [Person].[AdditionalContactInfoSchemaCollection] Script Date: 10/16/2020 7:31:03 PM ******/
130CREATE XML SCHEMA COLLECTION [Person].[AdditionalContactInfoSchemaCollection] AS N'<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:t="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo" targetNamespace="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo"><xsd:element name="AdditionalContactInfo"><xsd:complexType mixed="true"><xsd:complexContent mixed="true"><xsd:restriction base="xsd:anyType"><xsd:sequence><xsd:any namespace="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactRecord http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes" minOccurs="0" maxOccurs="unbounded" /></xsd:sequence></xsd:restriction></xsd:complexContent></xsd:complexType></xsd:element></xsd:schema><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:t="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactRecord" targetNamespace="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactRecord"><xsd:element name="ContactRecord"><xsd:complexType mixed="true"><xsd:complexContent mixed="true"><xsd:restriction base="xsd:anyType"><xsd:choice minOccurs="0" maxOccurs="unbounded"><xsd:any namespace="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes" /></xsd:choice><xsd:attribute name="date" type="xsd:date" /></xsd:restriction></xsd:complexContent></xsd:complexType></xsd:element></xsd:schema><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:t="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes" targetNamespace="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes" elementFormDefault="qualified"><xsd:element name="eMail" type="t:eMailType" /><xsd:element name="facsimileTelephoneNumber" type="t:phoneNumberType" /><xsd:element name="homePostalAddress" type="t:addressType" /><xsd:element name="internationaliSDNNumber" type="t:phoneNumberType" /><xsd:element name="mobile" type="t:phoneNumberType" /><xsd:element name="pager" type="t:phoneNumberType" /><xsd:element name="physicalDeliveryOfficeName" type="t:addressType" /><xsd:element name="registeredAddress" type="t:addressType" /><xsd:element name="telephoneNumber" type="t:phoneNumberType" /><xsd:element name="telexNumber" type="t:phoneNumberType" /><xsd:complexType name="addressType"><xsd:complexContent><xsd:restriction base="xsd:anyType"><xsd:sequence><xsd:element name="Street" type="xsd:string" maxOccurs="2" /><xsd:element name="City" type="xsd:string" /><xsd:element name="StateProvince" type="xsd:string" /><xsd:element name="PostalCode" type="xsd:string" minOccurs="0" /><xsd:element name="CountryRegion" type="xsd:string" /><xsd:element name="SpecialInstructions" type="t:specialInstructionsType" minOccurs="0" /></xsd:sequence></xsd:restriction></xsd:complexContent></xsd:complexType><xsd:complexType name="eMailType"><xsd:complexContent><xsd:restriction base="xsd:anyType"><xsd:sequence><xsd:element name="eMailAddress" type="xsd:string" /><xsd:element name="SpecialInstructions" type="t:specialInstructionsType" minOccurs="0" /></xsd:sequence></xsd:restriction></xsd:complexContent></xsd:complexType><xsd:complexType name="phoneNumberType"><xsd:complexContent><xsd:restriction base="xsd:anyType"><xsd:sequence><xsd:element name="number"><xsd:simpleType><xsd:restriction base="xsd:string"><xsd:pattern value="[0-9\(\)\-]*" /></xsd:restriction></xsd:simpleType></xsd:element><xsd:element name="SpecialInstructions" type="t:specialInstructionsType" minOccurs="0" /></xsd:sequence></xsd:restriction></xsd:complexContent></xsd:complexType><xsd:complexType name="specialInstructionsType" mixed="true"><xsd:complexContent mixed="true"><xsd:restriction base="xsd:anyType"><xsd:sequence><xsd:any namespace="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes" minOccurs="0" maxOccurs="unbounded" /></xsd:sequence></xsd:restriction></xsd:complexContent></xsd:complexType></xsd:schema>'
131GO
132/****** Object: UserDefinedDataType [dbo].[Flag] Script Date: 10/16/2020 7:31:03 PM ******/
133CREATE TYPE [dbo].[Flag] FROM [bit] NOT NULL
134GO
135/****** Object: UserDefinedDataType [dbo].[Name] Script Date: 10/16/2020 7:31:03 PM ******/
136CREATE TYPE [dbo].[Name] FROM [nvarchar](50) NULL
137GO
138/****** Object: UserDefinedDataType [dbo].[NameStyle] Script Date: 10/16/2020 7:31:03 PM ******/
139CREATE TYPE [dbo].[NameStyle] FROM [bit] NOT NULL
140GO
141/****** Object: UserDefinedDataType [dbo].[Notes] Script Date: 10/16/2020 7:31:03 PM ******/
142CREATE TYPE [dbo].[Notes] FROM [nvarchar](max) NULL
143GO
144/****** Object: UserDefinedDataType [dbo].[NoYes] Script Date: 10/16/2020 7:31:03 PM ******/
145CREATE TYPE [dbo].[NoYes] FROM [int] NOT NULL
146GO
147/****** Object: UserDefinedDataType [dbo].[NoYesMaybe] Script Date: 10/16/2020 7:31:03 PM ******/
148CREATE TYPE [dbo].[NoYesMaybe] FROM [int] NOT NULL
149GO
150/****** Object: UserDefinedDataType [dbo].[Phone] Script Date: 10/16/2020 7:31:03 PM ******/
151CREATE TYPE [dbo].[Phone] FROM [nvarchar](25) NULL
152GO
153/****** Object: UserDefinedDataType [dbo].[x] Script Date: 10/16/2020 7:31:03 PM ******/
154CREATE TYPE [dbo].[x] FROM [int] NOT NULL
155GO
156/****** Object: UserDefinedDataType [Foodshelf].[GroceryOrBreadProduce] Script Date: 10/16/2020 7:31:03 PM ******/
157CREATE TYPE [Foodshelf].[GroceryOrBreadProduce] FROM [int] NOT NULL
158GO
159/****** Object: UserDefinedDataType [Person].[SSN] Script Date: 10/16/2020 7:31:03 PM ******/
160CREATE TYPE [Person].[SSN] FROM [nvarchar](9) NOT NULL
161GO
162/****** Object: UserDefinedTableType [dbo].[BatchProcessPersonID] Script Date: 10/16/2020 7:31:03 PM ******/
163CREATE TYPE [dbo].[BatchProcessPersonID] AS TABLE(
164 [RowID] [int] NOT NULL,
165 [PersonID] [int] NULL,
166 [ActionToTake] [nvarchar](50) NULL
167)
168GO
169/****** Object: UserDefinedTableType [dbo].[LUTableChanges] Script Date: 10/16/2020 7:31:03 PM ******/
170CREATE TYPE [dbo].[LUTableChanges] AS TABLE(
171 [TableRows] [int] IDENTITY(1,1) NOT NULL,
172 [TableName] [nvarchar](50) NULL,
173 [ActionTaken] [nvarchar](50) NULL,
174 [Oldvalue] [nvarchar](max) NULL,
175 [OldLUTableID] [int] NULL,
176 [NewValue] [nvarchar](max) NULL
177)
178GO
179/****** Object: UserDefinedTableType [dbo].[LUTableChangesa] Script Date: 10/16/2020 7:31:03 PM ******/
180CREATE TYPE [dbo].[LUTableChangesa] AS TABLE(
181 [TableRows] [int] IDENTITY(1,1) NOT NULL,
182 [TableName] [nvarchar](50) NULL,
183 [ActionTaken] [nvarchar](50) NULL,
184 [Oldvalue] [nvarchar](max) NULL,
185 [OldLUTableID] [int] NULL,
186 [NewValue] [nvarchar](max) NULL
187)
188GO
189/****** Object: UserDefinedFunction [dbo].[ActionToTake] Script Date: 10/16/2020 7:31:03 PM ******/
190SET ANSI_NULLS ON
191GO
192SET QUOTED_IDENTIFIER ON
193GO
194
195
196-- =============================================
197-- Author: Gary Savard
198-- Create date: 28 April 11
199-- Description: This function validates the actions to be taken when a household member becomes the client, etc.
200-- If the input value is valid, then the function returns 1, if not, 0.
201-- =============================================
202CREATE FUNCTION [dbo].[ActionToTake]
203(
204 @Source NVarchar(8)
205
206)
207RETURNS int
208AS
209BEGIN
210 DECLARE
211 @Result int,
212 @Temp NVarchar(8)
213
214 SET @Result =0;
215 SET @Temp ='';
216
217
218 SELECT @Temp = LTRIM(RTRIM(@Source));--Clean any spaces out
219
220 IF @Temp = 'DEMOTE'
221 SET @Result = 1;
222 ELSE IF @Temp ='DELETE'
223 SET @Result = 1;
224 ELSE IF @Temp ='NEWHOUSEHOLD'
225 SET @Result = 1;
226 ELSE
227 SET @Result =0;
228
229
230
231 RETURN @Result;
232
233END
234
235
236
237GO
238/****** Object: UserDefinedFunction [dbo].[CheckRecertifyDate] Script Date: 10/16/2020 7:31:03 PM ******/
239SET ANSI_NULLS ON
240GO
241SET QUOTED_IDENTIFIER ON
242GO
243
244
245-- =============================================
246-- Author: Gary Savard
247-- Create date: 26 Oct 10
248-- Description: This function determines whether a customer must recertify based on the 1 year criteria
249-- The PersonID input is optional and, if it is zero then we just work based on the LastCertificationDate input
250-- If the PersonID is >0 then we get the last certification date from the foodshelf.foodshelfcertification table and ignore
251--the input date.
252-- =============================================
253CREATE FUNCTION [dbo].[CheckRecertifyDate]
254(
255 @PersonID int =0, --We can just do the calculation based on input date time, or by getting from the Foodshelf.FoodshelfCertification table
256 @LastCertificationDate DateTime
257
258)
259RETURNS bit
260AS
261BEGIN
262 DECLARE
263 @Result BIT,
264 @TempDate DATETIME
265 SET @Result =0; --Could debate whether 0 or 1 is better for default.
266 SET @TempDate =SYSDATETIME();
267
268 IF @PersonID =0
269 BEGIN
270 IF (DATEDIFF(DD,@LastCertificationDate,SYSDATETIME()) >= 365)
271 BEGIN
272 SET @Result =1;
273 RETURN @RESULT;
274 END
275 ELSE
276 BEGIN
277 SET @Result =0;
278 RETURN @Result;
279 END
280 END
281
282 ELSE
283 BEGIN
284 SELECT @TempDate = MAX(LastCertificationDate)
285 FROM Foodshelf.FoodShelfCertification Where PersonID = @PersonID
286
287 IF (DATEDIFF(DD,@TempDate,SYSDATETIME()) >= 365)
288 BEGIN
289 SET @Result =1;
290 RETURN @RESULT;
291 END
292 ELSE
293 BEGIN
294 SET @Result =0;
295 RETURN @Result;
296 END
297 END
298
299
300 RETURN @Result;
301
302END
303
304
305
306GO
307/****** Object: UserDefinedFunction [dbo].[TotalHours] Script Date: 10/16/2020 7:31:03 PM ******/
308SET ANSI_NULLS ON
309GO
310SET QUOTED_IDENTIFIER ON
311GO
312create function [dbo].[TotalHours]
313(
314@volID int
315)
316returns int
317as
318begin
319 declare @total int
320
321 set @total = (
322 select sum(a.ActualHoursTotal) from volunteer.VolunteerScheduleDayTime as a
323 where a.VolunteerPersonID = @volID
324 );
325
326 return @total;
327end
328
329
330
331
332
333
334GO
335/****** Object: UserDefinedFunction [dbo].[ValidateDataSource] Script Date: 10/16/2020 7:31:03 PM ******/
336SET ANSI_NULLS ON
337GO
338SET QUOTED_IDENTIFIER ON
339GO
340
341-- =============================================
342-- Author: Gary Savard
343-- Create date: 26 Oct 10
344-- Description: This function takes in a set of possible values for origin of a new record: FOOD,WX,MICRO,TENANT,COMMACT
345-- If the input value is valid, then the function returns 1, if not, 0.
346-- =============================================
347CREATE FUNCTION [dbo].[ValidateDataSource]
348(
349 @Source NVarchar(8)
350
351)
352RETURNS int
353AS
354BEGIN
355 DECLARE
356 @Result int,
357 @Temp NVarchar(8)
358
359 SET @Result =0;
360 SET @Temp ='';
361
362
363 SELECT @Temp = LTRIM(RTRIM(@Source));--Clean any spaces out
364
365 IF @Temp = 'FOOD'
366 SET @Result = 1;
367 ELSE IF @Temp ='WX'
368 SET @Result = 1;
369 ELSE IF @Temp ='MICRO'
370 SET @Result = 1;
371 ELSE IF @Temp ='TENANT'
372 SET @Result = 1;
373 ELSE IF @Temp ='COMMACT'
374 SET @Result = 1;
375 ELSE IF @Temp ='ADMIN'
376 SET @Result =1;
377 ELSE
378 SET @Result =0;
379
380
381
382 RETURN @Result;
383
384END
385
386
387GO
388/****** Object: Table [dbo].[GuidelinesByProgram] Script Date: 10/16/2020 7:31:03 PM ******/
389SET ANSI_NULLS ON
390GO
391SET QUOTED_IDENTIFIER ON
392GO
393CREATE TABLE [dbo].[GuidelinesByProgram](
394 [GuidelinesID] [int] IDENTITY(1,1) NOT NULL,
395 [ProgramID] [int] NOT NULL,
396 [ModifiedBy] [dbo].[Name] NOT NULL,
397 [ModifiedDate] [datetime] NOT NULL,
398 CONSTRAINT [PK_GuidelinesByProgram] PRIMARY KEY CLUSTERED
399(
400 [GuidelinesID] ASC,
401 [ProgramID] ASC
402)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
403) ON [PRIMARY]
404
405GO
406/****** Object: Table [dbo].[HouseholdTransferRequest] Script Date: 10/16/2020 7:31:03 PM ******/
407SET ANSI_NULLS ON
408GO
409SET QUOTED_IDENTIFIER ON
410GO
411CREATE TABLE [dbo].[HouseholdTransferRequest](
412 [ClientMaintenanceID] [int] IDENTITY(1,1) NOT NULL,
413 [OriginalClientID] [int] NULL,
414 [HouseholdMemberToMoveID] [int] NOT NULL,
415 [NewClientID] [int] NOT NULL,
416 [ActionRequested] [int] NOT NULL,
417 [Notes] [nvarchar](max) NULL,
418 [ModifiedDate] [datetime] NOT NULL,
419 [ModifiedBy] [dbo].[Name] NOT NULL
420) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
421
422GO
423/****** Object: Table [dbo].[JournalClientFamilyChanges] Script Date: 10/16/2020 7:31:03 PM ******/
424SET ANSI_NULLS ON
425GO
426SET QUOTED_IDENTIFIER ON
427GO
428CREATE TABLE [dbo].[JournalClientFamilyChanges](
429 [JournalClientFamilyChangesID] [int] IDENTITY(1,1) NOT NULL,
430 [HouseholdMembersID] [int] NOT NULL,
431 [PreviousClientsID] [int] NULL,
432 [NewClientsID] [int] NULL,
433 [ActionTaken] [nvarchar](50) NULL,
434 [Notes] [nvarchar](max) NULL,
435 [ModifiedBy] [dbo].[Name] NOT NULL,
436 [ModifiedDate] [datetime] NOT NULL
437) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
438
439GO
440/****** Object: Table [dbo].[JournalLookupTableChanges] Script Date: 10/16/2020 7:31:03 PM ******/
441SET ANSI_NULLS ON
442GO
443SET QUOTED_IDENTIFIER ON
444GO
445CREATE TABLE [dbo].[JournalLookupTableChanges](
446 [JournalLookupTableID] [int] IDENTITY(1,1) NOT NULL,
447 [TableName] [nvarchar](50) NULL,
448 [ActionTaken] [nvarchar](50) NOT NULL,
449 [OldValue] [nvarchar](max) NULL,
450 [OldLUTableID] [int] NULL,
451 [NewValue] [nvarchar](max) NULL,
452 [ModifiedBy] [dbo].[Name] NOT NULL,
453 [ModifiedDate] [datetime] NOT NULL
454) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
455
456GO
457/****** Object: Table [dbo].[LUHouseholdTransferOptions] Script Date: 10/16/2020 7:31:03 PM ******/
458SET ANSI_NULLS ON
459GO
460SET QUOTED_IDENTIFIER ON
461GO
462CREATE TABLE [dbo].[LUHouseholdTransferOptions](
463 [HouseholdTransferActionID] [int] IDENTITY(1,1) NOT NULL,
464 [ActionToTake] [nvarchar](50) NOT NULL,
465 [ActionToTakeDescription] [nvarchar](max) NULL,
466 [ModifiedDate] [datetime] NOT NULL,
467 [ModifiedBy] [dbo].[Name] NOT NULL,
468 [IsDeleted] [bit] NULL
469) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
470
471GO
472/****** Object: Table [dbo].[LUJoTypbe] Script Date: 10/16/2020 7:31:03 PM ******/
473SET ANSI_NULLS ON
474GO
475SET QUOTED_IDENTIFIER ON
476GO
477SET ANSI_PADDING ON
478GO
479CREATE TABLE [dbo].[LUJoTypbe](
480 [JobType] [int] NULL,
481 [JobDescript] [varchar](50) NULL
482) ON [PRIMARY]
483
484GO
485SET ANSI_PADDING OFF
486GO
487/****** Object: Table [dbo].[LUStateFederalProgram] Script Date: 10/16/2020 7:31:03 PM ******/
488SET ANSI_NULLS ON
489GO
490SET QUOTED_IDENTIFIER ON
491GO
492CREATE TABLE [dbo].[LUStateFederalProgram](
493 [StateFederalProgramID] [int] IDENTITY(1,1) NOT NULL,
494 [IsFederal] [bit] NOT NULL,
495 [ProgramName] [nvarchar](50) NOT NULL,
496 [ModifiedBy] [dbo].[Name] NOT NULL,
497 [ModifiedDate] [datetime] NOT NULL,
498 [IsDeleted] [bit] NULL,
499 CONSTRAINT [PK_LUStateFederalProgram] PRIMARY KEY CLUSTERED
500(
501 [StateFederalProgramID] ASC
502)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
503) ON [PRIMARY]
504
505GO
506/****** Object: Table [dbo].[Organization] Script Date: 10/16/2020 7:31:03 PM ******/
507SET ANSI_NULLS ON
508GO
509SET QUOTED_IDENTIFIER ON
510GO
511CREATE TABLE [dbo].[Organization](
512 [OrganizationID] [int] NOT NULL,
513 [OrganizationName] [nvarchar](50) NOT NULL,
514 [Phone] [nchar](10) NULL,
515 [Address] [nvarchar](50) NULL,
516 [Note] [nvarchar](max) NULL,
517 [ModifiedDate] [datetime] NOT NULL,
518 [ModifiedBy] [dbo].[Name] NOT NULL,
519 CONSTRAINT [PK_Organization] PRIMARY KEY CLUSTERED
520(
521 [OrganizationID] ASC
522)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
523) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
524
525GO
526/****** Object: Table [dbo].[ProgramGuidelines] Script Date: 10/16/2020 7:31:03 PM ******/
527SET ANSI_NULLS ON
528GO
529SET QUOTED_IDENTIFIER ON
530GO
531CREATE TABLE [dbo].[ProgramGuidelines](
532 [ProgramGuidelinesID] [int] IDENTITY(1,1) NOT NULL,
533 [GuidelinesID] [int] NOT NULL,
534 [Guideline1] [nvarchar](max) NOT NULL,
535 [Guideline2] [nvarchar](max) NULL,
536 [Guideline3] [nvarchar](max) NULL,
537 [Guideline4] [nvarchar](max) NULL,
538 CONSTRAINT [PK_ProgramGuidelines] PRIMARY KEY CLUSTERED
539(
540 [ProgramGuidelinesID] ASC
541)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
542) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
543
544GO
545/****** Object: Table [Foodshelf].[FoodShelfCertification] Script Date: 10/16/2020 7:31:03 PM ******/
546SET ANSI_NULLS ON
547GO
548SET QUOTED_IDENTIFIER ON
549GO
550CREATE TABLE [Foodshelf].[FoodShelfCertification](
551 [FoodShelfCertificationID] [int] IDENTITY(1,1) NOT NULL,
552 [PersonID] [int] NOT NULL,
553 [CertificationTextID] [int] NOT NULL,
554 [LastCertificationDate] [datetime] NOT NULL,
555 [IsPaperCertification] [bit] NULL,
556 [PaperCertificationDate] [datetime] NULL,
557 [ModifiedDate] [datetime] NOT NULL,
558 [ModifiedBy] [dbo].[Name] NOT NULL,
559 CONSTRAINT [PK_FoodShelfCertification_1] PRIMARY KEY CLUSTERED
560(
561 [FoodShelfCertificationID] ASC
562)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
563 CONSTRAINT [UK_FoodShelfCertification] UNIQUE NONCLUSTERED
564(
565 [FoodShelfCertificationID] ASC,
566 [PersonID] ASC
567)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
568) ON [PRIMARY]
569
570GO
571/****** Object: Table [Foodshelf].[FoodshelfRules] Script Date: 10/16/2020 7:31:03 PM ******/
572SET ANSI_NULLS ON
573GO
574SET QUOTED_IDENTIFIER ON
575GO
576CREATE TABLE [Foodshelf].[FoodshelfRules](
577 [FoodshelfRulesID] [int] IDENTITY(1,1) NOT NULL,
578 [FoodshelfRules] [nvarchar](max) NOT NULL,
579 [ModifiedDate] [datetime] NOT NULL,
580 [ModifiedBy] [dbo].[Name] NOT NULL
581) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
582
583GO
584/****** Object: Table [Foodshelf].[FoodTypeGiven] Script Date: 10/16/2020 7:31:03 PM ******/
585SET ANSI_NULLS ON
586GO
587SET QUOTED_IDENTIFIER ON
588GO
589CREATE TABLE [Foodshelf].[FoodTypeGiven](
590 [PersonID] [int] NOT NULL,
591 [FoodTypeGivenID] [int] IDENTITY(1,1) NOT NULL,
592 [ReceivedDate] [datetime] NOT NULL,
593 [FoodGiven] [Foodshelf].[GroceryOrBreadProduce] NOT NULL,
594 [ModifiedDate] [datetime] NOT NULL,
595 [ModifiedBy] [dbo].[Name] NOT NULL,
596 CONSTRAINT [PK_FoodTypeGiven] PRIMARY KEY CLUSTERED
597(
598 [PersonID] ASC,
599 [FoodTypeGivenID] ASC
600)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
601 CONSTRAINT [UK_FoodTypeGiven] UNIQUE NONCLUSTERED
602(
603 [FoodTypeGivenID] ASC
604)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
605 CONSTRAINT [UK_FoodTypeGivenRecord] UNIQUE NONCLUSTERED
606(
607 [FoodTypeGivenID] ASC,
608 [PersonID] ASC
609)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
610) ON [PRIMARY]
611
612GO
613/****** Object: Table [Foodshelf].[HouseholdNotes] Script Date: 10/16/2020 7:31:03 PM ******/
614SET ANSI_NULLS ON
615GO
616SET QUOTED_IDENTIFIER ON
617GO
618CREATE TABLE [Foodshelf].[HouseholdNotes](
619 [HouseholdNotesID] [int] IDENTITY(1,1) NOT NULL,
620 [ClientPersonID] [int] NOT NULL,
621 [HouseholdMemberPersonID] [int] NULL,
622 [Notes] [nvarchar](max) NOT NULL,
623 [ModifiedBy] [dbo].[Name] NOT NULL,
624 [ModifiedDate] [datetime] NOT NULL,
625 CONSTRAINT [PK_Table_1] PRIMARY KEY CLUSTERED
626(
627 [HouseholdNotesID] ASC,
628 [ClientPersonID] ASC
629)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
630) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
631
632GO
633/****** Object: Table [Foodshelf].[LUCertificationText] Script Date: 10/16/2020 7:31:03 PM ******/
634SET ANSI_NULLS ON
635GO
636SET QUOTED_IDENTIFIER ON
637GO
638CREATE TABLE [Foodshelf].[LUCertificationText](
639 [CertificationTextID] [int] IDENTITY(1,1) NOT NULL,
640 [CertificationText] [nvarchar](max) NOT NULL,
641 [GuidelinesText] [nvarchar](max) NULL,
642 [ModifiedDate] [datetime] NOT NULL,
643 [ModifiedBy] [dbo].[Name] NOT NULL,
644 [IsDeleted] [bit] NULL
645) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
646
647GO
648/****** Object: Table [Foodshelf].[Signature] Script Date: 10/16/2020 7:31:03 PM ******/
649SET ANSI_NULLS ON
650GO
651SET QUOTED_IDENTIFIER ON
652GO
653SET ANSI_PADDING ON
654GO
655CREATE TABLE [Foodshelf].[Signature](
656 [SignatureID] [int] IDENTITY(1,1) NOT NULL,
657 [PersonID] [int] NOT NULL,
658 [FoodShelfCertificationID] [int] NOT NULL,
659 [Signature] [varchar](max) NOT NULL,
660 [ModifiedDate] [datetime] NOT NULL,
661 [ModifiedBy] [dbo].[Name] NOT NULL,
662 CONSTRAINT [PK_Signature] PRIMARY KEY CLUSTERED
663(
664 [SignatureID] ASC
665)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
666 CONSTRAINT [UK_Signature] UNIQUE NONCLUSTERED
667(
668 [SignatureID] ASC,
669 [PersonID] ASC
670)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
671) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
672
673GO
674SET ANSI_PADDING OFF
675GO
676/****** Object: Table [Maintenance].[UserModifiableTables] Script Date: 10/16/2020 7:31:03 PM ******/
677SET ANSI_NULLS ON
678GO
679SET QUOTED_IDENTIFIER ON
680GO
681CREATE TABLE [Maintenance].[UserModifiableTables](
682 [UserModifiableTablesID] [int] IDENTITY(1,1) NOT NULL,
683 [FromSchema] [nvarchar](30) NOT NULL,
684 [FromTable] [nchar](50) NOT NULL,
685 [ModifiedDate] [datetime] NOT NULL,
686 [ModifiedBy] [dbo].[Name] NOT NULL
687) ON [PRIMARY]
688
689GO
690/****** Object: Table [Message].[Msg] Script Date: 10/16/2020 7:31:03 PM ******/
691SET ANSI_NULLS ON
692GO
693SET QUOTED_IDENTIFIER ON
694GO
695SET ANSI_PADDING ON
696GO
697CREATE TABLE [Message].[Msg](
698 [MessageID] [int] IDENTITY(1,1) NOT NULL,
699 [UserName] [dbo].[Name] NULL,
700 [ErrMsg] [varchar](50) NULL,
701 [ErrNo] [varchar](50) NULL,
702 [StoredProcedure] [varchar](100) NULL,
703 [inputValues] [varchar](max) NULL,
704 [ErrDate] [datetime] NULL
705) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
706
707GO
708SET ANSI_PADDING OFF
709GO
710/****** Object: Table [Person].[Address] Script Date: 10/16/2020 7:31:03 PM ******/
711SET ANSI_NULLS ON
712GO
713SET QUOTED_IDENTIFIER ON
714GO
715CREATE TABLE [Person].[Address](
716 [AddressID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
717 [PersonID] [int] NOT NULL,
718 [AddressLine1] [nvarchar](60) NOT NULL,
719 [AddressLine2] [nvarchar](60) NULL,
720 [City] [nvarchar](30) NOT NULL,
721 [County] [nvarchar](30) NULL,
722 [State] [nvarchar](2) NOT NULL,
723 [PostalCode] [nvarchar](10) NULL,
724 [AddressTypeID] [int] NULL,
725 [ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Address_ModifiedDate] DEFAULT (getdate()),
726 [ModifiedBy] [dbo].[Name] NOT NULL,
727 CONSTRAINT [PK_Address] PRIMARY KEY CLUSTERED
728(
729 [AddressID] ASC
730)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
731) ON [PRIMARY]
732
733GO
734/****** Object: Table [Person].[Demographics] Script Date: 10/16/2020 7:31:03 PM ******/
735SET ANSI_NULLS ON
736GO
737SET QUOTED_IDENTIFIER ON
738GO
739CREATE TABLE [Person].[Demographics](
740 [DemographicsID] [int] IDENTITY(1,1) NOT NULL,
741 [PersonID] [int] NOT NULL,
742 [EducationCategoryID] [int] NULL,
743 [HousingStatus] [nvarchar](50) NULL,
744 [NumberInHousehold] [int] NULL,
745 [Gender] [nvarchar](2) NULL,
746 [Race] [nvarchar](20) NULL,
747 [CountryOfOrigin] [nvarchar](70) NULL,
748 [Ethnicity] [nvarchar](20) NULL,
749 [Disability] [dbo].[NoYesMaybe] NOT NULL,
750 [CSFP] [dbo].[NoYesMaybe] NOT NULL,
751 [Veteran] [dbo].[NoYesMaybe] NOT NULL,
752 [HealthInsurance] [dbo].[NoYesMaybe] NOT NULL,
753 [FamilyStatusType] [nvarchar](50) NULL,
754 [InsuranceType] [nvarchar](50) NULL,
755 [FoodStamps] [dbo].[NoYesMaybe] NOT NULL,
756 [HomeboundDelivery] [dbo].[NoYesMaybe] NOT NULL,
757 [ModifiedDate] [datetime] NOT NULL,
758 [ModifiedBy] [dbo].[Name] NOT NULL,
759 [IsWorker] [int] NULL,
760 CONSTRAINT [PK__Deomogra__E81ABA19151B244E] PRIMARY KEY CLUSTERED
761(
762 [DemographicsID] ASC
763)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
764) ON [PRIMARY]
765
766GO
767/****** Object: Table [Person].[FamilyRelationships] Script Date: 10/16/2020 7:31:03 PM ******/
768SET ANSI_NULLS ON
769GO
770SET QUOTED_IDENTIFIER ON
771GO
772CREATE TABLE [Person].[FamilyRelationships](
773 [FamilyRelationshipID] [int] IDENTITY(1,1) NOT NULL,
774 [PersonID] [int] NOT NULL,
775 [ClientPersonID] [int] NOT NULL,
776 [RelationshipID] [int] NOT NULL,
777 [RelationDescription] [nvarchar](50) NOT NULL,
778 [ModifiedDate] [datetime] NOT NULL,
779 [ModifiedBy] [dbo].[Name] NOT NULL,
780 CONSTRAINT [PK_FamilyRelationships] PRIMARY KEY CLUSTERED
781(
782 [FamilyRelationshipID] ASC
783)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
784 CONSTRAINT [UK_FamilyRelationships] UNIQUE NONCLUSTERED
785(
786 [ClientPersonID] ASC,
787 [PersonID] ASC
788)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
789) ON [PRIMARY]
790
791GO
792/****** Object: Table [Person].[Income] Script Date: 10/16/2020 7:31:03 PM ******/
793SET ANSI_NULLS ON
794GO
795SET QUOTED_IDENTIFIER ON
796GO
797CREATE TABLE [Person].[Income](
798 [IncomeSourceRowID] [int] IDENTITY(1,1) NOT NULL,
799 [IncomeSourceID] [int] NOT NULL,
800 [PersonID] [int] NOT NULL,
801 [ModifiedBy] [dbo].[Name] NOT NULL,
802 [ModifiedDate] [datetime] NOT NULL,
803 CONSTRAINT [PK_Income] PRIMARY KEY CLUSTERED
804(
805 [IncomeSourceRowID] ASC
806)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
807 CONSTRAINT [UK_IncomeSource] UNIQUE NONCLUSTERED
808(
809 [IncomeSourceRowID] ASC,
810 [PersonID] ASC
811)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
812) ON [PRIMARY]
813
814GO
815/****** Object: Table [Person].[LanguagesSpoken] Script Date: 10/16/2020 7:31:03 PM ******/
816SET ANSI_NULLS ON
817GO
818SET QUOTED_IDENTIFIER ON
819GO
820CREATE TABLE [Person].[LanguagesSpoken](
821 [LanguageID] [int] NOT NULL,
822 [PersonID] [int] NOT NULL,
823 [IsPrimaryLanguage] [bit] NOT NULL,
824 [ModifiedDate] [datetime] NOT NULL,
825 [ModifiedBy] [dbo].[Name] NOT NULL,
826 [rowid] [uniqueidentifier] ROWGUIDCOL NOT NULL,
827 [LanguagesSpokenID] [int] IDENTITY(1,1) NOT NULL,
828 CONSTRAINT [PK_LanguagesSpoken] PRIMARY KEY CLUSTERED
829(
830 [LanguageID] ASC
831)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
832) ON [PRIMARY]
833
834GO
835/****** Object: Table [Person].[LUAddressType] Script Date: 10/16/2020 7:31:03 PM ******/
836SET ANSI_NULLS ON
837GO
838SET QUOTED_IDENTIFIER ON
839GO
840CREATE TABLE [Person].[LUAddressType](
841 [AddressTypeID] [int] IDENTITY(1,1) NOT NULL,
842 [AddressType] [nvarchar](10) NOT NULL,
843 [ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_AddressType_ModifiedDate] DEFAULT (getdate()),
844 [ModifiedBy] [dbo].[Name] NOT NULL,
845 [IsDeleted] [bit] NULL,
846 CONSTRAINT [PK_AddressType_AddressTypeID] PRIMARY KEY CLUSTERED
847(
848 [AddressTypeID] ASC
849)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
850) ON [PRIMARY]
851
852GO
853/****** Object: Table [Person].[LUCity] Script Date: 10/16/2020 7:31:03 PM ******/
854SET ANSI_NULLS ON
855GO
856SET QUOTED_IDENTIFIER ON
857GO
858CREATE TABLE [Person].[LUCity](
859 [CityID] [int] IDENTITY(1,1) NOT NULL,
860 [StateID] [int] NOT NULL,
861 [CountyID] [int] NOT NULL,
862 [PostalCodeID] [int] NOT NULL,
863 [CityName] [nvarchar](30) NOT NULL,
864 [CityAbbreviation] [nvarchar](30) NULL,
865 [ModifiedDate] [datetime] NOT NULL,
866 [ModifiedBy] [dbo].[Name] NOT NULL,
867 [IsDeleted] [bit] NULL,
868 CONSTRAINT [PK_LUCity] PRIMARY KEY CLUSTERED
869(
870 [CityID] ASC
871)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
872) ON [PRIMARY]
873
874GO
875/****** Object: Table [Person].[LUContactType] Script Date: 10/16/2020 7:31:03 PM ******/
876SET ANSI_NULLS ON
877GO
878SET QUOTED_IDENTIFIER ON
879GO
880CREATE TABLE [Person].[LUContactType](
881 [ContactTypeID] [int] IDENTITY(1,1) NOT NULL,
882 [Name] [dbo].[Name] NOT NULL,
883 [ModifiedDate] [datetime] NOT NULL,
884 [ModifiedBy] [dbo].[Name] NOT NULL,
885 [IsDeleted] [bit] NULL,
886 CONSTRAINT [PK_ContactType_ContactTypeID] PRIMARY KEY CLUSTERED
887(
888 [ContactTypeID] ASC
889)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
890) ON [PRIMARY]
891
892GO
893/****** Object: Table [Person].[LUCountryOfOrigin] Script Date: 10/16/2020 7:31:03 PM ******/
894SET ANSI_NULLS ON
895GO
896SET QUOTED_IDENTIFIER ON
897GO
898CREATE TABLE [Person].[LUCountryOfOrigin](
899 [CountryID] [int] IDENTITY(1,1) NOT NULL,
900 [CountryAbbreviation] [nvarchar](50) NULL,
901 [CountryName] [nvarchar](70) NOT NULL,
902 [FIPSCode] [nvarchar](2) NULL,
903 [ModifiedDate] [datetime] NOT NULL,
904 [ModifiedBy] [dbo].[Name] NOT NULL,
905 [IsDeleted] [bit] NULL
906) ON [PRIMARY]
907
908GO
909/****** Object: Table [Person].[LUCounty] Script Date: 10/16/2020 7:31:03 PM ******/
910SET ANSI_NULLS ON
911GO
912SET QUOTED_IDENTIFIER ON
913GO
914CREATE TABLE [Person].[LUCounty](
915 [CountyID] [int] IDENTITY(1,1) NOT NULL,
916 [CityID] [int] NOT NULL,
917 [StateID] [int] NOT NULL,
918 [CountyName] [nvarchar](20) NOT NULL,
919 [ModifiedDate] [datetime] NOT NULL,
920 [ModifiedBy] [dbo].[Name] NOT NULL,
921 [IsDeleted] [bit] NULL,
922 CONSTRAINT [PK_LUCounty] PRIMARY KEY CLUSTERED
923(
924 [CountyID] ASC
925)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
926 CONSTRAINT [UK_LUCounty] UNIQUE NONCLUSTERED
927(
928 [CountyID] ASC,
929 [CityID] ASC,
930 [StateID] ASC
931)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
932) ON [PRIMARY]
933
934GO
935/****** Object: Table [Person].[LUEducationCategory] Script Date: 10/16/2020 7:31:03 PM ******/
936SET ANSI_NULLS ON
937GO
938SET QUOTED_IDENTIFIER ON
939GO
940CREATE TABLE [Person].[LUEducationCategory](
941 [EducationCategoryID] [int] IDENTITY(1,1) NOT NULL,
942 [EducationLevel] [nvarchar](50) NOT NULL,
943 [ModifiedDate] [datetime] NOT NULL,
944 [ModifiedBy] [dbo].[Name] NOT NULL,
945 [IsDeleted] [bit] NULL
946) ON [PRIMARY]
947
948GO
949/****** Object: Table [Person].[LUEthnicity] Script Date: 10/16/2020 7:31:03 PM ******/
950SET ANSI_NULLS ON
951GO
952SET QUOTED_IDENTIFIER ON
953GO
954CREATE TABLE [Person].[LUEthnicity](
955 [EthnicityID] [int] IDENTITY(1,1) NOT NULL,
956 [EthnicityAbbreviation] [nvarchar](20) NOT NULL,
957 [EthnicityDescription] [nvarchar](50) NOT NULL,
958 [ModifiedDate] [datetime] NOT NULL,
959 [ModifiedBy] [dbo].[Name] NOT NULL,
960 [IsDeleted] [bit] NULL
961) ON [PRIMARY]
962
963GO
964/****** Object: Table [Person].[LUFamilyRelationship] Script Date: 10/16/2020 7:31:03 PM ******/
965SET ANSI_NULLS ON
966GO
967SET QUOTED_IDENTIFIER ON
968GO
969CREATE TABLE [Person].[LUFamilyRelationship](
970 [FamilyRelationshipID] [int] IDENTITY(1,1) NOT NULL,
971 [RelationshipCode] [nvarchar](30) NOT NULL,
972 [RelationshipDescription] [nvarchar](50) NOT NULL,
973 [ModifiedDate] [datetime] NOT NULL,
974 [ModifiedBy] [dbo].[Name] NOT NULL,
975 [IsDeleted] [bit] NULL
976) ON [PRIMARY]
977
978GO
979/****** Object: Table [Person].[LUFamilyStatusType] Script Date: 10/16/2020 7:31:03 PM ******/
980SET ANSI_NULLS ON
981GO
982SET QUOTED_IDENTIFIER ON
983GO
984CREATE TABLE [Person].[LUFamilyStatusType](
985 [FamilyStatusTypeID] [int] IDENTITY(1,1) NOT NULL,
986 [FamilyStatusType] [nvarchar](50) NOT NULL,
987 [ModifiedBy] [dbo].[Name] NOT NULL,
988 [ModifiedDate] [datetime] NOT NULL,
989 [IsDeleted] [bit] NULL
990) ON [PRIMARY]
991
992GO
993/****** Object: Table [Person].[LUHousingStatus] Script Date: 10/16/2020 7:31:03 PM ******/
994SET ANSI_NULLS ON
995GO
996SET QUOTED_IDENTIFIER ON
997GO
998CREATE TABLE [Person].[LUHousingStatus](
999 [HousingStatusID] [int] IDENTITY(1,1) NOT NULL,
1000 [HousingStatus] [nvarchar](50) NOT NULL,
1001 [ModifiedDate] [datetime] NOT NULL,
1002 [ModifiedBy] [dbo].[Name] NOT NULL,
1003 [IsDeleted] [bit] NULL
1004) ON [PRIMARY]
1005
1006GO
1007/****** Object: Table [Person].[LUIncomeSource] Script Date: 10/16/2020 7:31:03 PM ******/
1008SET ANSI_NULLS ON
1009GO
1010SET QUOTED_IDENTIFIER ON
1011GO
1012CREATE TABLE [Person].[LUIncomeSource](
1013 [IncomeSourceID] [int] IDENTITY(1,1) NOT NULL,
1014 [IncomeSourceAbbreviation] [nvarchar](20) NOT NULL,
1015 [IncomeSourceDescription] [nvarchar](50) NULL,
1016 [ModifiedDate] [datetime] NOT NULL,
1017 [ModifiedBy] [dbo].[Name] NOT NULL,
1018 [IsDeleted] [bit] NULL
1019) ON [PRIMARY]
1020
1021GO
1022/****** Object: Table [Person].[LUInsuranceType] Script Date: 10/16/2020 7:31:03 PM ******/
1023SET ANSI_NULLS ON
1024GO
1025SET QUOTED_IDENTIFIER ON
1026GO
1027CREATE TABLE [Person].[LUInsuranceType](
1028 [InsuranceTypeID] [int] IDENTITY(1,1) NOT NULL,
1029 [InsuranceType] [nvarchar](50) NOT NULL,
1030 [ModifiedBy] [dbo].[Name] NOT NULL,
1031 [ModifiedDate] [datetime] NOT NULL,
1032 [IsDeleted] [bit] NULL
1033) ON [PRIMARY]
1034
1035GO
1036/****** Object: Table [Person].[LULanguage] Script Date: 10/16/2020 7:31:03 PM ******/
1037SET ANSI_NULLS ON
1038GO
1039SET QUOTED_IDENTIFIER ON
1040GO
1041CREATE TABLE [Person].[LULanguage](
1042 [LanguageID] [int] IDENTITY(1,1) NOT NULL,
1043 [LanguageName] [nvarchar](50) NOT NULL,
1044 [ModifiedDate] [datetime] NOT NULL,
1045 [ModifiedBy] [dbo].[Name] NOT NULL,
1046 [IsDeleted] [bit] NULL
1047) ON [PRIMARY]
1048
1049GO
1050/****** Object: Table [Person].[LUPersonType] Script Date: 10/16/2020 7:31:03 PM ******/
1051SET ANSI_NULLS ON
1052GO
1053SET QUOTED_IDENTIFIER ON
1054GO
1055CREATE TABLE [Person].[LUPersonType](
1056 [PersonTypeID] [int] IDENTITY(1,1) NOT NULL,
1057 [PersonType] [nvarchar](20) NOT NULL,
1058 [ModifiedDate] [datetime] NOT NULL,
1059 [ModifiedBy] [dbo].[Name] NOT NULL,
1060 [IsDeleted] [bit] NULL
1061) ON [PRIMARY]
1062
1063GO
1064/****** Object: Table [Person].[LUPhoneType] Script Date: 10/16/2020 7:31:03 PM ******/
1065SET ANSI_NULLS ON
1066GO
1067SET QUOTED_IDENTIFIER ON
1068GO
1069CREATE TABLE [Person].[LUPhoneType](
1070 [PhoneTypeID] [int] IDENTITY(1,1) NOT NULL,
1071 [PhoneType] [nvarchar](50) NOT NULL,
1072 [ModifiedDate] [datetime] NOT NULL,
1073 [ModifiedBy] [dbo].[Name] NOT NULL,
1074 [IsDeleted] [bit] NULL
1075) ON [PRIMARY]
1076
1077GO
1078/****** Object: Table [Person].[LUPostalCode] Script Date: 10/16/2020 7:31:03 PM ******/
1079SET ANSI_NULLS ON
1080GO
1081SET QUOTED_IDENTIFIER ON
1082GO
1083CREATE TABLE [Person].[LUPostalCode](
1084 [PostalCodeID] [int] IDENTITY(1,1) NOT NULL,
1085 [CityID] [int] NOT NULL,
1086 [PostalCode] [nvarchar](50) NOT NULL,
1087 [ModifiedDate] [datetime] NOT NULL,
1088 [ModifiedBy] [dbo].[Name] NOT NULL,
1089 [IsDeleted] [bit] NULL,
1090 CONSTRAINT [PK_LUPostalCode] PRIMARY KEY CLUSTERED
1091(
1092 [PostalCodeID] ASC,
1093 [CityID] ASC
1094)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1095) ON [PRIMARY]
1096
1097GO
1098/****** Object: Table [Person].[LUProgramServiceType] Script Date: 10/16/2020 7:31:03 PM ******/
1099SET ANSI_NULLS ON
1100GO
1101SET QUOTED_IDENTIFIER ON
1102GO
1103CREATE TABLE [Person].[LUProgramServiceType](
1104 [ProgramServiceTypeID] [int] IDENTITY(1,1) NOT NULL,
1105 [ServiceCode] [nvarchar](20) NOT NULL,
1106 [ServiceDescription] [nvarchar](50) NOT NULL,
1107 [ModifiedDate] [datetime] NOT NULL,
1108 [ModifiedBy] [dbo].[Name] NOT NULL,
1109 [IsDeleted] [bit] NULL
1110) ON [PRIMARY]
1111
1112GO
1113/****** Object: Table [Person].[LUProgramType] Script Date: 10/16/2020 7:31:03 PM ******/
1114SET ANSI_NULLS ON
1115GO
1116SET QUOTED_IDENTIFIER ON
1117GO
1118CREATE TABLE [Person].[LUProgramType](
1119 [ProgramTypeID] [int] IDENTITY(1,1) NOT NULL,
1120 [ProgramName] [nvarchar](20) NOT NULL,
1121 [ProgramDescription] [nvarchar](50) NOT NULL,
1122 [ModifiedDate] [datetime] NOT NULL,
1123 [ModifiedBy] [dbo].[Name] NOT NULL,
1124 [IsDeleted] [bit] NULL
1125) ON [PRIMARY]
1126
1127GO
1128/****** Object: Table [Person].[LURace] Script Date: 10/16/2020 7:31:03 PM ******/
1129SET ANSI_NULLS ON
1130GO
1131SET QUOTED_IDENTIFIER ON
1132GO
1133CREATE TABLE [Person].[LURace](
1134 [RaceID] [int] IDENTITY(1,1) NOT NULL,
1135 [RaceAbbreviation] [nvarchar](20) NOT NULL,
1136 [RaceDescription] [nvarchar](50) NOT NULL,
1137 [ModifiedDate] [datetime] NOT NULL,
1138 [ModifiedBy] [dbo].[Name] NOT NULL,
1139 [IsDeleted] [bit] NULL
1140) ON [PRIMARY]
1141
1142GO
1143/****** Object: Table [Person].[LUState] Script Date: 10/16/2020 7:31:03 PM ******/
1144SET ANSI_NULLS ON
1145GO
1146SET QUOTED_IDENTIFIER ON
1147GO
1148CREATE TABLE [Person].[LUState](
1149 [StateID] [int] IDENTITY(1,1) NOT NULL,
1150 [StateCode] [nvarchar](2) NOT NULL,
1151 [Name] [dbo].[Name] NOT NULL,
1152 [ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_State_ModifiedDate] DEFAULT (getdate()),
1153 [ModifiedBy] [dbo].[Name] NOT NULL,
1154 [IsDeleted] [bit] NULL,
1155 CONSTRAINT [PK_State_StateID] PRIMARY KEY CLUSTERED
1156(
1157 [StateID] ASC
1158)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1159) ON [PRIMARY]
1160
1161GO
1162/****** Object: Table [Person].[Notes] Script Date: 10/16/2020 7:31:03 PM ******/
1163SET ANSI_NULLS ON
1164GO
1165SET QUOTED_IDENTIFIER ON
1166GO
1167CREATE TABLE [Person].[Notes](
1168 [HouseholdNotesID] [int] IDENTITY(1,1) NOT NULL,
1169 [PersonID] [int] NOT NULL,
1170 [Notes] [nvarchar](max) NOT NULL,
1171 [ModifiedBy] [dbo].[Name] NOT NULL,
1172 [ModifiedDate] [datetime] NOT NULL,
1173 CONSTRAINT [PK_Table_1] PRIMARY KEY CLUSTERED
1174(
1175 [HouseholdNotesID] ASC,
1176 [PersonID] ASC
1177)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1178) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
1179
1180GO
1181/****** Object: Table [Person].[Person] Script Date: 10/16/2020 7:31:03 PM ******/
1182SET ANSI_NULLS ON
1183GO
1184SET QUOTED_IDENTIFIER ON
1185GO
1186SET ANSI_PADDING ON
1187GO
1188CREATE TABLE [Person].[Person](
1189 [PersonID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
1190 [Title] [varchar](50) NULL,
1191 [FirstName] [varchar](50) NOT NULL,
1192 [MiddleName] [varchar](50) NULL,
1193 [LastName] [varchar](50) NOT NULL,
1194 [Suffix] [varchar](10) NULL,
1195 [DateOfBirth] [datetime] NULL,
1196 [EmailAddress] [varchar](50) NULL,
1197 [EmailContactPreference] [int] NULL,
1198 [ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Person_ModifiedDate] DEFAULT (getdate()),
1199 [ModifiedBy] [varchar](50) NOT NULL,
1200 [IsVolunteer] [bit] NULL,
1201 [IsDeleted] [bit] NOT NULL,
1202 CONSTRAINT [PK_Person_PersonID] PRIMARY KEY CLUSTERED
1203(
1204 [PersonID] ASC
1205)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1206) ON [PRIMARY]
1207
1208GO
1209SET ANSI_PADDING OFF
1210GO
1211/****** Object: Table [Person].[PersonAddresses] Script Date: 10/16/2020 7:31:03 PM ******/
1212SET ANSI_NULLS ON
1213GO
1214SET QUOTED_IDENTIFIER ON
1215GO
1216CREATE TABLE [Person].[PersonAddresses](
1217 [AddressID] [int] NOT NULL,
1218 [PersonID] [int] NOT NULL,
1219 [ModifiedDate] [datetime] NOT NULL,
1220 [ModifiedBy] [dbo].[Name] NOT NULL,
1221 CONSTRAINT [PK_PersonAddresses] PRIMARY KEY CLUSTERED
1222(
1223 [AddressID] ASC,
1224 [PersonID] ASC
1225)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1226) ON [PRIMARY]
1227
1228GO
1229/****** Object: Table [Person].[Phone] Script Date: 10/16/2020 7:31:03 PM ******/
1230SET ANSI_NULLS ON
1231GO
1232SET QUOTED_IDENTIFIER ON
1233GO
1234CREATE TABLE [Person].[Phone](
1235 [PhoneID] [int] IDENTITY(1,1) NOT NULL,
1236 [PersonID] [int] NOT NULL,
1237 [PhoneNumber] [dbo].[Phone] NOT NULL,
1238 [PhoneExtension] [nvarchar](8) NULL,
1239 [PhoneType] [int] NOT NULL,
1240 [ModifiedDate] [datetime] NOT NULL,
1241 [ModifiedBy] [dbo].[Name] NOT NULL,
1242 CONSTRAINT [PK_Phone] PRIMARY KEY CLUSTERED
1243(
1244 [PhoneID] ASC
1245)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1246) ON [PRIMARY]
1247
1248GO
1249/****** Object: Table [Person].[Programs] Script Date: 10/16/2020 7:31:03 PM ******/
1250SET ANSI_NULLS ON
1251GO
1252SET QUOTED_IDENTIFIER ON
1253GO
1254CREATE TABLE [Person].[Programs](
1255 [ProgramsID] [int] IDENTITY(1,1) NOT NULL,
1256 [PersonID] [int] NOT NULL,
1257 [ProgramID] [int] NOT NULL,
1258 [ModifiedDate] [datetime] NOT NULL,
1259 [ModifiedBy] [dbo].[Name] NOT NULL,
1260 CONSTRAINT [PK_Programs] PRIMARY KEY CLUSTERED
1261(
1262 [PersonID] ASC,
1263 [ProgramID] ASC
1264)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1265) ON [PRIMARY]
1266
1267GO
1268/****** Object: Table [Person].[ProgramServicesUsed] Script Date: 10/16/2020 7:31:03 PM ******/
1269SET ANSI_NULLS ON
1270GO
1271SET QUOTED_IDENTIFIER ON
1272GO
1273CREATE TABLE [Person].[ProgramServicesUsed](
1274 [ServiceID] [int] IDENTITY(1,1) NOT NULL,
1275 [PersonID] [int] NOT NULL,
1276 [ProgramID] [int] NOT NULL,
1277 [ModifiedDate] [datetime] NOT NULL,
1278 [ModifiedBy] [dbo].[Name] NOT NULL,
1279 [ProgramServiceID] [int] NOT NULL,
1280 CONSTRAINT [PK_ProgramServicesUsed_1] PRIMARY KEY CLUSTERED
1281(
1282 [ServiceID] ASC,
1283 [PersonID] ASC,
1284 [ProgramID] ASC,
1285 [ProgramServiceID] ASC
1286)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
1287 CONSTRAINT [PK_ProgramService] UNIQUE NONCLUSTERED
1288(
1289 [ServiceID] ASC
1290)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
1291 CONSTRAINT [UK_ProgramServicesUsed] UNIQUE NONCLUSTERED
1292(
1293 [ServiceID] ASC
1294)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1295) ON [PRIMARY]
1296
1297GO
1298/****** Object: Table [Signature].[Signature] Script Date: 10/16/2020 7:31:03 PM ******/
1299SET ANSI_NULLS ON
1300GO
1301SET QUOTED_IDENTIFIER ON
1302GO
1303SET ANSI_PADDING ON
1304GO
1305CREATE TABLE [Signature].[Signature](
1306 [SignatureID] [int] IDENTITY(1,1) NOT NULL,
1307 [PersonID] [int] NOT NULL,
1308 [Signature] [varchar](max) NOT NULL,
1309 [ModifiedDate] [datetime] NOT NULL,
1310 [ModifiedBy] [dbo].[Name] NOT NULL,
1311 CONSTRAINT [PK_Signature] PRIMARY KEY CLUSTERED
1312(
1313 [SignatureID] ASC
1314)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
1315 CONSTRAINT [UK_Signature] UNIQUE NONCLUSTERED
1316(
1317 [SignatureID] ASC,
1318 [PersonID] ASC
1319)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1320) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
1321
1322GO
1323SET ANSI_PADDING OFF
1324GO
1325/****** Object: Table [Signature].[Signatures] Script Date: 10/16/2020 7:31:03 PM ******/
1326SET ANSI_NULLS ON
1327GO
1328SET QUOTED_IDENTIFIER ON
1329GO
1330CREATE TABLE [Signature].[Signatures](
1331 [SignaturesID] [int] IDENTITY(1,1) NOT NULL,
1332 [PersonID] [int] NOT NULL,
1333 [SignatureID] [int] NOT NULL,
1334 [ModifiedDate] [datetime] NOT NULL,
1335 [ModifiedBy] [dbo].[Name] NOT NULL,
1336 CONSTRAINT [PK_Signatures] PRIMARY KEY CLUSTERED
1337(
1338 [SignaturesID] ASC
1339)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
1340 CONSTRAINT [UK_Signatures] UNIQUE NONCLUSTERED
1341(
1342 [SignaturesID] ASC,
1343 [PersonID] ASC,
1344 [SignatureID] ASC
1345)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1346) ON [PRIMARY]
1347
1348GO
1349/****** Object: Table [SSN].[SSN] Script Date: 10/16/2020 7:31:03 PM ******/
1350SET ANSI_NULLS ON
1351GO
1352SET QUOTED_IDENTIFIER ON
1353GO
1354CREATE TABLE [SSN].[SSN](
1355 [SSNID] [int] IDENTITY(1,1) NOT NULL,
1356 [PersonID] [int] NOT NULL,
1357 [SSN] [nvarchar](9) NOT NULL,
1358 [ModifiedDate] [datetime] NOT NULL,
1359 [ModifiedBy] [dbo].[Name] NOT NULL,
1360 CONSTRAINT [PK_SSN] PRIMARY KEY CLUSTERED
1361(
1362 [SSNID] ASC
1363)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
1364 CONSTRAINT [UK_SSN] UNIQUE NONCLUSTERED
1365(
1366 [SSN] ASC,
1367 [PersonID] ASC
1368)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1369) ON [PRIMARY]
1370
1371GO
1372/****** Object: Table [Volunteer].[EmContact] Script Date: 10/16/2020 7:31:03 PM ******/
1373SET ANSI_NULLS ON
1374GO
1375SET QUOTED_IDENTIFIER ON
1376GO
1377SET ANSI_PADDING ON
1378GO
1379CREATE TABLE [Volunteer].[EmContact](
1380 [VolunteerEmergencyContactID] [int] IDENTITY(1,1) NOT NULL,
1381 [VolunteerPersonID] [int] NOT NULL,
1382 [ContactFirstName] [varchar](50) NOT NULL,
1383 [ContactMidName] [varchar](50) NULL,
1384 [ContactLastName] [varchar](50) NOT NULL,
1385 [ContactPrimaryPhone] [varchar](50) NULL,
1386 [ContactAltPhone] [varchar](50) NULL,
1387 [ContactEmail] [varchar](50) NULL,
1388 [ContactAddress] [varchar](250) NULL,
1389 [ModifiedBy] [varchar](50) NOT NULL,
1390 [ModifiedDAte] [datetime] NOT NULL,
1391 CONSTRAINT [PK_EmContact] PRIMARY KEY CLUSTERED
1392(
1393 [VolunteerEmergencyContactID] ASC
1394)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1395) ON [PRIMARY]
1396
1397GO
1398SET ANSI_PADDING OFF
1399GO
1400/****** Object: Table [Volunteer].[LUMonthCode] Script Date: 10/16/2020 7:31:03 PM ******/
1401SET ANSI_NULLS ON
1402GO
1403SET QUOTED_IDENTIFIER ON
1404GO
1405SET ANSI_PADDING ON
1406GO
1407CREATE TABLE [Volunteer].[LUMonthCode](
1408 [Month] [varchar](15) NULL,
1409 [MonthCode] [int] NULL
1410) ON [PRIMARY]
1411
1412GO
1413SET ANSI_PADDING OFF
1414GO
1415/****** Object: Table [Volunteer].[LUOrganizationCode] Script Date: 10/16/2020 7:31:03 PM ******/
1416SET ANSI_NULLS ON
1417GO
1418SET QUOTED_IDENTIFIER ON
1419GO
1420SET ANSI_PADDING ON
1421GO
1422CREATE TABLE [Volunteer].[LUOrganizationCode](
1423 [Organization] [varchar](50) NULL,
1424 [Code] [int] NULL
1425) ON [PRIMARY]
1426
1427GO
1428SET ANSI_PADDING OFF
1429GO
1430/****** Object: Table [Volunteer].[LUPositionCode] Script Date: 10/16/2020 7:31:03 PM ******/
1431SET ANSI_NULLS ON
1432GO
1433SET QUOTED_IDENTIFIER ON
1434GO
1435SET ANSI_PADDING ON
1436GO
1437CREATE TABLE [Volunteer].[LUPositionCode](
1438 [Position] [varchar](50) NULL,
1439 [Code] [int] NULL,
1440 [Organization] [int] NULL
1441) ON [PRIMARY]
1442
1443GO
1444SET ANSI_PADDING OFF
1445GO
1446/****** Object: Table [Volunteer].[LUVolunteerJobType] Script Date: 10/16/2020 7:31:03 PM ******/
1447SET ANSI_NULLS ON
1448GO
1449SET QUOTED_IDENTIFIER ON
1450GO
1451SET ANSI_PADDING ON
1452GO
1453CREATE TABLE [Volunteer].[LUVolunteerJobType](
1454 [VolunteerJobTypeID] [int] IDENTITY(1,1) NOT NULL,
1455 [JobType] [varchar](50) NOT NULL,
1456 [JobDescription] [varchar](100) NOT NULL,
1457 [ModifiedDate] [datetime] NOT NULL,
1458 [ModifiedBy] [dbo].[Name] NOT NULL,
1459 [IsDeleted] [bit] NULL
1460) ON [PRIMARY]
1461
1462GO
1463SET ANSI_PADDING OFF
1464GO
1465/****** Object: Table [Volunteer].[VolunteerContactInformation] Script Date: 10/16/2020 7:31:03 PM ******/
1466SET ANSI_NULLS ON
1467GO
1468SET QUOTED_IDENTIFIER ON
1469GO
1470SET ANSI_PADDING ON
1471GO
1472CREATE TABLE [Volunteer].[VolunteerContactInformation](
1473 [VolunteerPersonID] [int] IDENTITY(1,1) NOT NULL,
1474 [IsActive] [bit] NOT NULL,
1475 [ModifiedDate] [datetime] NOT NULL,
1476 [PersonID] [int] NOT NULL,
1477 [ModifiedBy] [varchar](50) NOT NULL,
1478 [PrimaryPhone] [varchar](50) NULL,
1479 [AltPhone] [varchar](50) NULL,
1480 [Email] [varchar](50) NULL,
1481 CONSTRAINT [PK_VolunteerContactInformation] PRIMARY KEY CLUSTERED
1482(
1483 [VolunteerPersonID] ASC
1484)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1485) ON [PRIMARY]
1486
1487GO
1488SET ANSI_PADDING OFF
1489GO
1490/****** Object: Table [Volunteer].[VolunteerJobs] Script Date: 10/16/2020 7:31:03 PM ******/
1491SET ANSI_NULLS ON
1492GO
1493SET QUOTED_IDENTIFIER ON
1494GO
1495SET ANSI_PADDING ON
1496GO
1497CREATE TABLE [Volunteer].[VolunteerJobs](
1498 [VolunteerJobsID] [int] IDENTITY(1,1) NOT NULL,
1499 [VolunteerPersonID] [int] NOT NULL,
1500 [Job] [varchar](50) NOT NULL,
1501 [ModifiedDate] [datetime] NOT NULL,
1502 [ModifiedBy] [varchar](50) NOT NULL,
1503 [PositionCode] [int] NOT NULL,
1504 CONSTRAINT [PK_VolunteerJobs] PRIMARY KEY CLUSTERED
1505(
1506 [VolunteerJobsID] ASC
1507)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1508) ON [PRIMARY]
1509
1510GO
1511SET ANSI_PADDING OFF
1512GO
1513/****** Object: Table [Volunteer].[VolunteerNotes] Script Date: 10/16/2020 7:31:03 PM ******/
1514SET ANSI_NULLS ON
1515GO
1516SET QUOTED_IDENTIFIER ON
1517GO
1518SET ANSI_PADDING ON
1519GO
1520CREATE TABLE [Volunteer].[VolunteerNotes](
1521 [VolunteerNotesID] [int] IDENTITY(1,1) NOT NULL,
1522 [VolunteerPersonID] [int] NOT NULL,
1523 [Note] [varchar](250) NOT NULL,
1524 [ModifiedDate] [datetime] NOT NULL,
1525 [ModifiedBy] [dbo].[Name] NOT NULL,
1526 CONSTRAINT [PK_VolunteerNotes] PRIMARY KEY CLUSTERED
1527(
1528 [VolunteerNotesID] ASC
1529)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1530) ON [PRIMARY]
1531
1532GO
1533SET ANSI_PADDING OFF
1534GO
1535/****** Object: Table [Volunteer].[VolunteerScheduleDayTime] Script Date: 10/16/2020 7:31:03 PM ******/
1536SET ANSI_NULLS ON
1537GO
1538SET QUOTED_IDENTIFIER ON
1539GO
1540CREATE TABLE [Volunteer].[VolunteerScheduleDayTime](
1541 [VolunteerScheduleDayTimeID] [int] IDENTITY(1,1) NOT NULL,
1542 [DayOfWeek] [int] NOT NULL,
1543 [AvailableBeginTime] [time](0) NOT NULL,
1544 [AvailableEndTime] [time](0) NOT NULL,
1545 [IsNoShow] [bit] NOT NULL,
1546 [ActualHoursTotal] [numeric](18, 0) NOT NULL,
1547 [ModifiedDate] [datetime] NOT NULL,
1548 [VolunteerPersonID] [int] NOT NULL,
1549 [ModifiedBy] [dbo].[Name] NOT NULL,
1550 [Date] [date] NOT NULL,
1551 [Month] [int] NOT NULL,
1552 [Year] [int] NOT NULL,
1553 [JobID] [int] NOT NULL,
1554 CONSTRAINT [PK_VolunteerScheduleDayTime] PRIMARY KEY CLUSTERED
1555(
1556 [VolunteerScheduleDayTimeID] ASC
1557)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
1558) ON [PRIMARY]
1559
1560GO
1561/****** Object: UserDefinedFunction [dbo].[GetGroceryHistory] Script Date: 10/16/2020 7:31:03 PM ******/
1562SET ANSI_NULLS ON
1563GO
1564SET QUOTED_IDENTIFIER ON
1565GO
1566-- =============================================
1567-- Author: Gary Savard
1568-- Create date: 14 April, 2011
1569-- Description: Returns the number of times a client received groceries from the foodshelf in the past 6 months.
1570-- =============================================
1571CREATE FUNCTION [dbo].[GetGroceryHistory]
1572(@PersonID int)
1573RETURNS TABLE
1574AS
1575RETURN
1576 select ReceivedDate from foodshelf.FoodTypeGiven where PersonID =@PersonID
1577 and ReceivedDate between DATEADD(m,-6,(CONVERT(DATE,GETDATE()))) and CONVERT(DATE,GETDATE()) and FoodGiven =0;
1578
1579
1580GO
1581/****** Object: View [dbo].[vGetFoodshelfRules] Script Date: 10/16/2020 7:31:03 PM ******/
1582SET ANSI_NULLS ON
1583GO
1584SET QUOTED_IDENTIFIER ON
1585GO
1586CREATE VIEW [dbo].[vGetFoodshelfRules]
1587AS
1588SELECT FoodshelfRules
1589FROM Foodshelf.FoodshelfRules
1590WHERE (ModifiedDate =
1591 (SELECT MAX(ModifiedDate) AS Expr1
1592 FROM Foodshelf.FoodshelfRules AS FoodshelfRules_1))
1593
1594GO
1595ALTER TABLE [Person].[LanguagesSpoken] ADD CONSTRAINT [DF_LanguagesSpoken_rowid] DEFAULT (newid()) FOR [rowid]
1596GO
1597ALTER TABLE [Person].[LUContactType] ADD CONSTRAINT [DF_ContactType_ModifiedDate] DEFAULT (getdate()) FOR [ModifiedDate]
1598GO
1599ALTER TABLE [dbo].[GuidelinesByProgram] WITH CHECK ADD CONSTRAINT [FK_GuidelinesByProgram_LUStateFederalProgram] FOREIGN KEY([ProgramID])
1600REFERENCES [dbo].[LUStateFederalProgram] ([StateFederalProgramID])
1601GO
1602ALTER TABLE [dbo].[GuidelinesByProgram] CHECK CONSTRAINT [FK_GuidelinesByProgram_LUStateFederalProgram]
1603GO
1604ALTER TABLE [dbo].[GuidelinesByProgram] WITH CHECK ADD CONSTRAINT [FK_GuidelinesByProgram_ProgramGuidelines] FOREIGN KEY([GuidelinesID])
1605REFERENCES [dbo].[ProgramGuidelines] ([ProgramGuidelinesID])
1606GO
1607ALTER TABLE [dbo].[GuidelinesByProgram] CHECK CONSTRAINT [FK_GuidelinesByProgram_ProgramGuidelines]
1608GO
1609ALTER TABLE [Foodshelf].[FoodShelfCertification] WITH CHECK ADD CONSTRAINT [FK_FoodShelfCertification_Person] FOREIGN KEY([PersonID])
1610REFERENCES [Person].[Person] ([PersonID])
1611GO
1612ALTER TABLE [Foodshelf].[FoodShelfCertification] CHECK CONSTRAINT [FK_FoodShelfCertification_Person]
1613GO
1614ALTER TABLE [Foodshelf].[FoodTypeGiven] WITH CHECK ADD CONSTRAINT [FK_FoodTypeGiven_Person] FOREIGN KEY([PersonID])
1615REFERENCES [Person].[Person] ([PersonID])
1616GO
1617ALTER TABLE [Foodshelf].[FoodTypeGiven] CHECK CONSTRAINT [FK_FoodTypeGiven_Person]
1618GO
1619ALTER TABLE [Foodshelf].[HouseholdNotes] WITH CHECK ADD CONSTRAINT [FK_HouseholdNotes_Person] FOREIGN KEY([ClientPersonID])
1620REFERENCES [Person].[Person] ([PersonID])
1621GO
1622ALTER TABLE [Foodshelf].[HouseholdNotes] CHECK CONSTRAINT [FK_HouseholdNotes_Person]
1623GO
1624ALTER TABLE [Foodshelf].[Signature] WITH CHECK ADD CONSTRAINT [FK_Signature_FoodShelfCertification] FOREIGN KEY([FoodShelfCertificationID], [PersonID])
1625REFERENCES [Foodshelf].[FoodShelfCertification] ([FoodShelfCertificationID], [PersonID])
1626GO
1627ALTER TABLE [Foodshelf].[Signature] CHECK CONSTRAINT [FK_Signature_FoodShelfCertification]
1628GO
1629ALTER TABLE [Person].[Demographics] WITH CHECK ADD CONSTRAINT [FK_Deomographics_Person] FOREIGN KEY([PersonID])
1630REFERENCES [Person].[Person] ([PersonID])
1631GO
1632ALTER TABLE [Person].[Demographics] CHECK CONSTRAINT [FK_Deomographics_Person]
1633GO
1634ALTER TABLE [Person].[FamilyRelationships] WITH CHECK ADD CONSTRAINT [FK_FamilyRelationships_Person] FOREIGN KEY([ClientPersonID])
1635REFERENCES [Person].[Person] ([PersonID])
1636GO
1637ALTER TABLE [Person].[FamilyRelationships] CHECK CONSTRAINT [FK_FamilyRelationships_Person]
1638GO
1639ALTER TABLE [Person].[LanguagesSpoken] WITH CHECK ADD CONSTRAINT [FK_LanguagesSpoken_Person] FOREIGN KEY([PersonID])
1640REFERENCES [Person].[Person] ([PersonID])
1641GO
1642ALTER TABLE [Person].[LanguagesSpoken] CHECK CONSTRAINT [FK_LanguagesSpoken_Person]
1643GO
1644ALTER TABLE [Person].[LUCity] WITH CHECK ADD CONSTRAINT [FK_LUCity_LUCounty] FOREIGN KEY([CountyID])
1645REFERENCES [Person].[LUCounty] ([CountyID])
1646GO
1647ALTER TABLE [Person].[LUCity] CHECK CONSTRAINT [FK_LUCity_LUCounty]
1648GO
1649ALTER TABLE [Person].[LUCounty] WITH CHECK ADD CONSTRAINT [FK_LUCounty_LUState] FOREIGN KEY([StateID])
1650REFERENCES [Person].[LUState] ([StateID])
1651GO
1652ALTER TABLE [Person].[LUCounty] CHECK CONSTRAINT [FK_LUCounty_LUState]
1653GO
1654ALTER TABLE [Person].[LUPostalCode] WITH CHECK ADD CONSTRAINT [FK_LUPostalCode_LUCity] FOREIGN KEY([CityID])
1655REFERENCES [Person].[LUCity] ([CityID])
1656GO
1657ALTER TABLE [Person].[LUPostalCode] CHECK CONSTRAINT [FK_LUPostalCode_LUCity]
1658GO
1659ALTER TABLE [Person].[Notes] WITH CHECK ADD CONSTRAINT [FK_HouseholdNotes_Person] FOREIGN KEY([PersonID])
1660REFERENCES [Person].[Person] ([PersonID])
1661GO
1662ALTER TABLE [Person].[Notes] CHECK CONSTRAINT [FK_HouseholdNotes_Person]
1663GO
1664ALTER TABLE [Person].[PersonAddresses] WITH CHECK ADD CONSTRAINT [FK_PersonAddresses_Address] FOREIGN KEY([AddressID])
1665REFERENCES [Person].[Address] ([AddressID])
1666GO
1667ALTER TABLE [Person].[PersonAddresses] CHECK CONSTRAINT [FK_PersonAddresses_Address]
1668GO
1669ALTER TABLE [Person].[PersonAddresses] WITH CHECK ADD CONSTRAINT [FK_PersonAddresses_Person] FOREIGN KEY([PersonID])
1670REFERENCES [Person].[Person] ([PersonID])
1671GO
1672ALTER TABLE [Person].[PersonAddresses] CHECK CONSTRAINT [FK_PersonAddresses_Person]
1673GO
1674ALTER TABLE [Person].[Phone] WITH CHECK ADD CONSTRAINT [FK_Phone_Person] FOREIGN KEY([PersonID])
1675REFERENCES [Person].[Person] ([PersonID])
1676GO
1677ALTER TABLE [Person].[Phone] CHECK CONSTRAINT [FK_Phone_Person]
1678GO
1679ALTER TABLE [Person].[Programs] WITH CHECK ADD CONSTRAINT [FK_Programs_Person] FOREIGN KEY([PersonID])
1680REFERENCES [Person].[Person] ([PersonID])
1681GO
1682ALTER TABLE [Person].[Programs] CHECK CONSTRAINT [FK_Programs_Person]
1683GO
1684ALTER TABLE [Person].[ProgramServicesUsed] WITH CHECK ADD CONSTRAINT [FK_ProgramServicesUsed_Programs] FOREIGN KEY([PersonID], [ProgramID])
1685REFERENCES [Person].[Programs] ([PersonID], [ProgramID])
1686GO
1687ALTER TABLE [Person].[ProgramServicesUsed] CHECK CONSTRAINT [FK_ProgramServicesUsed_Programs]
1688GO
1689ALTER TABLE [Signature].[Signatures] WITH CHECK ADD CONSTRAINT [FK_Signatures_Signature1] FOREIGN KEY([SignatureID], [PersonID])
1690REFERENCES [Signature].[Signature] ([SignatureID], [PersonID])
1691GO
1692ALTER TABLE [Signature].[Signatures] CHECK CONSTRAINT [FK_Signatures_Signature1]
1693GO
1694ALTER TABLE [Volunteer].[EmContact] WITH CHECK ADD CONSTRAINT [FK_EmContact_VolunteerContactInformation] FOREIGN KEY([VolunteerPersonID])
1695REFERENCES [Volunteer].[VolunteerContactInformation] ([VolunteerPersonID])
1696GO
1697ALTER TABLE [Volunteer].[EmContact] CHECK CONSTRAINT [FK_EmContact_VolunteerContactInformation]
1698GO
1699ALTER TABLE [Volunteer].[VolunteerContactInformation] WITH CHECK ADD CONSTRAINT [FK_VolunteerContactInformation_Person] FOREIGN KEY([PersonID])
1700REFERENCES [Person].[Person] ([PersonID])
1701GO
1702ALTER TABLE [Volunteer].[VolunteerContactInformation] CHECK CONSTRAINT [FK_VolunteerContactInformation_Person]
1703GO
1704ALTER TABLE [Volunteer].[VolunteerJobs] WITH CHECK ADD CONSTRAINT [FK_VolunteerJobs_VolunteerContactInformation] FOREIGN KEY([VolunteerPersonID])
1705REFERENCES [Volunteer].[VolunteerContactInformation] ([VolunteerPersonID])
1706GO
1707ALTER TABLE [Volunteer].[VolunteerJobs] CHECK CONSTRAINT [FK_VolunteerJobs_VolunteerContactInformation]
1708GO
1709ALTER TABLE [Volunteer].[VolunteerNotes] WITH CHECK ADD CONSTRAINT [FK_VolunteerNotes_VolunteerContactInformation] FOREIGN KEY([VolunteerPersonID])
1710REFERENCES [Volunteer].[VolunteerContactInformation] ([VolunteerPersonID])
1711GO
1712ALTER TABLE [Volunteer].[VolunteerNotes] CHECK CONSTRAINT [FK_VolunteerNotes_VolunteerContactInformation]
1713GO
1714ALTER TABLE [Volunteer].[VolunteerScheduleDayTime] WITH CHECK ADD CONSTRAINT [FK_VolunteerScheduleDayTime_VolunteerContactInformation] FOREIGN KEY([VolunteerPersonID])
1715REFERENCES [Volunteer].[VolunteerContactInformation] ([VolunteerPersonID])
1716GO
1717ALTER TABLE [Volunteer].[VolunteerScheduleDayTime] CHECK CONSTRAINT [FK_VolunteerScheduleDayTime_VolunteerContactInformation]
1718GO
1719/****** Object: StoredProcedure [dbo].[GetClientRels] Script Date: 10/16/2020 7:31:03 PM ******/
1720SET ANSI_NULLS ON
1721GO
1722SET QUOTED_IDENTIFIER ON
1723GO
1724create procedure [dbo].[GetClientRels]
1725(
1726/*
1727relationship key for @RelType
172835 = head of household
172936 = Spouse
173037 = Child
173138 = Parent
173239 = Other
1733other values will show all relationships
1734*/
1735@TheClient int,
1736@RelType int null
1737)
1738
1739as
1740if @RelType between 35 and 39 --This is what executes if a CORRECT relationship code is entered
1741 begin
1742
1743 with CLIENT as
1744 (
1745 select rel.ClientPersonID, rel.RelationDescription, rel.PersonID from person.FamilyRelationships as rel
1746 where rel.ClientPersonID = @TheClient
1747 ),
1748 RELS as
1749 (
1750 select rel.PersonID, rel.RelationshipID, pers.FirstName, pers.LastName from person.FamilyRelationships as rel
1751 inner join person.person as pers on pers.PersonID = rel.PersonID
1752 where rel.RelationshipID = @RelType
1753 )
1754
1755 select RELS.FirstName, RELS.LastName, CLIENT.RelationDescription from RELS
1756 join CLIENT on CLIENT.PersonID = RELS.PersonID
1757
1758 end
1759
1760
1761else --This executes if a relationship code is not entered
1762
1763 begin
1764
1765 with CLIENT as
1766 (
1767 select rel.ClientPersonID, rel.RelationDescription, rel.PersonID from person.FamilyRelationships as rel
1768 where rel.ClientPersonID = @TheClient
1769 )
1770
1771 select person.person.FirstName, person.person.LastName, CLIENT.RelationDescription from person.Person
1772 inner join CLIENT on CLIENT.ClientPersonID = person.person.PersonID
1773 where CLIENT.ClientPersonID = @TheClient
1774 end
1775
1776GO
1777/****** Object: StoredProcedure [dbo].[pDeleteAddress] Script Date: 10/16/2020 7:31:03 PM ******/
1778SET ANSI_NULLS ON
1779GO
1780SET QUOTED_IDENTIFIER ON
1781GO
1782
1783/*************************************************************************************************
1784
1785*Author: Gary Savard
1786*Date: 8 Oct 10
1787*Table Name: Address
1788Description: Delete data from Address table.This table has the possibility of duplicate rows because
1789 persons can have more than one address. Make sure that delete haplpens based on AddressID PersonId as extra
1790 precaution
1791Revisions:
1792**************************************************************************************************/
1793
1794create PROCEDURE [dbo].[pDeleteAddress](
1795 @AddressID int,
1796 @PersonID int,
1797 @Success bit Output,
1798 @ErrorStatus Nvarchar(50) Output
1799 )
1800AS
1801SET NOCOUNT ON;
1802BEGIN
1803 DECLARE
1804 @TempAddressID int,
1805 @TempPersonID int
1806
1807
1808 SET @Success = 0;
1809 SET @ErrorStatus ='';
1810 SET @TempAddressID =0;
1811 SET @TempAddressID = 0;
1812
1813
1814
1815
1816 BEGIN TRY
1817 BEGIN TRANSACTION;
1818
1819 /****************************************************************************/
1820
1821 SELECT @TempAddressID = @AddressID
1822 FROM Person.Address
1823 WHERE
1824 AddressID = @AddressID AND PersonID = @PersonID
1825
1826 IF @TempAddressID = 0 OR @TempAddressID IS NULL
1827 BEGIN
1828 SELECT @ErrorStatus='-7015 PersonID/AddressID combo doesnt exist in Address';
1829 SET @Success =0;
1830 RAISERROR(@ErrorStatus,16,1);
1831
1832 END
1833
1834 IF @@Error <> 0
1835 BEGIN
1836 SELECT @ErrorStatus = Convert(nVarchar(50),@@ERROR) + '-7000';
1837 SET @Success = 0;
1838 RAISERROR (@ErrorStatus,16,1);
1839 END
1840
1841 DELETE FROM Person.Address WHERE AddressID = @AddressID and PersonID = @PersonID;
1842
1843
1844 set @success =1;
1845 set @ErrorStatus =0;
1846 COMMIT TRANSACTION;
1847
1848 END TRY
1849
1850 BEGIN CATCH
1851 ROLLBACK TRANSACTION;
1852 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
1853 --We only care if the error was not raised by SSE
1854 IF @@ERROR <> 50000
1855 BEGIN
1856 SET @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
1857 END
1858
1859
1860 SELECT @ErrorStatus =@ErrorStatus + ' -7001' +' Delete Failed';
1861 SET @Success =0;
1862
1863 RAISERROR(@ErrorStatus, 16, 1);
1864
1865
1866 END CATCH
1867
1868
1869END
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881GO
1882/****** Object: StoredProcedure [dbo].[pDeleteAddressType] Script Date: 10/16/2020 7:31:03 PM ******/
1883SET ANSI_NULLS ON
1884GO
1885SET QUOTED_IDENTIFIER ON
1886GO
1887
1888/*************************************************************************************************
1889
1890*Author: Gary Savard
1891*Date: 8 Oct 10
1892*Table Name: LUAddressType
1893Description: Deletes from LUAddressType
1894Revisions:
1895**************************************************************************************************/
1896CREATE PROCEDURE [dbo].[pDeleteAddressType](
1897 @AddressTypeID int,
1898 @Success bit Output,
1899 @ErrorStatus Nvarchar(50) Output
1900 )
1901AS
1902SET NOCOUNT ON;
1903
1904 DECLARE
1905 @TempAddressTypeID int
1906
1907 SET @TempAddressTypeID =0;
1908 SET @Success = 0;
1909 SET @ErrorStatus ='';
1910
1911
1912
1913 BEGIN
1914 BEGIN TRY
1915 BEGIN TRANSACTION;
1916 IF ((@AddressTypeID = 0) OR (@AddressTypeID IS NULL))
1917 BEGIN
1918 SELECT @ErrorStatus = '6015 AddressTypeID cant be 0/NULL';
1919 SET @Success = 0;
1920 RAISERROR(@ErrorStatus, 16,1);
1921 END
1922
1923
1924 SELECT @TempAddressTypeID =@AddressTypeID
1925 FROM person.LUAddressType
1926 WHERE AddressTypeID= @AddressTypeID
1927
1928
1929 IF ((@TempAddressTypeID=0) OR (@TempAddressTypeID IS NULL))
1930 BEGIN
1931 SELECT @ErrorStatus = ' -6018 AddressTypeID does not exist';
1932 SET @Success =0;
1933 RAISERROR(@ErrorStatus,16,1);
1934 END
1935
1936 IF @@Error <> 0
1937 BEGIN
1938 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6010';
1939 SET @Success = 0;
1940 RAISERROR(@ErrorStatus, 16, 1);
1941 END
1942
1943 DELETE FROM Person.LUAddressType
1944 WHERE AddressTypeID = @AddressTypeID
1945
1946 set @success =1;
1947 set @ErrorStatus =0;
1948 COMMIT TRANSACTION;
1949
1950 END TRY
1951
1952 BEGIN CATCH
1953 ROLLBACK TRANSACTION;
1954 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
1955 --We only care if the error was not raised by SSE
1956 IF @@ERROR <> 50000
1957 BEGIN
1958 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
1959 END
1960 SET @Success =0;
1961 SELECT @ErrorStatus= @ErrorStatus +'-6013 DELETE Fail AddressType';
1962 RAISERROR(@ErrorStatus, 15, 1);
1963
1964
1965 END CATCH
1966
1967 END
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980GO
1981/****** Object: StoredProcedure [dbo].[pDeleteCity] Script Date: 10/16/2020 7:31:03 PM ******/
1982SET ANSI_NULLS ON
1983GO
1984SET QUOTED_IDENTIFIER ON
1985GO
1986
1987/*************************************************************************************************
1988
1989*Author: Gary Savard
1990*Date: 8 Oct 10
1991*Table Name: LUCity
1992Description: Deletes from LUCity
1993Revisions:
1994**************************************************************************************************/
1995CREATE PROCEDURE [dbo].[pDeleteCity](
1996 @CityID int,
1997 @Success bit Output,
1998 @ErrorStatus Nvarchar(50) Output
1999 )
2000AS
2001SET NOCOUNT ON;
2002
2003 DECLARE
2004 @TempCityID int
2005
2006 SET @TempCityID =0;
2007 SET @Success = 0;
2008 SET @ErrorStatus ='';
2009
2010
2011
2012 BEGIN
2013 BEGIN TRY
2014 BEGIN TRANSACTION;
2015 IF ((@CityID = 0) OR (@CityID IS NULL))
2016 BEGIN
2017 SELECT @ErrorStatus = '60055 CityID cant be 0/NULL';
2018 SET @Success = 0;
2019 RAISERROR(@ErrorStatus, 16,1);
2020 END
2021
2022
2023 SELECT @TempCityID =@CityID
2024 FROM person.LUCity
2025 WHERE CityID= @CityID
2026
2027
2028 IF ((@TempCityID=0) OR (@TempCityID IS NULL))
2029 BEGIN
2030 SELECT @ErrorStatus = ' -60058 CityID does not exist';
2031 SET @Success =0;
2032 RAISERROR(@ErrorStatus,16,1);
2033 END
2034
2035 IF @@Error <> 0
2036 BEGIN
2037 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -60050';
2038 SET @Success = 0;
2039 RAISERROR(@ErrorStatus, 16, 1);
2040 END
2041
2042 DELETE FROM Person.LUCity
2043 WHERE CityID = @CityID
2044
2045 set @success =1;
2046 set @ErrorStatus =0;
2047 COMMIT TRANSACTION;
2048
2049 END TRY
2050
2051 BEGIN CATCH
2052 ROLLBACK TRANSACTION;
2053 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
2054 --We only care if the error was not raised by SSE
2055 IF @@ERROR <> 50000
2056 BEGIN
2057 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
2058 END
2059 SET @Success =0;
2060 SELECT @ErrorStatus= @ErrorStatus +'-60053 DELETE Fail City';
2061 RAISERROR(@ErrorStatus, 15, 1);
2062
2063
2064 END CATCH
2065
2066 END
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079GO
2080/****** Object: StoredProcedure [dbo].[pDeleteClient] Script Date: 10/16/2020 7:31:03 PM ******/
2081SET ANSI_NULLS ON
2082GO
2083SET QUOTED_IDENTIFIER ON
2084GO
2085-- =============================================
2086-- Author: <Author,,Name>
2087-- Create date: <Create Date,,>
2088-- Description: <Description,,>
2089-- =============================================
2090CREATE PROCEDURE [dbo].[pDeleteClient](
2091 @PersonID int,
2092 @Success bit Output,
2093 @ErrorStatus Nvarchar(50) Output
2094 )
2095AS
2096SET NOCOUNT ON;
2097BEGIN
2098 DECLARE
2099 @TempPersonID int
2100 SET @TempPersonID =0;
2101 BEGIN
2102 BEGIN TRY
2103 BEGIN TRANSACTION;
2104 IF (@PersonID = 0) or (@PersonID) = NULL --Must have a person id to know the person
2105 BEGIN
2106 SELECT @ErrorStatus = '-60055 PersonID cannot be 0 or null';
2107 SET @Success = 0;
2108 RAISERROR(@ErrorStatus, 16,1);
2109 END
2110
2111/****************************************************************************/
2112 --Check to see if the person exists
2113 SELECT @TempPersonID = PersonID
2114 FROM person.person
2115 WHERE PersonID = @PersonID
2116
2117 If (@TempPersonID = NULL) OR (@TempPersonID= 0)
2118 BEGIN
2119 SET @ErrorStatus = ' -60052 PersonID Doesnt Exist in Person table.';
2120 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
2121
2122 END
2123
2124/****************************************************************************/
2125
2126 IF @@Error <> 0
2127 BEGIN
2128 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60050';
2129 SET @Success = 0;
2130 RAISERROR(@ErrorStatus, 16,1);
2131 END
2132
2133 --StateID is not updated because that should not change!
2134 UPDATE Person.Person
2135 SET IsDeleted = 1
2136 WHERE
2137 PersonID = @PersonID;
2138
2139 set @success =1;
2140 set @ErrorStatus =0;
2141 COMMIT TRANSACTION;
2142
2143 END TRY
2144
2145 BEGIN CATCH
2146 ROLLBACK TRANSACTION;
2147 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
2148 --We only care if the error was not raised by SSE
2149 IF @@ERROR <> 50000
2150 BEGIN
2151 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
2152 END
2153
2154 SET @Success =0;
2155 SELECT @ErrorStatus= @ErrorStatus +'-60051 Delete Failed on Person ';
2156 RAISERROR(@ErrorStatus, 16, 1);
2157
2158
2159 END CATCH
2160
2161 END
2162END
2163
2164GO
2165/****** Object: StoredProcedure [dbo].[pDeleteContactType] Script Date: 10/16/2020 7:31:03 PM ******/
2166SET ANSI_NULLS ON
2167GO
2168SET QUOTED_IDENTIFIER ON
2169GO
2170
2171/*************************************************************************************************
2172
2173*Author: Gary Savard
2174*Date: 8 Oct 10
2175*Table Name: LUContactType
2176Description: Deletes from LUContactType
2177Revisions:
2178**************************************************************************************************/
2179CREATE PROCEDURE [dbo].[pDeleteContactType](
2180 @ContactTypeID int,
2181 @Success bit Output,
2182 @ErrorStatus Nvarchar(50) Output
2183 )
2184AS
2185SET NOCOUNT ON;
2186
2187 DECLARE
2188 @TempContactTypeID int
2189
2190 SET @TempContactTypeID =0;
2191 SET @Success = 0;
2192 SET @ErrorStatus ='';
2193
2194
2195
2196 BEGIN
2197 BEGIN TRY
2198 BEGIN TRANSACTION;
2199 IF ((@ContactTypeID = 0) OR (@ContactTypeID IS NULL))
2200 BEGIN
2201 SELECT @ErrorStatus = '60025 ContactTypeID cant be 0/NULL';
2202 SET @Success = 0;
2203 RAISERROR(@ErrorStatus, 16,1);
2204 END
2205
2206
2207 SELECT @TempContactTypeID =ContactTypeID
2208 FROM person.LUContactType
2209 WHERE ContactTypeID= @ContactTypeID
2210
2211
2212 IF ((@TempContactTypeID=0) OR (@TempContactTypeID IS NULL))
2213 BEGIN
2214 SELECT @ErrorStatus = ' -60028 ContactTypeID does not exist';
2215 SET @Success =0;
2216 RAISERROR(@ErrorStatus,16,1);
2217 END
2218
2219 IF @@Error <> 0
2220 BEGIN
2221 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -60020';
2222 SET @Success = 0;
2223 RAISERROR(@ErrorStatus, 16, 1);
2224 END
2225
2226 DELETE FROM Person.LUContactType
2227 WHERE ContactTypeID = @ContactTypeID
2228
2229 set @success =1;
2230 set @ErrorStatus =0;
2231 COMMIT TRANSACTION;
2232
2233 END TRY
2234
2235 BEGIN CATCH
2236 ROLLBACK TRANSACTION;
2237 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
2238 --We only care if the error was not raised by SSE
2239 IF @@ERROR <> 50000
2240 BEGIN
2241 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
2242 END
2243 SET @Success =0;
2244 SELECT @ErrorStatus= @ErrorStatus +'-60023 DELETE Fail ContactType';
2245 RAISERROR(@ErrorStatus, 15, 1);
2246
2247
2248 END CATCH
2249
2250 END
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263GO
2264/****** Object: StoredProcedure [dbo].[pDeleteDemographics] Script Date: 10/16/2020 7:31:03 PM ******/
2265SET ANSI_NULLS ON
2266GO
2267SET QUOTED_IDENTIFIER ON
2268GO
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279/*************************************************************************************************
2280
2281*Author: Gary Savard
2282*Date: 8 Oct 10
2283*Table Name: Demographics
2284Description: Deletes from Demographics
2285Revisions:
2286**************************************************************************************************/
2287CREATE PROCEDURE [dbo].[pDeleteDemographics](
2288 @DemographicsID int,
2289 @PersonID int,
2290 @ModifiedBy Name,
2291 @Success bit Output,
2292 @ErrorStatus Nvarchar(50) Output
2293 )
2294AS
2295SET NOCOUNT ON;
2296
2297 DECLARE
2298 @TempDemographicsID int,
2299 @TempPersonID int
2300
2301 SET @TempPersonID =0;
2302 SET @Success = 0;
2303 SET @ErrorStatus ='';
2304 SET @TempDemographicsID =0;
2305
2306
2307
2308
2309 BEGIN
2310 BEGIN TRY
2311 BEGIN TRANSACTION;
2312 IF ((@DemographicsID = 0) OR (@DemographicsID IS NULL)) OR ((@PersonID = 0) OR (@PersonID IS NULL))
2313 BEGIN
2314 SELECT @ErrorStatus = '2005 DemographicsID/PersonID cant be 0/NULL';
2315 SET @Success = 0;
2316 RAISERROR(@ErrorStatus, 16,1);
2317 END
2318
2319 --Check to see that the IDs match.. paranoid? NO! Have had worse things happen....Data integrity can fail!
2320 --Could use count but that has some optimization and indexing problems....
2321 SELECT @TempPersonID = PersonID, @TempDemographicsID = DemographicsID
2322 FROM person.Demographics
2323 WHERE PersonID = @PersonID AND DemographicsID = @DemographicsID
2324
2325
2326 IF ((@TempDemographicsID=0) OR (@TempDemographicsID IS NULL))OR ((@TempPersonID =0) OR (@TempPersonID IS NULL))
2327 BEGIN
2328 SELECT @ErrorStatus = ' -2008 DemographicsID/PersonID combo does not exist';
2329 SET @Success =0;
2330 RAISERROR(@ErrorStatus,16,1);
2331 END
2332
2333 IF @@Error <> 0
2334 BEGIN
2335 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -2000';
2336 SET @Success = 0;
2337 RAISERROR(@ErrorStatus, 16, 1);
2338 END
2339
2340 DELETE FROM Person.Demographics
2341 WHERE DemographicsID = @DemographicsID AND PersonID = @PersonID
2342
2343 set @success =1;
2344 set @ErrorStatus =0;
2345 COMMIT TRANSACTION;
2346
2347 END TRY
2348
2349 BEGIN CATCH
2350 ROLLBACK TRANSACTION;
2351 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
2352 --We only care if the error was not raised by SSE
2353 IF @@ERROR <> 50000
2354 BEGIN
2355 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
2356 END
2357 SET @Success =0;
2358 SELECT @ErrorStatus= @ErrorStatus +'-2001 DELETE Fail Demographics';
2359 RAISERROR(@ErrorStatus, 15, 1);
2360
2361
2362 END CATCH
2363
2364 END
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377GO
2378/****** Object: StoredProcedure [dbo].[pDeleteEducationCategory] Script Date: 10/16/2020 7:31:03 PM ******/
2379SET ANSI_NULLS ON
2380GO
2381SET QUOTED_IDENTIFIER ON
2382GO
2383
2384
2385
2386
2387/*************************************************************************************************
2388
2389*Author: Gary Savard
2390*Date: 8 Oct 10
2391*Table Name: LUEducationCategory
2392Description: Deletes from LUEducationCategory
2393Revisions:
2394**************************************************************************************************/
2395CREATE PROCEDURE [dbo].[pDeleteEducationCategory](
2396 @EducationCategoryID int,
2397 @Success bit Output,
2398 @ErrorStatus Nvarchar(50) Output
2399 )
2400AS
2401SET NOCOUNT ON;
2402
2403 DECLARE
2404 @TempEducationCategoryID int
2405
2406
2407 SET @TempEducationCategoryID =0;
2408 SET @Success = 0;
2409 SET @ErrorStatus ='';
2410
2411
2412
2413 BEGIN
2414 BEGIN TRY
2415 BEGIN TRANSACTION;
2416 IF ((@EducationCategoryID = 0) OR (@EducationCategoryID IS NULL))
2417 BEGIN
2418 SELECT @ErrorStatus = '60065 EducationCategoryID cant be 0/NULL';
2419 SET @Success = 0;
2420 RAISERROR(@ErrorStatus, 16,1);
2421 END
2422
2423
2424 SELECT @TempEducationCategoryID = EducationCategoryID
2425 FROM person.LUEducationCategory
2426 WHERE EducationCategoryID = @TempEducationCategoryID
2427
2428
2429 IF ((@TempEducationCategoryID=0) OR (@TempEducationCategoryID IS NULL))
2430 BEGIN
2431 SELECT @ErrorStatus = ' -60078 EducationCategoryID does not exist';
2432 SET @Success =0;
2433 RAISERROR(@ErrorStatus,16,1);
2434 END
2435
2436 IF @@Error <> 0
2437 BEGIN
2438 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -2000';
2439 SET @Success = 0;
2440 RAISERROR(@ErrorStatus, 16, 1);
2441 END
2442
2443 DELETE FROM Person.LUEducationCategory
2444 WHERE EducationCategoryID = @EducationCategoryID
2445
2446 set @success =1;
2447 set @ErrorStatus =0;
2448 COMMIT TRANSACTION;
2449
2450 END TRY
2451
2452 BEGIN CATCH
2453 ROLLBACK TRANSACTION;
2454 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
2455 --We only care if the error was not raised by SSE
2456 IF @@ERROR <> 50000
2457 BEGIN
2458 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
2459 END
2460 SET @Success =0;
2461 SELECT @ErrorStatus= @ErrorStatus +'-60073 DELETE Fail EducationCategory';
2462 RAISERROR(@ErrorStatus, 15, 1);
2463
2464
2465 END CATCH
2466
2467 END
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480GO
2481/****** Object: StoredProcedure [dbo].[pDeleteEthnicity] Script Date: 10/16/2020 7:31:03 PM ******/
2482SET ANSI_NULLS ON
2483GO
2484SET QUOTED_IDENTIFIER ON
2485GO
2486
2487
2488
2489
2490/*************************************************************************************************
2491
2492*Author: Gary Savard
2493*Date: 8 Oct 10
2494*Table Name: LUEthnicity
2495Description: Deletes from LUEthicity
2496Revisions:
2497**************************************************************************************************/
2498CREATE PROCEDURE [dbo].[pDeleteEthnicity](
2499 @EthnicityID int,
2500 @Success bit Output,
2501 @ErrorStatus Nvarchar(50) Output
2502 )
2503AS
2504SET NOCOUNT ON;
2505
2506 DECLARE
2507 @TempEthnicityID int
2508
2509 SET @TempEthnicityID =0;
2510 SET @Success = 0;
2511 SET @ErrorStatus ='';
2512
2513
2514
2515 BEGIN
2516 BEGIN TRY
2517 BEGIN TRANSACTION;
2518 IF ((@EthnicityID = 0) OR (@EthnicityID IS NULL))
2519 BEGIN
2520 SELECT @ErrorStatus = '60085 EthnicityID cant be 0/NULL';
2521 SET @Success = 0;
2522 RAISERROR(@ErrorStatus, 16,1);
2523 END
2524
2525
2526 SELECT @TempEthnicityID =EthnicityID
2527 FROM person.LUEthnicity
2528 WHERE EthnicityID = @TempEthnicityID
2529
2530
2531 IF ((@TempEthnicityID=0) OR (@TempEthnicityID IS NULL))
2532 BEGIN
2533 SELECT @ErrorStatus = ' -60088 EthnicityID does not exist';
2534 SET @Success =0;
2535 RAISERROR(@ErrorStatus,16,1);
2536 END
2537
2538 IF @@Error <> 0
2539 BEGIN
2540 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -2000';
2541 SET @Success = 0;
2542 RAISERROR(@ErrorStatus, 16, 1);
2543 END
2544
2545 DELETE FROM Person.LUEthnicity
2546 WHERE EthnicityID = @EthnicityID
2547
2548 set @success =1;
2549 set @ErrorStatus =0;
2550 COMMIT TRANSACTION;
2551
2552 END TRY
2553
2554 BEGIN CATCH
2555 ROLLBACK TRANSACTION;
2556 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
2557 --We only care if the error was not raised by SSE
2558 IF @@ERROR <> 50000
2559 BEGIN
2560 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
2561 END
2562 SET @Success =0;
2563 SELECT @ErrorStatus= @ErrorStatus +'-60083 DELETE Fail Ethnicity';
2564 RAISERROR(@ErrorStatus, 15, 1);
2565
2566
2567 END CATCH
2568
2569 END
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582GO
2583/****** Object: StoredProcedure [dbo].[pDeleteFamilyMember] Script Date: 10/16/2020 7:31:03 PM ******/
2584SET ANSI_NULLS ON
2585GO
2586SET QUOTED_IDENTIFIER ON
2587GO
2588
2589
2590
2591
2592/*************************************************************************************************
2593*
2594*Author: Gary Savard
2595*Date: 15 April 2011
2596*
2597Description: This SP covers the instances where a family member is deleted from a household. It assumes that if the
2598person is the head of the old household, that another person has been promoted to head of that household already. It will also delete
2599an entire household, if requested.
2600
2601REV: 25 July 11. Commented out delete entire household per Carol Paul's request
2602
2603THIS SP IS NOT BEING USED !!! MAY RETURN IN THE FUTURE!
2604**************************************************************************************************/
2605CREATE PROCEDURE [dbo].[pDeleteFamilyMember](
2606 @DeletePersonID int,--The person/Household,
2607 @HeadofHouseholdPersonID int, --Might be the same as @DeletePersonID if it is the head of household!
2608 --@NewHeadOfHouseholdPersonID int, --Only filled if the person to be deleted is currently the head of household
2609 --@IsHouseholdDelete bit,--This set to 1 will delete the entire household
2610 @ModifiedBy Name,
2611 @Success bit Output,
2612 @ErrorStatus Nvarchar(50) Output
2613 )
2614AS
2615SET NOCOUNT ON;
2616
2617-- DECLARE
2618-- @ErrNo INT,
2619-- @LogMsg NVarchar(50),
2620-- @journalSuccess BIT,
2621-- @JournalErrorStatus NVarchar(50)
2622
2623
2624-- SET @Success = 0;
2625-- SET @ErrorStatus ='';
2626-- SET @ErrNo =0;
2627-- SET @LogMsg ='Deleted from household. IsHouseholdDelete: '+ CONVERT(NVarchar(50),@ISHouseholdDelete)
2628
2629
2630
2631--BEGIN TRY
2632 -- BEGIN TRANSACTION;
2633 ----Place a record in the Journal Table with the appropriate information before making the change.
2634 ----Update the Relationship table with the new household's client ID and the new relationship
2635 ----Make update to demographics table for new family status.
2636
2637 -- EXEC dbo.pInsertJournalClientFamilyChanges @DeletePersonID,
2638 -- @HeadofHouseholdPersonID,
2639 -- @NewHeadOfHouseholdPersonID,
2640 -- @LogMsg,
2641 -- '',--Notes Field blank for now
2642 -- @ModifiedBy,
2643 -- @JournalSuccess,--we don't care about the return values of this and error status for time being
2644 -- @JournalErrorStatus
2645
2646
2647
2648
2649 --IF @IsHouseholdDelete =1
2650 ----cursors are evil so we will use a temp table. This assum that the family as a whole is to be deleted.
2651 -- BEGIN
2652 -- --We need to retrieve the entire family from the FamilyRelationships table. Using temp table because
2653 -- --cursors are not very efficient. Do this to isolate this family's records from the main tables to help avoid
2654 -- --problems with batch updates in main system
2655
2656 -- DECLARE
2657 -- @RowCount int,
2658 -- @NumberRecs int,
2659 -- @tmpPersonID int,
2660 -- @tmpClientPersonID int
2661
2662 -- SET @tmpClientPersonID = @HeadOfHouseholdPersonID
2663
2664
2665 -- SET @RowCount =1
2666
2667 -- CREATE TABLE #tempfamily
2668 -- (RowID int identity(1,1), PersID int)
2669
2670 -- INSERT #tempfamily
2671
2672 -- SELECT PersonID
2673 -- FROM Person.FamilyRelationships
2674 -- WHERE ClientPersonID=@HeadOfHouseholdPersonID
2675
2676 -- SET @NumberRecs = @@ROWCOUNT --How many did we insert into #tempFamily
2677
2678 -- WHILE @RowCount <=@NumberRecs
2679 -- BEGIN
2680 -- SELECT @tmpPersonID =PersID
2681 -- FROM #tempfamily
2682 -- WHERE RowID =@Rowcount
2683
2684 -- UPDATE Person.Person
2685 -- SET IsDeleted =1
2686 -- WHERE PersonID =@TmpPersonID
2687
2688 -- SELECT @ErrNo =@@ERROR
2689
2690 -- SET @RowCount = @RowCount + 1
2691
2692 -- END --End While
2693
2694 --IF @ErrNo<>0
2695 -- BEGIN
2696 -- SET @ErrorStatus ='Failed on Delete Family Member PersonID: ' + CONVERT(NVarchar(50),@TmpPersonID)
2697 -- RAISERROR(@ErrorStatus,16,0)
2698
2699 -- END--IF@ErrNO
2700
2701
2702
2703 -- --Finally, delete the client
2704 -- UPDATE person.Person
2705 -- SET IsDeleted =1
2706 -- WHERE PersonID =@HeadOfHouseholdPersonID
2707 -- SELECT @ErrNo =@@ERROR
2708
2709 --IF @ErrNo<>0
2710 -- BEGIN
2711 -- SET @ErrorStatus ='Failed on Delete PersonID: ' + CONVERT(NVarchar(50),@HeadOfHouseholdPersonID)
2712 -- RAISERROR(@ErrorStatus,16,0)
2713
2714 -- END--@Errno
2715
2716
2717 --DROP TABLE #tempfamily
2718
2719 --END
2720
2721 ----ELSE IF @IsHouseholdDelete =0
2722 -- BEGIN
2723 -- --Delete the client
2724 -- UPDATE Person.Person
2725 -- SET IsDeleted =1
2726 -- WHERE PersonID =@HeadOfHouseholdPersonID
2727
2728 -- SELECT @ErrNo =@@ERROR
2729
2730 -- IF @ErrNo<>0
2731 -- BEGIN
2732 -- SET @ErrorStatus ='Failed on Client Delete'
2733 -- RAISERROR(@ErrorStatus,16,0)
2734
2735 -- END--@errNO=...
2736 --END--Else IF
2737
2738
2739
2740 /******************************************************************************************************
2741
2742
2743
2744 --*******************************************************************************************************/
2745 -- COMMIT TRANSACTION;
2746
2747 -- END TRY
2748
2749 -- BEGIN CATCH
2750 -- ROLLBACK TRANSACTION;
2751 -- --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
2752 -- --We only care if the error was not raised by SSE
2753 -- IF @@ERROR <> 50000
2754 -- BEGIN
2755 -- SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @ErrNo);
2756 -- END
2757 -- SET @Success =0;
2758 -- SET @ErrorStatus= @ErrorStatus + '-1001';
2759 -- RAISERROR(@ErrorStatus, 15, 1);
2760
2761
2762 -- END CATCH
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780GO
2781/****** Object: StoredProcedure [dbo].[pDeleteFamilyStatusType] Script Date: 10/16/2020 7:31:03 PM ******/
2782SET ANSI_NULLS ON
2783GO
2784SET QUOTED_IDENTIFIER ON
2785GO
2786
2787
2788
2789/*************************************************************************************************
2790
2791*Author: Gary Savard
2792*Date: 14 March 11
2793*Table Name: LUFamilyStatusType
2794Description: Deletes from LUFamilyStatusType
2795Revisions:
2796**************************************************************************************************/
2797CREATE PROCEDURE [dbo].[pDeleteFamilyStatusType](
2798 @FamilyStatusTypeID int,
2799 @Success bit Output,
2800 @ErrorStatus Nvarchar(50) Output
2801 )
2802AS
2803SET NOCOUNT ON;
2804
2805 DECLARE
2806 @TempFamilyStatusTypeID int
2807
2808 SET @FamilyStatusTypeID =0;
2809 SET @Success = 0;
2810 SET @ErrorStatus ='';
2811
2812
2813
2814 BEGIN
2815 BEGIN TRY
2816 BEGIN TRANSACTION;
2817 IF ((@FamilyStatusTypeID = 0) OR (@FamilyStatusTypeID IS NULL))
2818 BEGIN
2819 SELECT @ErrorStatus = '600015 FamilyStatusTypeID cant be 0/NULL';
2820 SET @Success = 0;
2821 RAISERROR(@ErrorStatus, 16,1);
2822 END
2823
2824
2825 SELECT @FamilyStatusTypeID =FamilySTatusTypeID
2826 FROM person.LUFamilyStatusType
2827 WHERE FamilyStatusTypeID = @FamilyStatusTypeID
2828
2829
2830 IF ((@TempFamilyStatusTypeID=0) OR (@TempFamilyStatusTypeID IS NULL))
2831 BEGIN
2832 SELECT @ErrorStatus = ' -600018 FamilySTatusTypeID does not exist';
2833 SET @Success =0;
2834 RAISERROR(@ErrorStatus,16,1);
2835 END
2836
2837 IF @@Error <> 0
2838 BEGIN
2839 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -600010';
2840 SET @Success = 0;
2841 RAISERROR(@ErrorStatus, 16, 1);
2842 END
2843
2844 DELETE FROM Person.LUFamilyStatusType
2845 WHERE FamilyStatusTypeID = @FamilyStatusTypeID
2846
2847 set @success =1;
2848 set @ErrorStatus =0;
2849 COMMIT TRANSACTION;
2850
2851 END TRY
2852
2853 BEGIN CATCH
2854 ROLLBACK TRANSACTION;
2855 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
2856 --We only care if the error was not raised by SSE
2857 IF @@ERROR <> 50000
2858 BEGIN
2859 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
2860 END
2861 SET @Success =0;
2862 SELECT @ErrorStatus= @ErrorStatus +'-600013 DELETE Fail LuFamilyStatusType';
2863 RAISERROR(@ErrorStatus, 15, 1);
2864
2865
2866 END CATCH
2867
2868 END
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883GO
2884/****** Object: StoredProcedure [dbo].[pDeleteFoodTypeGiven] Script Date: 10/16/2020 7:31:03 PM ******/
2885SET ANSI_NULLS ON
2886GO
2887SET QUOTED_IDENTIFIER ON
2888GO
2889
2890/*************************************************************************************************
2891
2892*Author: Gary Savard
2893*Date: 8 Oct 10
2894*Table Name: FoodTypeGiven
2895Description: Deletes from FoodTypeGiven. A person may have 1 to may records here. Deletes only one based
2896on input ID.
2897Revisions:
2898**************************************************************************************************/
2899CREATE PROCEDURE [dbo].[pDeleteFoodTypeGiven](
2900 @PersonID int,
2901 @FoodTypeGivenID int, --This is the key.
2902 @Success bit Output,
2903 @ErrorStatus Nvarchar(50) Output
2904 )
2905AS
2906SET NOCOUNT ON;
2907
2908 DECLARE
2909 @TempFoodTypeGivenID int
2910
2911 SET @TempFoodTypeGivenID =0;
2912 SET @Success = 0;
2913 SET @ErrorStatus ='';
2914
2915
2916
2917 BEGIN
2918 BEGIN TRY
2919 BEGIN TRANSACTION;
2920 IF ((@FoodTypeGivenID = 0) OR (@FoodTypeGivenID IS NULL))
2921 BEGIN
2922 SELECT @ErrorStatus = '600005 FoodTypeGiven cant be 0/NULL';
2923 SET @Success = 0;
2924 RAISERROR(@ErrorStatus, 16,1);
2925 END
2926
2927 IF ((@PersonID = 0) OR (@PersonID IS NULL))
2928 BEGIN
2929 SELECT @ErrorStatus = '6000006 PersonID cant be 0/NULL';
2930 SET @Success = 0;
2931 RAISERROR(@ErrorStatus, 16,1);
2932 END
2933
2934 --This just avoids deleting a FoodTypeGivenID if it is associated with a different PersonID
2935 SELECT @TempFoodTypeGivenID = FoodTypeGivenID
2936 FROM Foodshelf.FoodTypeGiven
2937 WHERE PersonID= @PersonID AND FoodTypeGivenID = @FoodTypeGivenID
2938
2939
2940 IF ((@TempFoodTypeGivenID=0) OR (@TempFoodTypeGivenID IS NULL))
2941 BEGIN
2942 SELECT @ErrorStatus = ' -600008 FoodTypeGivenID does not exist';
2943 SET @Success =0;
2944 RAISERROR(@ErrorStatus,16,1);
2945 END
2946
2947 IF @@Error <> 0
2948 BEGIN
2949 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -600010';
2950 SET @Success = 0;
2951 RAISERROR(@ErrorStatus, 16, 1);
2952 END
2953
2954 DELETE FROM Foodshelf.FoodTypeGiven
2955 WHERE FoodTypeGivenID = @FoodTypeGivenID AND PersonID = @PersonID
2956
2957 set @success =1;
2958 set @ErrorStatus =0;
2959 COMMIT TRANSACTION;
2960
2961 END TRY
2962
2963 BEGIN CATCH
2964 ROLLBACK TRANSACTION;
2965 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
2966 --We only care if the error was not raised by SSE
2967 IF @@ERROR <> 50000
2968 BEGIN
2969 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
2970 END
2971 SET @Success =0;
2972 SELECT @ErrorStatus= @ErrorStatus +'-600013 DELETE Fail FoodTypeGiven';
2973 RAISERROR(@ErrorStatus, 15, 1);
2974
2975
2976 END CATCH
2977
2978 END
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991GO
2992/****** Object: StoredProcedure [dbo].[pDeleteHouseholdTransferOptions] Script Date: 10/16/2020 7:31:03 PM ******/
2993SET ANSI_NULLS ON
2994GO
2995SET QUOTED_IDENTIFIER ON
2996GO
2997
2998
2999/*************************************************************************************************
3000
3001*Author: Gary Savard
3002*Date: 22 April 11
3003*Table Name: HouseholdTransferOptions
3004Description: Deletes from HouseholdTransferOptions. Since the fields are free format in this table,
3005we only take in the ID for deletion
3006Revisions:
3007**************************************************************************************************/
3008CREATE PROCEDURE [dbo].[pDeleteHouseholdTransferOptions](
3009 @ActionToTakeID int,
3010 @Success bit Output,
3011 @ErrorStatus Nvarchar(50) Output
3012 )
3013AS
3014SET NOCOUNT ON;
3015
3016 DECLARE
3017 @TempActionToTakeID int
3018
3019 SET @TempActionToTakeID =0;
3020 SET @Success = 0;
3021 SET @ErrorStatus ='';
3022
3023
3024
3025 BEGIN
3026 BEGIN TRY
3027 BEGIN TRANSACTION;
3028 IF ((@ActionToTakeID = 0) OR (@ActionToTakeID IS NULL))
3029 BEGIN
3030 SELECT @ErrorStatus = '6015 ActionToTakeID cant be 0/NULL';
3031 SET @Success = 0;
3032 RAISERROR(@ErrorStatus, 16,1);
3033 END
3034
3035
3036 SELECT @TempActionToTakeID =@ActionToTakeID
3037 FROM dbo.LUHouseholdTransferOptions
3038 WHERE HouseholdTransferActionID= @ActionToTakeID
3039
3040
3041 IF ((@TempActionToTakeID=0) OR (@TempActionToTakeID IS NULL))
3042 BEGIN
3043 SELECT @ErrorStatus = ' -6018 ActionToTakeID does not exist';
3044 SET @Success =0;
3045 RAISERROR(@ErrorStatus,16,1);
3046 END
3047
3048 IF @@Error <> 0
3049 BEGIN
3050 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6010';
3051 SET @Success = 0;
3052 RAISERROR(@ErrorStatus, 16, 1);
3053 END
3054
3055 DELETE FROM dbo.LUHouseholdTransferOptions
3056 WHERE HouseholdTransferActionID = @TempActionToTakeID
3057
3058 set @success =1;
3059 set @ErrorStatus =0;
3060 COMMIT TRANSACTION;
3061
3062 END TRY
3063
3064 BEGIN CATCH
3065 ROLLBACK TRANSACTION;
3066 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
3067 --We only care if the error was not raised by SSE
3068 IF @@ERROR <> 50000
3069 BEGIN
3070 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
3071 END
3072 SET @Success =0;
3073 SELECT @ErrorStatus= @ErrorStatus +'-6013 DELETE Fail LUHouseholdTransferOptions';
3074 RAISERROR(@ErrorStatus, 15, 1);
3075
3076
3077 END CATCH
3078
3079 END
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093GO
3094/****** Object: StoredProcedure [dbo].[pDeleteHousingStatus] Script Date: 10/16/2020 7:31:03 PM ******/
3095SET ANSI_NULLS ON
3096GO
3097SET QUOTED_IDENTIFIER ON
3098GO
3099
3100/*************************************************************************************************
3101
3102*Author: Gary Savard
3103*Date: 8 Oct 10
3104*Table Name: LUHousingStatus
3105Description: Deletes from LUHousingStatus
3106Revisions:
3107**************************************************************************************************/
3108CREATE PROCEDURE [dbo].[pDeleteHousingStatus](
3109 @HousingStatusID int,
3110 @Success bit Output,
3111 @ErrorStatus Nvarchar(50) Output
3112 )
3113AS
3114SET NOCOUNT ON;
3115
3116 DECLARE
3117 @TempHousingStatusID int
3118
3119 SET @TempHousingStatusID =0;
3120 SET @Success = 0;
3121 SET @ErrorStatus ='';
3122
3123
3124
3125 BEGIN
3126 BEGIN TRY
3127 BEGIN TRANSACTION;
3128 IF ((@HousingStatusID = 0) OR (@HousingStatusID IS NULL))
3129 BEGIN
3130 SELECT @ErrorStatus = '60085 HousingStatusID cant be 0/NULL';
3131 SET @Success = 0;
3132 RAISERROR(@ErrorStatus, 16,1);
3133 END
3134
3135
3136 SELECT @TempHousingStatusID =HousingStatusID
3137 FROM person.LUHousingStatus
3138 WHERE HousingStatusID= @HousingStatusID
3139
3140
3141 IF ((@TempHousingStatusID=0) OR (@TempHousingStatusID IS NULL))
3142 BEGIN
3143 SELECT @ErrorStatus = ' -60088 HousingStatusID does not exist';
3144 SET @Success =0;
3145 RAISERROR(@ErrorStatus,16,1);
3146 END
3147
3148 IF @@Error <> 0
3149 BEGIN
3150 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -60080';
3151 SET @Success = 0;
3152 RAISERROR(@ErrorStatus, 16, 1);
3153 END
3154
3155 DELETE FROM Person.LUHousingStatus
3156 WHERE HousingStatusID = @HousingStatusID
3157
3158 set @success =1;
3159 set @ErrorStatus =0;
3160 COMMIT TRANSACTION;
3161
3162 END TRY
3163
3164 BEGIN CATCH
3165 ROLLBACK TRANSACTION;
3166 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
3167 --We only care if the error was not raised by SSE
3168 IF @@ERROR <> 50000
3169 BEGIN
3170 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
3171 END
3172 SET @Success =0;
3173 SELECT @ErrorStatus= @ErrorStatus +'-60083 DELETE Fail HousingStatus';
3174 RAISERROR(@ErrorStatus, 15, 1);
3175
3176
3177 END CATCH
3178
3179 END
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192GO
3193/****** Object: StoredProcedure [dbo].[pDeleteIncomeSource] Script Date: 10/16/2020 7:31:03 PM ******/
3194SET ANSI_NULLS ON
3195GO
3196SET QUOTED_IDENTIFIER ON
3197GO
3198
3199
3200
3201
3202/*************************************************************************************************
3203
3204*Author: Gary Savard
3205*Date: 8 Oct 10
3206*Table Name: LUIncomeSource
3207Description: Deletes from LUIncomeSource
3208Revisions:
3209**************************************************************************************************/
3210CREATE PROCEDURE [dbo].[pDeleteIncomeSource](
3211 @IncomeSourceID int,
3212 @Success bit Output,
3213 @ErrorStatus Nvarchar(50) Output
3214 )
3215AS
3216SET NOCOUNT ON;
3217
3218 DECLARE
3219 @TempIncomeSourceID int
3220
3221 SET @TempIncomeSourceID =0;
3222 SET @Success = 0;
3223 SET @ErrorStatus ='';
3224
3225
3226
3227 BEGIN
3228 BEGIN TRY
3229 BEGIN TRANSACTION;
3230 IF ((@IncomeSourceID = 0) OR (@IncomeSourceID IS NULL))
3231 BEGIN
3232 SELECT @ErrorStatus = '60095 IncomeSourceID cant be 0/NULL';
3233 SET @Success = 0;
3234 RAISERROR(@ErrorStatus, 16,1);
3235 END
3236
3237
3238 SELECT @TempIncomeSourceID = IncomeSourceID
3239 FROM person.LUIncomeSource
3240 WHERE IncomeSourceID = @IncomeSourceID
3241
3242
3243 IF ((@TempIncomeSourceID=0) OR (@TempIncomeSourceID IS NULL))
3244 BEGIN
3245 SELECT @ErrorStatus = ' -60098 IncomeSourceID does not exist';
3246 SET @Success =0;
3247 RAISERROR(@ErrorStatus,16,1);
3248 END
3249
3250 IF @@Error <> 0
3251 BEGIN
3252 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -2000';
3253 SET @Success = 0;
3254 RAISERROR(@ErrorStatus, 16, 1);
3255 END
3256
3257 DELETE FROM Person.LUIncomeSource
3258 WHERE IncomeSourceID = @IncomeSourceID
3259
3260 set @success =1;
3261 set @ErrorStatus =0;
3262 COMMIT TRANSACTION;
3263
3264 END TRY
3265
3266 BEGIN CATCH
3267 ROLLBACK TRANSACTION;
3268 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
3269 --We only care if the error was not raised by SSE
3270 IF @@ERROR <> 50000
3271 BEGIN
3272 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
3273 END
3274 SET @Success =0;
3275 SELECT @ErrorStatus= @ErrorStatus +'-60093 DELETE Fail IncomeSource';
3276 RAISERROR(@ErrorStatus, 15, 1);
3277
3278
3279 END CATCH
3280
3281 END
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294GO
3295/****** Object: StoredProcedure [dbo].[pDeleteInsuranceType] Script Date: 10/16/2020 7:31:03 PM ******/
3296SET ANSI_NULLS ON
3297GO
3298SET QUOTED_IDENTIFIER ON
3299GO
3300
3301
3302/*************************************************************************************************
3303
3304*Author: Gary Savard
3305*Date: 14 March 11
3306*Table Name: LUInsuranceType
3307Description: Deletes from LUInsuranceType
3308Revisions:
3309**************************************************************************************************/
3310CREATE PROCEDURE [dbo].[pDeleteInsuranceType](
3311 @InsuranceTypeID int,
3312 @Success bit Output,
3313 @ErrorStatus Nvarchar(50) Output
3314 )
3315AS
3316SET NOCOUNT ON;
3317
3318 DECLARE
3319 @TempInsuranceTypeID int
3320
3321 SET @InsuranceTypeID =0;
3322 SET @Success = 0;
3323 SET @ErrorStatus ='';
3324
3325
3326
3327 BEGIN
3328 BEGIN TRY
3329 BEGIN TRANSACTION;
3330 IF ((@InsuranceTypeID = 0) OR (@InsuranceTypeID IS NULL))
3331 BEGIN
3332 SELECT @ErrorStatus = '600015 InsuranceTypeID cant be 0/NULL';
3333 SET @Success = 0;
3334 RAISERROR(@ErrorStatus, 16,1);
3335 END
3336
3337
3338 SELECT @InsuranceTypeID =InsuranceTypeID
3339 FROM person.LUInsuranceType
3340 WHERE InsuranceTypeID = @InsuranceTypeID
3341
3342
3343 IF ((@TempInsuranceTypeID=0) OR (@TempInsuranceTypeID IS NULL))
3344 BEGIN
3345 SELECT @ErrorStatus = ' -600018 InsuranceTypeID does not exist';
3346 SET @Success =0;
3347 RAISERROR(@ErrorStatus,16,1);
3348 END
3349
3350 IF @@Error <> 0
3351 BEGIN
3352 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -600010';
3353 SET @Success = 0;
3354 RAISERROR(@ErrorStatus, 16, 1);
3355 END
3356
3357 DELETE FROM Person.LUInsuranceType
3358 WHERE InsuranceTypeID = @InsuranceTypeID
3359
3360 set @success =1;
3361 set @ErrorStatus =0;
3362 COMMIT TRANSACTION;
3363
3364 END TRY
3365
3366 BEGIN CATCH
3367 ROLLBACK TRANSACTION;
3368 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
3369 --We only care if the error was not raised by SSE
3370 IF @@ERROR <> 50000
3371 BEGIN
3372 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
3373 END
3374 SET @Success =0;
3375 SELECT @ErrorStatus= @ErrorStatus +'-600013 DELETE Fail LuInsuranceType';
3376 RAISERROR(@ErrorStatus, 15, 1);
3377
3378
3379 END CATCH
3380
3381 END
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395GO
3396/****** Object: StoredProcedure [dbo].[pDeleteLanguage] Script Date: 10/16/2020 7:31:03 PM ******/
3397SET ANSI_NULLS ON
3398GO
3399SET QUOTED_IDENTIFIER ON
3400GO
3401
3402/*************************************************************************************************
3403
3404*Author: Gary Savard
3405*Date: 8 Oct 10
3406*Table Name: LULanguage
3407Description: Deletes from LULanguage
3408Revisions:
3409**************************************************************************************************/
3410CREATE PROCEDURE [dbo].[pDeleteLanguage](
3411 @LanguageID int,
3412 @Success bit Output,
3413 @ErrorStatus Nvarchar(50) Output
3414 )
3415AS
3416SET NOCOUNT ON;
3417
3418 DECLARE
3419 @TempLanguageID int
3420
3421 SET @TempLanguageID =0;
3422 SET @Success = 0;
3423 SET @ErrorStatus ='';
3424
3425
3426
3427 BEGIN
3428 BEGIN TRY
3429 BEGIN TRANSACTION;
3430 IF ((@LanguageID = 0) OR (@LanguageID IS NULL))
3431 BEGIN
3432 SELECT @ErrorStatus = '60065 LanguageID cant be 0/NULL';
3433 SET @Success = 0;
3434 RAISERROR(@ErrorStatus, 16,1);
3435 END
3436
3437
3438 SELECT @TempLanguageID = LanguageID
3439 FROM person.LULanguage
3440 WHERE LanguageID = @LanguageID
3441
3442
3443 IF ((@TempLanguageID=0) OR (@TempLanguageID IS NULL))
3444 BEGIN
3445 SELECT @ErrorStatus = ' -60068 LanguageID does not exist';
3446 SET @Success =0;
3447 RAISERROR(@ErrorStatus,16,1);
3448 END
3449
3450 IF @@Error <> 0
3451 BEGIN
3452 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -60000';
3453 SET @Success = 0;
3454 RAISERROR(@ErrorStatus, 16, 1);
3455 END
3456
3457 DELETE FROM Person.LULanguage
3458 WHERE LanguageID = @LanguageID
3459
3460 set @success =1;
3461 set @ErrorStatus =0;
3462 COMMIT TRANSACTION;
3463
3464 END TRY
3465
3466 BEGIN CATCH
3467 ROLLBACK TRANSACTION;
3468 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
3469 --We only care if the error was not raised by SSE
3470 IF @@ERROR <> 50000
3471 BEGIN
3472 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
3473 END
3474 SET @Success =0;
3475 SELECT @ErrorStatus= @ErrorStatus +'-60063 DELETE Fail Language';
3476 RAISERROR(@ErrorStatus, 15, 1);
3477
3478
3479 END CATCH
3480
3481 END
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494GO
3495/****** Object: StoredProcedure [dbo].[pDeleteLanguagesSpoken] Script Date: 10/16/2020 7:31:03 PM ******/
3496SET ANSI_NULLS ON
3497GO
3498SET QUOTED_IDENTIFIER ON
3499GO
3500
3501/*************************************************************************************************
3502
3503*Author: Gary Savard
3504*Date: 8 Oct 10
3505*Table Name: LanguagesSpoken
3506Description: Deletes from LanguagesSpoken. A person may have 1 to may records here. Deletes only one based
3507on input ID.
3508Revisions:
3509**************************************************************************************************/
3510CREATE PROCEDURE [dbo].[pDeleteLanguagesSpoken](
3511 @PersonID int,
3512 @LanguagesSpokenID int, --This is the key. do not confuse with LanguageID
3513 @Success bit Output,
3514 @ErrorStatus Nvarchar(50) Output
3515 )
3516AS
3517SET NOCOUNT ON;
3518
3519 DECLARE
3520 @TempLanguagesSpokenID int
3521
3522 SET @TempLanguagesSpokenID =0;
3523 SET @Success = 0;
3524 SET @ErrorStatus ='';
3525
3526
3527
3528 BEGIN
3529 BEGIN TRY
3530 BEGIN TRANSACTION;
3531 IF ((@LanguagesSpokenID = 0) OR (@LanguagesSpokenID IS NULL))
3532 BEGIN
3533 SELECT @ErrorStatus = '11005 LanguagesSpokenID cant be 0/NULL';
3534 SET @Success = 0;
3535 RAISERROR(@ErrorStatus, 16,1);
3536 END
3537
3538 IF ((@PersonID = 0) OR (@PersonID IS NULL))
3539 BEGIN
3540 SELECT @ErrorStatus = '11006 PersonID cant be 0/NULL';
3541 SET @Success = 0;
3542 RAISERROR(@ErrorStatus, 16,1);
3543 END
3544
3545 --This just avoids deleting a LanguagesSpokenID if it is associated with a different PersonID
3546 SELECT @TempLanguagesSpokenID = LanguagesSpokenID
3547 FROM person.LanguagesSpoken
3548 WHERE PersonID= @PersonID AND LanguagesSpokenID = @LanguagesSpokenID
3549
3550
3551 IF ((@TempLanguagesSpokenID=0) OR (@TempLanguagesSpokenID IS NULL))
3552 BEGIN
3553 SELECT @ErrorStatus = ' -11008 LanguagesSpokenID does not exist';
3554 SET @Success =0;
3555 RAISERROR(@ErrorStatus,16,1);
3556 END
3557
3558 IF @@Error <> 0
3559 BEGIN
3560 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -11010';
3561 SET @Success = 0;
3562 RAISERROR(@ErrorStatus, 16, 1);
3563 END
3564
3565 DELETE FROM Person.LanguagesSpoken
3566 WHERE LanguagesSpokenID = @LanguagesSpokenID AND PersonID = @PersonID
3567
3568 set @success =1;
3569 set @ErrorStatus =0;
3570 COMMIT TRANSACTION;
3571
3572 END TRY
3573
3574 BEGIN CATCH
3575 ROLLBACK TRANSACTION;
3576 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
3577 --We only care if the error was not raised by SSE
3578 IF @@ERROR <> 50000
3579 BEGIN
3580 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
3581 END
3582 SET @Success =0;
3583 SELECT @ErrorStatus= @ErrorStatus +'-11013 DELETE Fail LanguagesSpoken';
3584 RAISERROR(@ErrorStatus, 15, 1);
3585
3586
3587 END CATCH
3588
3589 END
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602GO
3603/****** Object: StoredProcedure [dbo].[pDeleteLUFamilyRelationship] Script Date: 10/16/2020 7:31:03 PM ******/
3604SET ANSI_NULLS ON
3605GO
3606SET QUOTED_IDENTIFIER ON
3607GO
3608
3609/*************************************************************************************************
3610
3611*Author: Gary Savard
3612*Date: 8 Oct 10
3613*Table Name: LUFamilyRelationship
3614Description: Deletes from LUFamilyRelationship
3615Revisions:
3616**************************************************************************************************/
3617CREATE PROCEDURE [dbo].[pDeleteLUFamilyRelationship](
3618 @FamilyRelationshipID int,
3619 @Success bit Output,
3620 @ErrorStatus Nvarchar(50) Output
3621 )
3622AS
3623SET NOCOUNT ON;
3624
3625 DECLARE
3626 @TempFamilyRelationshipID int
3627
3628 SET @TempFamilyRelationshipID =0;
3629 SET @Success = 0;
3630 SET @ErrorStatus ='';
3631
3632
3633
3634 BEGIN
3635 BEGIN TRY
3636 BEGIN TRANSACTION;
3637 IF ((@FamilyRelationshipID = 0) OR (@FamilyRelationshipID IS NULL))
3638 BEGIN
3639 SELECT @ErrorStatus = '60045 FamilyRelationshipID cant be 0/NULL';
3640 SET @Success = 0;
3641 RAISERROR(@ErrorStatus, 16,1);
3642 END
3643
3644
3645 SELECT @TempFamilyRelationshipID =FamilyRelationshipID
3646 FROM person.LUFamilyRelationship
3647 WHERE FamilyRelationshipID= @FamilyRelationshipID
3648
3649
3650 IF ((@TempFamilyRelationshipID=0) OR (@TempFamilyRelationshipID IS NULL))
3651 BEGIN
3652 SELECT @ErrorStatus = ' -60048 FamilyRelationshipID does not exist';
3653 SET @Success =0;
3654 RAISERROR(@ErrorStatus,16,1);
3655 END
3656
3657 IF @@Error <> 0
3658 BEGIN
3659 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -60040';
3660 SET @Success = 0;
3661 RAISERROR(@ErrorStatus, 16, 1);
3662 END
3663
3664 DELETE FROM Person.LUFamilyRelationship
3665 WHERE FamilyRelationshipID = @FamilyRelationshipID
3666
3667 set @success =1;
3668 set @ErrorStatus =0;
3669 COMMIT TRANSACTION;
3670
3671 END TRY
3672
3673 BEGIN CATCH
3674 ROLLBACK TRANSACTION;
3675 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
3676 --We only care if the error was not raised by SSE
3677 IF @@ERROR <> 50000
3678 BEGIN
3679 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
3680 END
3681 SET @Success =0;
3682 SELECT @ErrorStatus= @ErrorStatus +'-60043 DELETE Fail FamilyRelationship';
3683 RAISERROR(@ErrorStatus, 15, 1);
3684
3685
3686 END CATCH
3687
3688 END
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701GO
3702/****** Object: StoredProcedure [dbo].[pDeletePersonType] Script Date: 10/16/2020 7:31:03 PM ******/
3703SET ANSI_NULLS ON
3704GO
3705SET QUOTED_IDENTIFIER ON
3706GO
3707
3708/*************************************************************************************************
3709
3710*Author: Gary Savard
3711*Date: 8 Oct 10
3712*Table Name: LUPersonType
3713Description: Deletes from LUPersonType
3714Revisions:
3715**************************************************************************************************/
3716CREATE PROCEDURE [dbo].[pDeletePersonType](
3717 @PersonTypeID int,
3718 @Success bit Output,
3719 @ErrorStatus Nvarchar(50) Output
3720 )
3721AS
3722SET NOCOUNT ON;
3723
3724 DECLARE
3725 @TempPersonTypeID int
3726
3727 SET @TempPersonTypeID =0;
3728 SET @Success = 0;
3729 SET @ErrorStatus ='';
3730
3731
3732
3733 BEGIN
3734 BEGIN TRY
3735 BEGIN TRANSACTION;
3736 IF ((@PersonTypeID = 0) OR (@PersonTypeID IS NULL))
3737 BEGIN
3738 SELECT @ErrorStatus = '600015 PersonTypeID cant be 0/NULL';
3739 SET @Success = 0;
3740 RAISERROR(@ErrorStatus, 16,1);
3741 END
3742
3743
3744 SELECT @TempPersonTypeID =PersonTypeID
3745 FROM person.LUPersonType
3746 WHERE PersonTypeID = @PersonTypeID
3747
3748
3749 IF ((@TempPersonTypeID=0) OR (@TempPersonTypeID IS NULL))
3750 BEGIN
3751 SELECT @ErrorStatus = ' -600018 PersonTypeID does not exist';
3752 SET @Success =0;
3753 RAISERROR(@ErrorStatus,16,1);
3754 END
3755
3756 IF @@Error <> 0
3757 BEGIN
3758 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -600010';
3759 SET @Success = 0;
3760 RAISERROR(@ErrorStatus, 16, 1);
3761 END
3762
3763 DELETE FROM Person.LUPersonType
3764 WHERE PersonTypeID = @PersonTypeID
3765
3766 set @success =1;
3767 set @ErrorStatus =0;
3768 COMMIT TRANSACTION;
3769
3770 END TRY
3771
3772 BEGIN CATCH
3773 ROLLBACK TRANSACTION;
3774 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
3775 --We only care if the error was not raised by SSE
3776 IF @@ERROR <> 50000
3777 BEGIN
3778 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
3779 END
3780 SET @Success =0;
3781 SELECT @ErrorStatus= @ErrorStatus +'-600013 DELETE Fail PersonType';
3782 RAISERROR(@ErrorStatus, 15, 1);
3783
3784
3785 END CATCH
3786
3787 END
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800GO
3801/****** Object: StoredProcedure [dbo].[pDeletePhoneType] Script Date: 10/16/2020 7:31:03 PM ******/
3802SET ANSI_NULLS ON
3803GO
3804SET QUOTED_IDENTIFIER ON
3805GO
3806
3807/*************************************************************************************************
3808
3809*Author: Gary Savard
3810*Date: 8 Oct 10
3811*Table Name: LUPhoneType
3812Description: Deletes from LUPhoneType
3813Revisions:
3814**************************************************************************************************/
3815CREATE PROCEDURE [dbo].[pDeletePhoneType](
3816 @PhoneTypeID int,
3817 @Success bit Output,
3818 @ErrorStatus Nvarchar(50) Output
3819 )
3820AS
3821SET NOCOUNT ON;
3822
3823 DECLARE
3824 @TempPhoneTypeID int
3825
3826 SET @TempPhoneTypeID =0;
3827 SET @Success = 0;
3828 SET @ErrorStatus ='';
3829
3830
3831
3832 BEGIN
3833 BEGIN TRY
3834 BEGIN TRANSACTION;
3835 IF ((@PhoneTypeID = 0) OR (@PhoneTypeID IS NULL))
3836 BEGIN
3837 SELECT @ErrorStatus = '600085 PhoneTypeID cant be 0/NULL';
3838 SET @Success = 0;
3839 RAISERROR(@ErrorStatus, 16,1);
3840 END
3841
3842
3843 SELECT @TempPhoneTypeID =PhoneTypeID
3844 FROM person.LUPhoneType
3845 WHERE PhoneTypeID = @PhoneTypeID
3846
3847
3848 IF ((@TempPhoneTypeID=0) OR (@TempPhoneTypeID IS NULL))
3849 BEGIN
3850 SELECT @ErrorStatus = ' -600088 PhoneTypeID does not exist';
3851 SET @Success =0;
3852 RAISERROR(@ErrorStatus,16,1);
3853 END
3854
3855 IF @@Error <> 0
3856 BEGIN
3857 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -600080';
3858 SET @Success = 0;
3859 RAISERROR(@ErrorStatus, 16, 1);
3860 END
3861
3862 DELETE FROM Person.LUPhoneType
3863 WHERE PhoneTypeID = @PhoneTypeID
3864
3865 set @success =1;
3866 set @ErrorStatus =0;
3867 COMMIT TRANSACTION;
3868
3869 END TRY
3870
3871 BEGIN CATCH
3872 ROLLBACK TRANSACTION;
3873 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
3874 --We only care if the error was not raised by SSE
3875 IF @@ERROR <> 50000
3876 BEGIN
3877 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
3878 END
3879 SET @Success =0;
3880 SELECT @ErrorStatus= @ErrorStatus +'-600083 DELETE Fail PhoneType';
3881 RAISERROR(@ErrorStatus, 15, 1);
3882
3883
3884 END CATCH
3885
3886 END
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899GO
3900/****** Object: StoredProcedure [dbo].[pDeletePostalCode] Script Date: 10/16/2020 7:31:03 PM ******/
3901SET ANSI_NULLS ON
3902GO
3903SET QUOTED_IDENTIFIER ON
3904GO
3905
3906/*************************************************************************************************
3907
3908*Author: Gary Savard
3909*Date: 8 Oct 10
3910*Table Name: LUPostalCode
3911Description: Deletes from LUPostalCode
3912Revisions:
3913**************************************************************************************************/
3914CREATE PROCEDURE [dbo].[pDeletePostalCode](
3915 @PostalCodeID int,
3916 @Success bit Output,
3917 @ErrorStatus Nvarchar(50) Output
3918 )
3919AS
3920SET NOCOUNT ON;
3921
3922 DECLARE
3923 @TempPostalCodeID int
3924
3925 SET @TempPostalCodeID =0;
3926 SET @Success = 0;
3927 SET @ErrorStatus ='';
3928
3929
3930
3931 BEGIN
3932 BEGIN TRY
3933 BEGIN TRANSACTION;
3934 IF ((@PostalCodeID = 0) OR (@PostalCodeID IS NULL))
3935 BEGIN
3936 SELECT @ErrorStatus = '6075 PostalCodeID cant be 0/NULL';
3937 SET @Success = 0;
3938 RAISERROR(@ErrorStatus, 16,1);
3939 END
3940
3941
3942 SELECT @TempPostalCodeID =PostalCodeID
3943 FROM person.LUPostalCode
3944 WHERE PostalCodeID= @PostalCodeID
3945
3946
3947 IF ((@TempPostalCodeID=0) OR (@TempPostalCodeID IS NULL))
3948 BEGIN
3949 SELECT @ErrorStatus = ' -6078 PostalCodeID does not exist';
3950 SET @Success =0;
3951 RAISERROR(@ErrorStatus,16,1);
3952 END
3953
3954 IF @@Error <> 0
3955 BEGIN
3956 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6070';
3957 SET @Success = 0;
3958 RAISERROR(@ErrorStatus, 16, 1);
3959 END
3960
3961 DELETE FROM Person.LUPostalCode
3962 WHERE PostalCodeID = @PostalCodeID
3963
3964 set @success =1;
3965 set @ErrorStatus =0;
3966 COMMIT TRANSACTION;
3967
3968 END TRY
3969
3970 BEGIN CATCH
3971 ROLLBACK TRANSACTION;
3972 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
3973 --We only care if the error was not raised by SSE
3974 IF @@ERROR <> 50000
3975 BEGIN
3976 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
3977 END
3978 SET @Success =0;
3979 SELECT @ErrorStatus= @ErrorStatus +'-6073 DELETE Fail PostalCode';
3980 RAISERROR(@ErrorStatus, 15, 1);
3981
3982
3983 END CATCH
3984
3985 END
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998GO
3999/****** Object: StoredProcedure [dbo].[pDeleteProgramServiceType] Script Date: 10/16/2020 7:31:03 PM ******/
4000SET ANSI_NULLS ON
4001GO
4002SET QUOTED_IDENTIFIER ON
4003GO
4004
4005/*************************************************************************************************
4006
4007*Author: Gary Savard
4008*Date: 8 Oct 10
4009*Table Name: LUProgramServiceType
4010Description: Deletes from LUProgramServiceType
4011Revisions:
4012**************************************************************************************************/
4013CREATE PROCEDURE [dbo].[pDeleteProgramServiceType](
4014 @ProgramServiceTypeID int,
4015 @Success bit Output,
4016 @ErrorStatus Nvarchar(50) Output
4017 )
4018AS
4019SET NOCOUNT ON;
4020
4021 DECLARE
4022 @TempProgramServiceTypeID int
4023
4024 SET @TempProgramServiceTypeID =0;
4025 SET @Success = 0;
4026 SET @ErrorStatus ='';
4027
4028
4029
4030 BEGIN
4031 BEGIN TRY
4032 BEGIN TRANSACTION;
4033 IF ((@ProgramServiceTypeID = 0) OR (@ProgramServiceTypeID IS NULL))
4034 BEGIN
4035 SELECT @ErrorStatus = '6055 ProgramServiceTypeID cant be 0/NULL';
4036 SET @Success = 0;
4037 RAISERROR(@ErrorStatus, 16,1);
4038 END
4039
4040
4041 SELECT @TempProgramServiceTypeID =ProgramServiceTypeID
4042 FROM person.LUProgramServiceType
4043 WHERE ProgramServiceTypeID= @ProgramServiceTypeID
4044
4045
4046 IF ((@TempProgramServiceTypeID=0) OR (@TempProgramServiceTypeID IS NULL))
4047 BEGIN
4048 SELECT @ErrorStatus = ' -6058 ProgramServiceTypeID does not exist';
4049 SET @Success =0;
4050 RAISERROR(@ErrorStatus,16,1);
4051 END
4052
4053 IF @@Error <> 0
4054 BEGIN
4055 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6050';
4056 SET @Success = 0;
4057 RAISERROR(@ErrorStatus, 16, 1);
4058 END
4059
4060 DELETE FROM Person.LUProgramServiceType
4061 WHERE ProgramServiceTypeID = @ProgramServiceTypeID
4062
4063 set @success =1;
4064 set @ErrorStatus =0;
4065 COMMIT TRANSACTION;
4066
4067 END TRY
4068
4069 BEGIN CATCH
4070 ROLLBACK TRANSACTION;
4071 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
4072 --We only care if the error was not raised by SSE
4073 IF @@ERROR <> 50000
4074 BEGIN
4075 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
4076 END
4077 SET @Success =0;
4078 SELECT @ErrorStatus= @ErrorStatus +'-6053 DELETE Fail ProgramServiceType';
4079 RAISERROR(@ErrorStatus, 15, 1);
4080
4081
4082 END CATCH
4083
4084 END
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097GO
4098/****** Object: StoredProcedure [dbo].[pDeleteProgramType] Script Date: 10/16/2020 7:31:03 PM ******/
4099SET ANSI_NULLS ON
4100GO
4101SET QUOTED_IDENTIFIER ON
4102GO
4103
4104/*************************************************************************************************
4105
4106*Author: Gary Savard
4107*Date: 8 Oct 10
4108*Table Name: LUProgramType
4109Description: Deletes from LUProgramType
4110Revisions:
4111**************************************************************************************************/
4112CREATE PROCEDURE [dbo].[pDeleteProgramType](
4113 @ProgramTypeID int,
4114 @Success bit Output,
4115 @ErrorStatus Nvarchar(50) Output
4116 )
4117AS
4118SET NOCOUNT ON;
4119
4120 DECLARE
4121 @TempProgramTypeID int
4122
4123 SET @TempProgramTypeID =0;
4124 SET @Success = 0;
4125 SET @ErrorStatus ='';
4126
4127
4128
4129 BEGIN
4130 BEGIN TRY
4131 BEGIN TRANSACTION;
4132 IF ((@ProgramTypeID = 0) OR (@ProgramTypeID IS NULL))
4133 BEGIN
4134 SELECT @ErrorStatus = '6045 ProgramTypeID cant be 0/NULL';
4135 SET @Success = 0;
4136 RAISERROR(@ErrorStatus, 16,1);
4137 END
4138
4139
4140 SELECT @TempProgramTypeID =ProgramTypeID
4141 FROM person.LUProgramType
4142 WHERE ProgramTypeID= @ProgramTypeID
4143
4144
4145 IF ((@TempProgramTypeID=0) OR (@TempProgramTypeID IS NULL))
4146 BEGIN
4147 SELECT @ErrorStatus = ' -6048 ProgramTypeID does not exist';
4148 SET @Success =0;
4149 RAISERROR(@ErrorStatus,16,1);
4150 END
4151
4152 IF @@Error <> 0
4153 BEGIN
4154 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6040';
4155 SET @Success = 0;
4156 RAISERROR(@ErrorStatus, 16, 1);
4157 END
4158
4159 DELETE FROM Person.LUProgramType
4160 WHERE ProgramTypeID = @ProgramTypeID
4161
4162 set @success =1;
4163 set @ErrorStatus =0;
4164 COMMIT TRANSACTION;
4165
4166 END TRY
4167
4168 BEGIN CATCH
4169 ROLLBACK TRANSACTION;
4170 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
4171 --We only care if the error was not raised by SSE
4172 IF @@ERROR <> 50000
4173 BEGIN
4174 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
4175 END
4176 SET @Success =0;
4177 SELECT @ErrorStatus= @ErrorStatus +'-6043 DELETE Fail PostalCode';
4178 RAISERROR(@ErrorStatus, 15, 1);
4179
4180
4181 END CATCH
4182
4183 END
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196GO
4197/****** Object: StoredProcedure [dbo].[pDeleteRace] Script Date: 10/16/2020 7:31:03 PM ******/
4198SET ANSI_NULLS ON
4199GO
4200SET QUOTED_IDENTIFIER ON
4201GO
4202
4203/*************************************************************************************************
4204
4205*Author: Gary Savard
4206*Date: 8 Oct 10
4207*Table Name: LURace
4208Description: Deletes from LURace
4209Revisions:
4210**************************************************************************************************/
4211CREATE PROCEDURE [dbo].[pDeleteRace](
4212 @RaceID int,
4213 @Success bit Output,
4214 @ErrorStatus Nvarchar(50) Output
4215 )
4216AS
4217SET NOCOUNT ON;
4218
4219 DECLARE
4220 @TempRaceID int
4221
4222 SET @TempRaceID =0;
4223 SET @Success = 0;
4224 SET @ErrorStatus ='';
4225
4226
4227
4228 BEGIN
4229 BEGIN TRY
4230 BEGIN TRANSACTION;
4231 IF ((@RaceID = 0) OR (@RaceID IS NULL))
4232 BEGIN
4233 SELECT @ErrorStatus = '6025 RaceID cant be 0/NULL';
4234 SET @Success = 0;
4235 RAISERROR(@ErrorStatus, 16,1);
4236 END
4237
4238
4239 SELECT @TempRaceID =RaceID
4240 FROM person.LURace
4241 WHERE RaceID= @RaceID
4242
4243
4244 IF ((@TempRaceID=0) OR (@TempRaceID IS NULL))
4245 BEGIN
4246 SELECT @ErrorStatus = ' -6028 RaceID does not exist';
4247 SET @Success =0;
4248 RAISERROR(@ErrorStatus,16,1);
4249 END
4250
4251 IF @@Error <> 0
4252 BEGIN
4253 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6020';
4254 SET @Success = 0;
4255 RAISERROR(@ErrorStatus, 16, 1);
4256 END
4257
4258 DELETE FROM Person.LURace
4259 WHERE RaceID = @RaceID
4260
4261 set @success =1;
4262 set @ErrorStatus =0;
4263 COMMIT TRANSACTION;
4264
4265 END TRY
4266
4267 BEGIN CATCH
4268 ROLLBACK TRANSACTION;
4269 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
4270 --We only care if the error was not raised by SSE
4271 IF @@ERROR <> 50000
4272 BEGIN
4273 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
4274 END
4275 SET @Success =0;
4276 SELECT @ErrorStatus= @ErrorStatus +'-6023 DELETE Fail Race';
4277 RAISERROR(@ErrorStatus, 15, 1);
4278
4279
4280 END CATCH
4281
4282 END
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295GO
4296/****** Object: StoredProcedure [dbo].[pDeleteState] Script Date: 10/16/2020 7:31:03 PM ******/
4297SET ANSI_NULLS ON
4298GO
4299SET QUOTED_IDENTIFIER ON
4300GO
4301
4302/*************************************************************************************************
4303
4304*Author: Gary Savard
4305*Date: 8 Oct 10
4306*Table Name: LUState
4307Description: Deletes from LUState
4308Revisions:
4309**************************************************************************************************/
4310CREATE PROCEDURE [dbo].[pDeleteState](
4311 @StateID int,
4312 @Success bit Output,
4313 @ErrorStatus Nvarchar(50) Output
4314 )
4315AS
4316SET NOCOUNT ON;
4317
4318 DECLARE
4319 @TempStateID int
4320
4321 SET @TempStateID =0;
4322 SET @Success = 0;
4323 SET @ErrorStatus ='';
4324
4325
4326
4327 BEGIN
4328 BEGIN TRY
4329 BEGIN TRANSACTION;
4330 IF ((@StateID = 0) OR (@StateID IS NULL))
4331 BEGIN
4332 SELECT @ErrorStatus = '6035 StateID cant be 0/NULL';
4333 SET @Success = 0;
4334 RAISERROR(@ErrorStatus, 16,1);
4335 END
4336
4337
4338 SELECT @TempStateID =StateID
4339 FROM person.LUState
4340 WHERE StateID= @StateID
4341
4342
4343 IF ((@TempStateID=0) OR (@TempStateID IS NULL))
4344 BEGIN
4345 SELECT @ErrorStatus = ' -6038 StateID does not exist';
4346 SET @Success =0;
4347 RAISERROR(@ErrorStatus,16,1);
4348 END
4349
4350 IF @@Error <> 0
4351 BEGIN
4352 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6030';
4353 SET @Success = 0;
4354 RAISERROR(@ErrorStatus, 16, 1);
4355 END
4356
4357 DELETE FROM Person.LUState
4358 WHERE StateID = @StateID
4359
4360 set @success =1;
4361 set @ErrorStatus =0;
4362 COMMIT TRANSACTION;
4363
4364 END TRY
4365
4366 BEGIN CATCH
4367 ROLLBACK TRANSACTION;
4368 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
4369 --We only care if the error was not raised by SSE
4370 IF @@ERROR <> 50000
4371 BEGIN
4372 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
4373 END
4374 SET @Success =0;
4375 SELECT @ErrorStatus= @ErrorStatus +'-6033 DELETE Fail State';
4376 RAISERROR(@ErrorStatus, 15, 1);
4377
4378
4379 END CATCH
4380
4381 END
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394GO
4395/****** Object: StoredProcedure [dbo].[pInsertAddress] Script Date: 10/16/2020 7:31:03 PM ******/
4396SET ANSI_NULLS ON
4397GO
4398SET QUOTED_IDENTIFIER ON
4399GO
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410/*************************************************************************************************
4411* Stored Procedure Template. Change XXX in name to the name of the table that will get the insert. This is to be used
4412*for single table inserts only.
4413*Author: Gary Savard
4414*Date: 8 Oct 10
4415*Table Name: Address
4416Description: Inserts data to Address table.This table has the possibility of duplicate rows because
4417 persons can have more than one address. We can check to see if an address is a duplicate, but that will have
4418 limited use since we would have to count on a combination of free-format fields since it is possible to have more than
4419 one address in the same city, zipcode, state, county, etc.
4420Revisions:
4421**************************************************************************************************/
4422
4423CREATE PROCEDURE [dbo].[pInsertAddress](
4424 @PersonID int,
4425 @AddressLine1 Nvarchar(60),
4426 @AddressLine2 Nvarchar(60) = NULL,
4427 @City NVarchar(30),
4428 @County NVarchar(30),
4429 @State NVarchar(2),
4430 @PostalCode NVarchar(10) ,
4431 @AddressTypeID int,
4432 @ModifiedBy Name,
4433 @NewAddressID int Output,
4434 @Success bit Output,
4435 @ErrorStatus Nvarchar(50) Output
4436 )
4437AS
4438SET NOCOUNT ON;
4439BEGIN
4440 DECLARE
4441 @TempAddressTypeID int,
4442 @TempPersonID int,
4443 @TempAddressID int
4444
4445 SET @TempAddressTypeID =0;
4446 SET @Success = 0;
4447 SET @ErrorStatus ='';
4448 SET @TempAddressID =0;
4449 SET @TempAddressID = 0;
4450
4451
4452
4453 BEGIN TRY
4454 BEGIN TRANSACTION;
4455 /****************************************************************************/
4456 --This is a bit different than some procedures because there is a lookup table associated with
4457 --the address, so we need to be sure that the data matches an address type before continuing.
4458 SELECT @TempAddressTypeID = AddressTypeID
4459 FROM person.LUAddressType
4460 WHERE AddressTypeID = (@AddressTypeID)
4461
4462 If @TempAddressTypeID = 0
4463 BEGIN
4464 SET @ErrorStatus = ' -7002 Address Type does not existLUAddressType'; --Failed in lookup table
4465 RAISERROR(@ErrorStatus,15,1);--Could use WITH LOG for event log
4466
4467 END
4468 /****************************************************************************/
4469
4470 IF @@Error <> 0
4471 BEGIN
4472 SELECT @ErrorStatus = Convert(nVarchar(50),@@ERROR) + '-7000';
4473 SET @Success = 0;
4474 RAISERROR (@ErrorStatus,16,1);
4475 END
4476
4477 INSERT Person.Address(PersonID,AddressLine1,AddressLine2,City,County,Address.State,PostalCode,AddressTypeID,ModifiedDate, ModifiedBy)
4478 VALUES (@PersonID, @AddressLine1, @AddressLine2,@City,@County,@State,@PostalCode,@AddressTypeID,SYSDATETIME(),@ModifiedBy)
4479
4480 set @NewAddressID =@@IDENTITY;
4481 set @success =1;
4482 set @ErrorStatus =0;
4483 COMMIT TRANSACTION;
4484
4485 END TRY
4486
4487 BEGIN CATCH
4488 ROLLBACK TRANSACTION;
4489 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
4490 --We only care if the error was not raised by SSE
4491 IF @@ERROR <> 50000
4492 BEGIN
4493 SET @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
4494 END
4495
4496
4497 SELECT @ErrorStatus =@ErrorStatus + ' -7001' +' Insert Failed';
4498 SET @Success =0;
4499
4500 RAISERROR(@ErrorStatus, 16, 1);
4501
4502
4503 END CATCH
4504
4505
4506END
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518GO
4519/****** Object: StoredProcedure [dbo].[pInsertAddressType] Script Date: 10/16/2020 7:31:03 PM ******/
4520SET ANSI_NULLS ON
4521GO
4522SET QUOTED_IDENTIFIER ON
4523GO
4524
4525
4526/*************************************************************************************************
4527*Author: Gary Savard
4528*Date: 8 Oct 10
4529*Table Name: LUAddressType
4530Description: Inserts data to LUAddressType. This table matches the address with an address type
4531Revisions:
4532G.S. - 20 Oct 10. Fixed problem with error handler not firing on preliminary lookup.
4533**************************************************************************************************/
4534CREATE PROCEDURE [dbo].[pInsertAddressType](
4535 @AddressType Nvarchar(10),
4536 @ModifiedBy Name,
4537 @NewAddressTypeID int Output,
4538 @Success bit Output,
4539 @ErrorStatus Nvarchar(50) Output
4540 )
4541AS
4542SET NOCOUNT ON;
4543
4544BEGIN
4545 DECLARE
4546 @TempAddressTypeID int
4547
4548 SET @TempAddressTypeID =0;
4549 SET @Success = 0;
4550 SET @ErrorStatus ='';
4551
4552
4553
4554
4555
4556 BEGIN TRY
4557 BEGIN TRANSACTION;
4558
4559 /****************************************************************************/
4560 --Avoid Duplicate Rows! However, a typo on input such as 'Hmoe' instead of 'Home' will do an isert.
4561 --Can't avoid finger problems!
4562
4563 SELECT @TempAddressTypeID = AddressTypeID
4564 FROM person.LUAddressType
4565 WHERE AddressType = Rtrim(Ltrim(@AddressType)) --Be a bit paranoid and trim the input for white spaces
4566 If @TempAddressTypeID <> 0 --Already Exists
4567 BEGIN
4568 SELECT @ErrorStatus = '-7015 AddressType Already Exists';
4569 SET @Success =0;
4570 RAISERROR(@ErrorStatus, 16, 1);
4571 END
4572
4573 /****************************************************************************/
4574
4575 IF @@Error <> 0
4576 BEGIN
4577 SELECT @ErrorStatus = Convert (nVarchar(50),@@ERROR) + ' -6010';
4578 SET @Success = 0;
4579 RAISERROR(@ErrorStatus, 16, 1);
4580 END
4581
4582
4583 INSERT Person.LUAddressType(AddressType,ModifiedDate, ModifiedBy)
4584 VALUES (@AddressType,SYSDATETIME(),@ModifiedBy)
4585
4586 set @NewAddressTypeID =@@IDENTITY;
4587 set @success =1;
4588 set @ErrorStatus ='';
4589 COMMIT TRANSACTION;
4590
4591 END TRY
4592
4593 BEGIN CATCH
4594
4595 ROLLBACK TRANSACTION;
4596 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
4597 --We only care if the error was not raised by SSE
4598 IF @@ERROR <> 50000
4599 BEGIN
4600 SET @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
4601 END
4602
4603
4604 SET @Success =0;
4605 SELECT @ErrorStatus = @ErrorStatus + 'Rollback -6011';
4606 RAISERROR(@ErrorStatus, 16, 1);
4607
4608
4609 END CATCH
4610
4611
4612END
4613
4614
4615
4616
4617
4618
4619
4620
4621GO
4622/****** Object: StoredProcedure [dbo].[pInsertCertificationText] Script Date: 10/16/2020 7:31:03 PM ******/
4623SET ANSI_NULLS ON
4624GO
4625SET QUOTED_IDENTIFIER ON
4626GO
4627
4628
4629
4630
4631
4632
4633
4634
4635/*************************************************************************************************
4636*Author: Gary Savard
4637*Date: 03/29/2011
4638*Table Name: LuCertificationText
4639Description: Inserts data to LUCertificationText.
4640The text inserted into this table shall not be deleted because the text history must be assoicated with signature history. No
4641delete SP will be created for this table.
4642**************************************************************************************************/
4643
4644CREATE PROCEDURE [dbo].[pInsertCertificationText](
4645 @CertificationText NVarchar(MAX),
4646 @GuidelinesText NVarchar(MAX),
4647 @ModifiedBy Name,
4648 @NewCertificationTextID int Output,
4649 @Success bit Output,
4650 @ErrorStatus NVarchar(50) Output
4651 )
4652AS
4653SET NOCOUNT ON;
4654BEGIN
4655 DECLARE
4656 @TempCertificationTextID int
4657
4658 SET @TempCertificationTextID =0;
4659 SET @Success = 0;
4660 SET @ErrorStatus ='';
4661
4662
4663 BEGIN
4664 BEGIN TRY
4665 BEGIN TRANSACTION;
4666
4667
4668 IF @@Error <> 0
4669 BEGIN
4670 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60050';
4671 SET @Success = 0;
4672 RAISERROR(@ErrorStatus, 16,1);
4673 END
4674
4675 INSERT Foodshelf.LUCertificationText(CertificationText,GuidelinesText, ModifiedDate,ModifiedBy)
4676 VALUES (@CertificationText,@GuidelinesText,SYSDATETIME(),@ModifiedBy)
4677
4678 set @NewCertificationTextID =@@IDENTITY;
4679 set @success =1;
4680 set @ErrorStatus =0;
4681 COMMIT TRANSACTION;
4682
4683 END TRY
4684
4685 BEGIN CATCH
4686 ROLLBACK TRANSACTION;
4687 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
4688 --We only care if the error was not raised by SSE
4689 IF @@ERROR <> 50000
4690 BEGIN
4691 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
4692 END
4693
4694 SET @Success =0;
4695 SELECT @ErrorStatus= @ErrorStatus +'-60051 Insert Failed on LUCertificationText ';
4696 RAISERROR(@ErrorStatus, 16, 1);
4697
4698
4699 END CATCH
4700
4701 END
4702END
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716GO
4717/****** Object: StoredProcedure [dbo].[pInsertCity] Script Date: 10/16/2020 7:31:03 PM ******/
4718SET ANSI_NULLS ON
4719GO
4720SET QUOTED_IDENTIFIER ON
4721GO
4722
4723
4724
4725
4726
4727
4728/*************************************************************************************************
4729*Author: Gary Savard
4730*Date: 9 Oct 10
4731*Table Name: LUCity
4732Description: Inserts data to LUCity.
4733Ideally we would have information on the county as well as the state before we add the city. However,
4734we cannot assume that we have a county, so we will have it to default to 0, if no value is entered.
4735Revisions:
4736GS 20 Oct fixed failure in error handler due to implicit conversion of @@Error, worked intermittantly
4737**************************************************************************************************/
4738
4739CREATE PROCEDURE [dbo].[pInsertCity](
4740 @CityName NVarchar(30),
4741 @CityAbbreviation Nvarchar(30) ='',
4742 @StateID int,
4743 @CountyID int = 0,--Default countyID to 0 just in case it comes in later.
4744 @PostalCodeID int =0, --Will come later, just a place holder
4745 @ModifiedBy Name,
4746 @NewCityID int Output,
4747 @Success bit Output,
4748 @ErrorStatus NVarchar(50) Output
4749 )
4750AS
4751SET NOCOUNT ON;
4752BEGIN
4753 DECLARE
4754 @TempCityID int
4755
4756 SET @TempCityID =0;
4757 SET @Success = 0;
4758 SET @ErrorStatus ='';
4759
4760
4761 BEGIN
4762 BEGIN TRY
4763 BEGIN TRANSACTION;
4764 IF @StateID = 0 --Must have a state before we can have a city!
4765 BEGIN
4766 SELECT @ErrorStatus = '-60055 StateID cant be NULL or 0';
4767 SET @Success = 0;
4768 RAISERROR(@ErrorStatus, 16,1);
4769 END
4770
4771/****************************************************************************/
4772
4773 SELECT @TempCityID = CityID
4774 FROM person.LUCity
4775 WHERE CityName = Rtrim(Ltrim(@CityName)) and StateID = @StateID
4776 If @TempCityID <>0
4777 BEGIN
4778 SET @ErrorStatus = ' -60052 City exists in LUCity';
4779 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
4780
4781 END
4782
4783/****************************************************************************/
4784
4785 IF @@Error <> 0
4786 BEGIN
4787 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60050';
4788 SET @Success = 0;
4789 RAISERROR(@ErrorStatus, 16,1);
4790 END
4791
4792 INSERT Person.LUCity(StateID,CountyID,PostalCodeID,CityName,CityAbbreviation, ModifiedDate,ModifiedBy)
4793 VALUES (@StateID,@CountyID,@PostalCodeID,@CityName,@CityAbbreviation,SYSDATETIME(),@ModifiedBy)
4794
4795 set @NewCityID =@@IDENTITY;
4796 set @success =1;
4797 set @ErrorStatus =0;
4798 COMMIT TRANSACTION;
4799
4800 END TRY
4801
4802 BEGIN CATCH
4803 ROLLBACK TRANSACTION;
4804 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
4805 --We only care if the error was not raised by SSE
4806 IF @@ERROR <> 50000
4807 BEGIN
4808 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
4809 END
4810
4811 SET @Success =0;
4812 SELECT @ErrorStatus= @ErrorStatus +'-60051 Insert Failed on City ';
4813 RAISERROR(@ErrorStatus, 16, 1);
4814
4815
4816 END CATCH
4817
4818 END
4819END
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831GO
4832/****** Object: StoredProcedure [dbo].[pInsertClientFamilyRecord] Script Date: 10/16/2020 7:31:03 PM ******/
4833SET ANSI_NULLS ON
4834GO
4835SET QUOTED_IDENTIFIER ON
4836GO
4837
4838
4839
4840
4841-- =============================================
4842-- Author: Gary Savard
4843-- Create date: 26 Oct 2010
4844-- Description: This is the main stored procedure to save a new family member for a client
4845-- into the system. It calls several other stored procedures to do inserts into
4846-- selected parts of the DB. Clients and Family members of clients have similar data, but
4847--will use separate stored procedures for clarity.
4848--FOOD. Same idea with the rest of the programs.
4849--IDs that are important such as 'address type' from that lookup table need to be passed in here since they
4850--were selected by the user. No need to try to figure them out in the SP
4851--Certification has its own button so we have a separate stored procedure to deal with that functionality and the same for
4852--family members since they do not have some of the information that we need for the client.
4853
4854--Revisions: 4 Nov 10- Added Client notes insert procedure call
4855--15 March 11. Modified to remove address, phone, email and number in household for family members. The version with all of these parameters
4856--exists in a new stored procedure called pInsertFamilyRecordWithAddress, if ever needed. It is the same sp as this one before these edits.
4857--5 April remove @numberInHousehold, @HomeboundDelivery,@ISPrimaryLanguage,@LanguageId,@Title,@Suffix
4858--19 July 2011 Added LTRIM,RTRIM for @Firstname, @MiddleName, @LastName
4859-- =============================================
4860CREATE PROCEDURE [dbo].[pInsertClientFamilyRecord] (
4861 @RecordSource NVarchar(8),
4862 @ClientPersonID int,
4863 @FirstName Name,
4864 @MiddleName Name = NULL,
4865 @LastName Name,
4866 @DateOfBirth DateTime,
4867 @RelationshipID int,
4868 @RelationshipDescription NVarchar(50)='',
4869 @HousingStatus nVarchar(50),--The TEXT value from the lookup table. Saves having to query by ID later
4870 @FamilyStatusType NVarchar(50),
4871 @Disability NoYesMaybe =0,
4872 @Gender NVarchar(2)='',--Foodshelf and WX may leave blank
4873 @CSFP NoYesMaybe = 0,
4874 @Veteran NoYesMaybe=0,
4875 @HealthInsurance NoYesMaybe =0 ,
4876 @InsuranceType NVarchar(50),
4877 @FoodStamps NoYesMaybe =0,--Three squares
4878 @EducationCategoryID int =0, --Not required for Food shelf
4879 @CountryOfOrigin nVarchar(70)='', --Not required for food shelf
4880 @Race NVarchar(20) =NULL,
4881 @Ethnicity NVarchar(20) =NULL,
4882 @IncomeSourceID int =0,
4883 @Notes NVarchar(MAX)=NULL,--A single person may have many notes. The notes will be specific to a particular program, so we will not have a single notes table
4884 @ModifiedBy Name,
4885 @NewPersonIDout int Output,
4886 @NewFamilyRelationshipID int output,
4887 @Success bit Output,
4888 @ErrorStatus Nvarchar(50) Output
4889 )
4890AS
4891
4892
4893SET NOCOUNT ON;
4894 DECLARE
4895 @ValidSource int,
4896 @NewPersonID int,
4897 @NewAddressID int,
4898 @NewPhoneID int,
4899 @Succ bit,
4900 @ErrorMsg NVarchar(50),
4901 @NewDemographicsID int, --Not using here, just a place holder!
4902 @NewFoodTypeGivenID int, -- We don't do anything with this. Just receives SP output for now.
4903 @NewClientNotesID int,
4904 @TempClientPersonID int,
4905 @DummyNumberInHousehold int, --just place holder with default of 0
4906 @DummyHomeboundDelivery int,
4907 @DummyIsPrimaryLanguage bit,
4908 @DummyLanguageID int,
4909 @DummyTitle NVarchar(8),
4910 @DummySuffix NVarchar(10)
4911
4912
4913 SET @ValidSource =0;
4914 SET @NewPersonID =0;
4915 SET @NewAddressID =0;
4916 SET @NewPhoneID = 0;
4917 SET @NewDemographicsID =0;
4918 SET @NewFoodTypeGivenID =0;
4919 SET @NewClientNotesID =0;
4920 SET @Succ =0;
4921 SET @ErrorMsg ='';
4922 SET @TempClientPersonID =0;
4923 SET @DummyNumberInHousehold =0;
4924 SET @DummyHomeboundDelivery=2;--This is set to N/A
4925 SET @DummyIsPrimaryLanguage=0;
4926 SET @DummyLanguageID=0;
4927 SET @DummyTitle = NULL;
4928 SET @DummySuffix = NULL;
4929 SET @FirstName = LTRIM(rtrim(@firstname));
4930 SET @MiddleName = LTRIM(RTRIM(@MiddleName));
4931 SET @LastName = LTRIM(RTRIM(@LastName));
4932
4933 BEGIN TRY
4934 BEGIN TRANSACTION;
4935
4936 --The family member must be associated with a ClientPersonID or we bail.
4937--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4938 IF @ClientPersonID = 0 OR @ClientPersonID IS NULL
4939 BEGIN --IF @ClientPersonID = 0 OR
4940 SET @Success =0;
4941 SET @ErrorStatus = '-17500 ClientPersonID cannot be null or 0';
4942 RAISERROR(@ErrorStatus,16,1);
4943
4944 END --IF @ClientPersonID = 0 OR
4945--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4946--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4947 SELECT @TempClientPersonID = @ClientPersonID
4948 FROM Person.Person
4949 WHERE PersonID = @ClientPersonID
4950
4951 IF @TempClientPersonID = 0 OR @TempClientPersonID IS NULL--the client must exist to have a family member!
4952 BEGIN --IF @TempClientPersonID = 0 OR
4953 SET @Success=0;
4954 SET @ErrorStatus = '-17501 ClientPersonID does not exist in person';
4955 RAISERROR (@ErrorStatus,16,1);
4956 END --IF @TempClientPersonID = 0 OR
4957--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4958--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4959 --Take the return value and throw error if 0 because we cannot proceed of we don't know
4960 --which set of sps to call.
4961 SET @ValidSource = DBO.ValidateDataSource(@RecordSource);
4962
4963 IF @ValidSource =0
4964 BEGIN --IF @ValidSource =0
4965 SET @Success =0;
4966 SELECT @ErrorStatus = '-17100 Invalid Record source';
4967 RAISERROR(@ErrorStatus,16,1);
4968 --Raise Error Here because the source is unknown.
4969 END --IF @ValidSource =0
4970--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4971--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4972
4973 BEGIN --Insert into Person and take the new personID for further use. Email address NULL and Email Contact 0 hard coded for family members
4974 EXEC DBO.pInsertPerson @DummyTitle,@FirstName,@MiddleName,@LastName,@DummySuffix, @DateOfBirth,NULL,0,@ModifiedBy,@NewPersonID Output,@Succ Output, @ErrorMsg Output;
4975 SET @NewPersonIDout = @NewPersonID;--Fix this in future!
4976
4977
4978 IF @Succ =0 -- Failure!
4979 BEGIN --IF @Succ =0 -- Failure!
4980 SET @Success = @Succ;
4981 SELECT @ErrorStatus = '-17200 Sub Pro pInsertPerson Fail'+ @ErrorMsg;
4982 RAISERROR(@ErrorStatus,16,1);
4983 END --IF @Succ =0 -- Failure!
4984 SET @Success =1;
4985 SET @ErrorStatus='';
4986 END --Insert into Person and take the new personID for further use.
4987--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4988--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4989IF @NewPersonID > 0 AND @NewPersonID IS NOT NULL
4990 BEGIN --IF @NewPersonID > 0 AND @NewPersonID IS NOT NULL
4991
4992--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4993--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4994 --Insert Demographics
4995 BEGIN --Insert Demographics. Number in household hard coded to 0 for family members
4996 EXEC dbo.pInsertDemographics @NewPersonID,@EducationCategoryID ,@HousingStatus,@DummyNumberInHousehold,@Gender,@Race,@CountryOfOrigin,@Ethnicity,@Disability,@CSFP,@Veteran,@HealthInsurance,@FamilyStatusType,@InsuranceType,@FoodStamps,@DummyHomeboundDelivery,@ModifiedBy,@NewDemographicsID OUTPUT,@Succ OUTPUT, @ErrorMsg OUTPUT;
4997
4998 IF @Succ = 0
4999 BEGIN --IF @Succ = 0
5000 SET @Success =0;
5001 SELECT @ErrorStatus ='-13200 Sub proc Demographics returned fail' + @ErrorMsg;
5002 RAISERROR(@ErrorStatus,16,1);
5003
5004 END --IF @Succ = 0
5005 END --Insert Demographics
5006
5007 --Insert income source. This may take multiple entries in the future so we have not created an SP yet.
5008 IF @IncomeSourceID <> 0
5009 BEGIN
5010 INSERT INTO PERSON.Income (IncomeSourceID,PersonID,ModifiedBy,ModifiedDate) Values (@IncomeSourceID,@NewPersonID,@ModifiedBy,SYSDATETIME())
5011
5012 END
5013 IF @Succ =0
5014 BEGIN
5015 SET @Success =0;
5016 SET @ErrorStatus = 'Fail on Insert Income';
5017 RAISERROR (@ErrorSTatus,16,1) with log;
5018 END
5019
5020 --Insert Client Notes if they exist. This insert procedure is for the client, so we do not have
5021 --A value for HouseholdMemberPersonID so we hard code it to 0.
5022 IF LTRIM(RTRIM(@notes))<>'' AND @Notes IS NOT NULL
5023 BEGIN --IF LTRIM(RTRIM(@notes))<>''
5024 EXEC DBO.pInsertHouseholdNotes @ClientPersonID, @NewPersonID,@Notes,@ModifiedBy,@NewClientNotesID OUTPUT,@Succ OUTPUT,@ErrorMsg OUTPUT;
5025 IF @Succ =0
5026 BEGIN --IF @Succ =0
5027 SET @Success =0
5028 SET @ErrorStatus = '-17001 Insert Failed Notes' + @ErrorMsg;
5029 RAISERROR(@ErrorStatus,16,1);
5030 END --IF @Succ =0
5031
5032 END --IF LTRIM(RTRIM(@notes))<>''
5033
5034 --We have everything except for the relationship to the client, so we do that last.
5035
5036
5037 EXEC DBO.pInsertFamilyRelationship @NewPersonIDout, @ClientPersonID,@RelationshipID,@RelationshipDescription,@ModifiedBy, @NewFamilyRelationshipID OUTPUT, @Succ OUTPUT, @ErrorMsg OUTPUT;
5038 IF @Succ =0
5039 BEGIN --IF @Succ =0
5040 SET @Success =0;
5041 SET @ErrorStatus ='-17001 Insert Failed Family Relationship'+ @ErrorMsg
5042 RAISERROR(@ErrorStatus,16,1);
5043 END --IF @Succ =0
5044
5045 --We are using nested transactions to make sure one exists in case
5046 --of a rollback in subordinate Stored Procedure
5047 IF @@TRANCOUNT > 0
5048 BEGIN --IF @@TRANCOUNT > 0
5049 SET @Success =1;
5050 SET @ErrorStatus ='';
5051 COMMIT TRANSACTION;
5052 END --IF @@TRANCOUNT > 0
5053END --IF @NewPersonID > 0 AND @NewPersonID IS NOT NULL
5054END TRY
5055
5056BEGIN CATCH
5057 IF @@TRANCOUNT >0
5058 BEGIN
5059 SET @Success =0
5060 SET @ErrorStatus =@ErrorStatus + ' ' +@@Error
5061 ROLLBACK TRANSACTION;
5062
5063 RAISERROR(@ErrorStatus,16,1);
5064 END
5065END CATCH
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086GO
5087/****** Object: StoredProcedure [dbo].[pInsertClientFamilyRecordWithAddress] Script Date: 10/16/2020 7:31:03 PM ******/
5088SET ANSI_NULLS ON
5089GO
5090SET QUOTED_IDENTIFIER ON
5091GO
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102-- =============================================
5103-- Author: Gary Savard
5104-- Create date: 26 Oct 2010
5105-- Description: This is the main stored procedure to save a new family member for a client
5106-- into the system. It calls several other stored procedures to do inserts into
5107-- selected parts of the DB. Clients and Family members of clients have similar data, but
5108--will use separate stored procedures for clarity.
5109--FOOD. Same idea with the rest of the programs.
5110--IDs that are important such as 'address type' from that lookup table need to be passed in here since they
5111--were selected by the user. No need to try to figure them out in the SP
5112--Certification has its own button so we have a separate stored procedure to deal with that functionality and the same for
5113--family members since they do not have some of the information that we need for the client.
5114
5115--Revisions: 4 Nov 10- Added Client notes insert procedure call
5116
5117-- 16 March 11. This stored procedure has been renamed from pInsertClientFamilyRecord to pInsertClientFamilyRecordWithAddress
5118--Champlain Charity does not want to collect addresses of family members other than the client. The new pInsertClientFamilyRecord does not collect that data. This
5119--is kept in case future clients want to capture that data.
5120
5121
5122-- =============================================
5123CREATE PROCEDURE [dbo].[pInsertClientFamilyRecordWithAddress] (
5124 @RecordSource NVarchar(8),
5125 @ClientPersonID int,
5126 @Title NVarchar(8) =NULL,
5127 @FirstName Name,
5128 @MiddleName Name = NULL,
5129 @LastName Name,
5130 @Suffix NVarchar(10) = NULL,
5131 @DateOfBirth DateTime,
5132 @RelationshipID int,
5133 @RelationshipDescription NVarchar(50)='',
5134 @Address1 NVarchar(60) =NULL,--Only for Foodshelf!!
5135 @Address2 NVarchar(60) = NULL,
5136 @City NVarchar(30),
5137 @County NVarchar(30) = NULL,
5138 @State NVarchar(2),
5139 @PostalCode NVarchar(10),
5140 @AddressTypeID int =0,--From the Lookup based on user input. May not need if Foodshelf
5141 @EmailAddress Nvarchar(50) = NULL,--May not need for foodshelf
5142 @EmailContactPreference NoYes =0,
5143 @PhoneNumber Phone ='',
5144 @PhoneExtension Nvarchar(8) ='', --may not be implemented yet
5145 @PhoneTypeID int =0, --0 default, Food shelf again!
5146 @HousingStatus nVarchar(50),--The TEXT value from the lookup table. Saves having to query by ID later
5147 @NumberInHousehold int,
5148 @Disability NoYesMaybe =0,
5149 @Gender NVarchar(2)='',--Foodshelf and WX may leave blank
5150 @CSFP NoYesMaybe = 0,
5151 @Veteran NoYesMaybe=0,
5152 @HealthInsurance NoYesMaybe =0 ,
5153 @FoodStamps NoYesMaybe =0,--Three squares
5154 @HomeboundDelivery NoYesMaybe =0,
5155 @LanguageID int =0,--This is only important for volunteers and that funtionality has not been developed yet.
5156 @IsPrimaryLanguage bit =0,
5157 @EducationCategoryID int =0, --Not required for Food shelf
5158 @CountryOfOrigin nVarchar(70)='', --Not required for food shelf
5159 @Race NVarchar(20) =NULL,
5160 @Ethnicity NVarchar(20) =NULL,
5161 @IncomeSourceID int =0,
5162 @Notes NVarchar(MAX)=NULL,--A single person may have many notes. The notes will be specific to a particular program, so we will not have a single notes table
5163 @ModifiedBy Name,
5164 @NewPersonIDout int Output,
5165 @NewFamilyRelationshipID int out,
5166 @Success bit Output,
5167 @ErrorStatus Nvarchar(50) Output
5168 )
5169AS
5170
5171
5172SET NOCOUNT ON;
5173 DECLARE
5174 @ValidSource int,
5175 @NewPersonID int,
5176 @NewAddressID int,
5177 @NewPhoneID int,
5178 @Succ bit,
5179 @ErrorMsg NVarchar(50),
5180 @NewDemographicsID int, --Not using here, just a place holder!
5181 @NewFoodTypeGivenID int, -- We don't do anything with this. Just receives SP output for now.
5182 @NewClientNotesID int,
5183 @TempClientPersonID int
5184
5185
5186 SET @ValidSource =0;
5187 SET @NewPersonID =0;
5188 SET @NewAddressID =0;
5189 SET @NewPhoneID = 0;
5190 SET @NewDemographicsID =0;
5191 SET @NewFoodTypeGivenID =0;
5192 SET @NewClientNotesID =0;
5193 SET @Succ =0;
5194 SET @ErrorMsg ='';
5195 SET @TempClientPersonID =0;
5196 SET @FirstName =LTRIM(RTRIM(@FirstName));
5197 SET @MiddleName = LTRIM(RTRIM(@MiddleName));
5198 SET @LastName = LTRIM(RTRIM(@LastName));
5199
5200 BEGIN TRY
5201 BEGIN TRANSACTION;
5202
5203 --The family member must be associated with a ClientPersonID or we bail.
5204
5205 IF @ClientPersonID = 0 OR @ClientPersonID IS NULL
5206 BEGIN
5207 SET @Success =0;
5208 SET @ErrorStatus = '-17500 ClientPersonID cannot be null or 0';
5209 RAISERROR(@ErrorStatus,16,1);
5210
5211 END
5212
5213 SELECT @TempClientPersonID = @ClientPersonID
5214 FROM Person.Person
5215 WHERE PersonID = @ClientPersonID
5216
5217 IF @TempClientPersonID = 0 OR @TempClientPersonID IS NULL--the client must exist to have a family member!
5218 BEGIN
5219 SET @Success=0;
5220 SET @ErrorStatus = '-17501 ClientPersonID does not exist in person';
5221 RAISERROR (@ErrorStatus,16,1);
5222 END
5223
5224
5225 --Take the return value and throw error if 0 because we cannot proceed of we don't know
5226 --which set of sps to call.
5227 SET @ValidSource = DBO.ValidateDataSource(@RecordSource);
5228
5229 IF @ValidSource =0
5230 BEGIN
5231 SET @Success =0;
5232 SELECT @ErrorStatus = '-17100 Invalid Record source';
5233 RAISERROR(@ErrorStatus,16,1);
5234 --Raise Error Here because the source is unknown.
5235 END
5236
5237 --Insert into Person and take the new personID for further use.
5238 BEGIN
5239 EXEC DBO.pInsertPerson @Title,@FirstName,@MiddleName,@LastName,@Suffix, @DateOfBirth,@EmailAddress,@EmailContactPreference,@ModifiedBy,@NewPersonID Output,@Succ Output, @ErrorMsg Output;
5240 SET @NewPersonIDout = @NewPersonID;
5241
5242
5243 IF @Succ =0 -- Failure!
5244 BEGIN
5245 SET @Success = @Succ;
5246 SELECT @ErrorStatus = '-17200 Sub Pro Fail'+ @ErrorMsg;
5247 RAISERROR(@ErrorStatus,16,1);
5248 END
5249 SET @Success =1;
5250 SET @ErrorStatus='';
5251 END
5252
5253 --IF the source is from Food Shelf we cannot assume that we will need to call the address or phone SPs because they
5254 --are not required to take that information.
5255 --IF we have a good PersonID returned, we continue to Address
5256
5257 --The address should be the same as that of the client, but we will add it anyway because this person
5258 --may eventually become a client and we will already have an AddressID that we can use and modify the location.
5259
5260 IF @NewPersonID > 0 AND @NewPersonID IS NOT NULL
5261 BEGIN
5262 IF ((@RecordSource <> 'FOOD') AND (LTRIM(RTRIM(@Address1)) ='') OR (LTRIM(RTRIM(@Address1)) IS NULL) )--This is a problem because address is required
5263 BEGIN
5264 SET @Succ =0;
5265 SET @ErrorStatus ='-17300 Address Required for Non foodshelf intake.';
5266 RAISERROR(@ErrorStatus,16,1);
5267 END
5268 IF ((LTRIM(RTRIM(@Address1)) <> '') AND (@Address1 IS NOT NULL)) OR @RecordSource = 'FOOD'
5269 BEGIN
5270 EXEC DBO.pInsertAddress @NEWPersonID, @Address1,@Address2, @City,@County,@State,@PostalCOde,@AddressTypeID,@ModifiedBy, @NewAddressID Output,@Succ Output, @ErrorMsg Output ;
5271
5272 IF @Succ =0 --Failed, Rollback!
5273 BEGIN
5274 SET @Success =0;
5275 SELECT @ErrorStatus = '-17200 Sub proc call returned error' + @ErrorMsg;
5276 RAISERROR (@ErrorSTatus, 16,1);
5277 END
5278
5279 END
5280
5281
5282 --Insert Phone Number
5283 --We allow phone number since they may have a cell.
5284 BEGIN
5285 IF ((@RecordSource <> 'FOOD') AND (LTRIM(RTRIM(@PhoneNumber)) ='') OR (LTRIM(RTRIM(@PhoneNumber)) IS NULL) )--This is a problem because Phone Number is required
5286 BEGIN
5287 SET @Succ =0;
5288 SET @ErrorStatus ='-17400 Phone Number Required for Non foodshelf intake.';
5289 RAISERROR(@ErrorStatus,16,1);
5290 END
5291
5292 IF (LTRIM(RTRIM(@PhoneNumber))<>'' AND @PhoneNumber IS NOT NULL)
5293 BEGIN
5294 EXEC DBO.pInsertPhone @NewPersonID,@PhoneNumber, @PhoneExtension,@PhoneTypeID,@ModifiedBy,@NewPhoneID output, @Succ output, @ErrorMsg output ;
5295 END
5296
5297 IF @Succ =0
5298 BEGIN
5299 SET @Success =0;
5300 SELECT @ErrorStatus = '-13200 Sub proc Phone returned fail' + @ErrorMsg;
5301 RAISERROR(@ErrorStatus, 16,1);
5302 END
5303 END
5304
5305 --Insert Demographics
5306 BEGIN
5307 EXEC dbo.pInsertDemographics @NewPersonID,@EducationCategoryID ,@HousingStatus,@NumberInHousehold,@Gender,@Race,@CountryOfOrigin,@Ethnicity,@Disability,@CSFP,@Veteran,@HealthInsurance,@FoodStamps,@HomeboundDelivery,@ModifiedBy,@NewDemographicsID OUTPUT,@Succ OUTPUT, @ErrorMsg OUTPUT;
5308
5309 IF @Succ = 0
5310 BEGIN
5311 SET @Success =0;
5312 SELECT @ErrorStatus ='-13200 Sub proc Demographics returned fail' + @ErrorMsg;
5313 RAISERROR(@ErrorStatus,16,1);
5314
5315 END
5316 END
5317
5318 --Insert Client Notes if they exist. This insert procedure is for the client, so we do not have
5319 --A value for HouseholdMemberPersonID so we hard code it to 0.
5320 IF LTRIM(RTRIM(@notes))<>'' AND @Notes IS NOT NULL
5321 BEGIN
5322 EXEC DBO.pInsertHouseholdNotes @ClientPersonID, @NewPersonID,@Notes,@ModifiedBy,@NewClientNotesID OUTPUT,@Succ OUTPUT,@ErrorMsg OUTPUT;
5323 IF @Succ =0
5324 BEGIN
5325 SET @Success =0
5326 SET @ErrorStatus = '-17001 Insert Failed Notes' + @ErrorMsg;
5327 RAISERROR(@ErrorStatus,16,1);
5328 END
5329
5330 END
5331
5332 --We have everything except for the relationship to the client, so we do that last.
5333
5334
5335 EXEC DBO.pInsertFamilyRelationship @NewPersonIDout, @ClientPersonID,@RelationshipID,@RelationshipDescription,@ModifiedBy, @NewFamilyRelationshipID OUTPUT, @Succ OUTPUT, @ErrorMsg OUTPUT;
5336 IF @Succ =0
5337 BEGIN
5338 SET @Success =0;
5339 SET @ErrorStatus ='-17001 Insert Failed Family Relationship'+ @ErrorMsg
5340 RAISERROR(@ErrorStatus,16,1);
5341 END
5342
5343
5344
5345
5346
5347 --We are using nested transactions to make sure one exists in case
5348 --of a rollback in subordinate Stored Procedure
5349 IF @@TRANCOUNT > 0
5350 BEGIN
5351 SET @Success =1;
5352 SET @ErrorStatus ='';
5353 COMMIT TRANSACTION;
5354 END
5355END
5356END TRY
5357
5358BEGIN CATCH
5359 IF @@TRANCOUNT >0
5360 BEGIN
5361 SET @Success =0
5362 SET @ErrorStatus =@ErrorStatus + ' ' +@@Error
5363 Set @ErrorStatus = @ErrorStatus + 'Failure in pInsertClientFamilyRecordWithAddress'
5364 ROLLBACK TRANSACTION;
5365
5366 RAISERROR(@ErrorStatus,16,1);
5367 END
5368END CATCH
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386GO
5387/****** Object: StoredProcedure [dbo].[pInsertClientRecord] Script Date: 10/16/2020 7:31:03 PM ******/
5388SET ANSI_NULLS ON
5389GO
5390SET QUOTED_IDENTIFIER ON
5391GO
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407-- =============================================
5408-- Author: Gary Savard
5409-- Create date: 26 Oct 2010
5410-- Description: This is the main stored procedure to save a new client
5411-- into the system. It calls several other stored procedures to do inserts into
5412-- selected parts of the DB. Clients and Family members of clients have similar data, but
5413--will use separate stored procedures for clarity.
5414--@RecordSource can be FOOD,WX,MICRO,TENANT,COMMACT,ADMIN. This will be used to only execute parts of the
5415--SP relevant to the client intake data brought in. For example, Foodshelf requires that a record be
5416--set for the type of food taken, but this is not required elsewhere so we only execute that SP If things come from
5417--FOOD. Same idea with the rest of the programs.
5418--IDs that are important such as 'address type' from that lookup table need to be passed in here since they
5419--were selected by the user. No need to try to figure them out in the SP
5420--Certification has its own button so we have a separate stored procedure to deal with that functionality and the same for
5421--family members since they do not have some of the information that we need for the client.
5422
5423--Revisions: 4 Nov 10- Added Client notes insert procedure call
5424
5425---14 March 11 Added functionality for Cell Phone, Mailing Address, FamilyStatus, InsuranceType
5426--19 April, Add @IsUpdateBreadGroceries parameter to avoid inserting bread/produce, groceries if this is not required.
5427--3 May 11, fixed mail address blank records.
5428--11 July 11, Added LTrim,RTRIM @FIRSTNAME, @MiddleName, @LastName
5429-- =============================================
5430CREATE PROCEDURE [dbo].[pInsertClientRecord] (
5431 @RecordSource NVarchar (8), --This allows for the sub sp's to be executed or skipped based on what data is to be saved
5432 @Title NVarchar(8) =NULL,
5433 @FirstName Name,
5434 @MiddleName Name = NULL,
5435 @LastName Name,
5436 @Suffix NVarchar(10) = NULL,
5437 @Gender NVarchar(2) ='',--May not need everywhere
5438 @DateOfBirth DateTime,
5439 @PhysicalAddress1 NVarchar(60) =NULL,--Only for Foodshelf!!
5440 @PhysicalAddress2 NVarchar(60) = NULL,
5441 @PhysicalCity NVarchar(30),
5442 @PhysicalCounty NVarchar(30) = NULL,
5443 @PhysicalState NVarchar(2),
5444 @PhysicalPostalCode NVarchar(10),
5445 @PhysicalAddressTypeID int=0,--This is just addressTypeID, but this name is used to make distinctive in parameters list
5446 @MailAddress1 NVarchar(60) = NULL,
5447 @MailAddress2 NVarchar(60)= NULL,
5448 @MailCity NVarchar(30)=NULL,
5449 @MailCounty NVarchar(30)=NULL,
5450 @MailState NVarchar(2) =NULL,
5451 @MailPostalCode NVarchar(10)=NULL,
5452 @MailAddressTypeID int =0,--From the Lookup based on user input. May not need if Foodshelf
5453 @EmailAddress Nvarchar(50) = NULL,
5454 @EmailContactPreference NoYes =0,
5455 @PhoneNumber Phone ='',
5456 @PhoneExtension Nvarchar(8) ='', --may not be implemented yet
5457 @PhoneTypeID int =0, --Food shelf again!
5458 @PhoneNumber2 Phone ='',
5459 @PhoneExtension2 Nvarchar(8)='',
5460 @PhoneTypeID2 int =0,
5461 @FamilyStatusType Nvarchar(50),
5462 @HousingStatus nVarchar(50),--The TEXT value from the lookup table. Saves having to query by ID later
5463 @Disability NoYesMaybe =0,
5464 @CSFP NoYesMaybe = 0,
5465 @Veteran NoYesMaybe=0,
5466 @HealthInsurance NoYesMaybe =0 ,
5467 @InsuranceType Nvarchar(50),
5468 @FoodStamps NoYesMaybe =0,--Three squares
5469 @HomeboundDelivery NoYesMaybe =0,
5470 @LanguageID int =0,--This is only important for volunteers and that funtionality has not been developed yet.
5471 @IsPrimaryLanguage bit =0,
5472 @EducationCategoryID int =0,
5473 @CountryOfOrigin nVarchar (70)='',
5474 @Race NVarchar(20) =NULL,
5475 @Ethnicity NVarchar(20) =NULL,
5476 @NumberInHousehold int,
5477 @IncomeSourceID int =0,
5478 @Notes NVarchar(MAX)=NULL,--A single person may have many notes. The notes will be specific to a particular program, so we will not have a single notes table
5479 @FoodGiven FoodShelf.GroceryOrBreadProduce,
5480 @FoodReceivedDate DateTime,
5481 @IsUpdateBreadGroceries bit, --This is 1 if there is an update for the record and bread/produce, groceries.
5482 @ModifiedBy Name,
5483 @NewPersonIDout int Output,
5484 @Success bit Output,
5485 @ErrorStatus Nvarchar(50) Output
5486 )
5487AS
5488
5489
5490SET NOCOUNT ON;
5491 DECLARE
5492 @ValidSource int,
5493 @NewPersonID int,
5494 @NewPhysicalAddressID int,
5495 @NewMailAddressID int,
5496 @NewPhoneID int,
5497 @NewPhoneID2 int,
5498 @Succ bit,
5499 @ErrorMsg NVarchar(50),
5500 @NewDemographicsID int, --Not using here, just a place holder!
5501 @NewFoodTypeGivenID int, -- We don't do anything with this. Just receives SP output for now.
5502 @NewClientNotesID int,
5503 @NewIncomeSourceID int
5504
5505 SET @ValidSource =0;
5506 SET @NewPersonID =0;
5507 SET @NewPhysicalAddressID =0;
5508 SET @NewMailAddressID =0;
5509 SET @NewPhoneID = 0;
5510 SET @NewPhoneID2 =0;
5511 SET @NewDemographicsID =0;
5512 SET @NewFoodTypeGivenID =0;
5513 SET @NewClientNotesID =0;
5514 SET @NewIncomeSourceId =0;
5515 SET @Succ =0;
5516 SET @ErrorMsg ='';
5517 SET @FirstName = LTRIM(RTRIM(@FirstName));
5518 SET @MiddleName = LTRIM(RTRIM(@MiddleName));
5519 SET @LastName = LTRIM(RTRIM(@LastName));
5520
5521BEGIN
5522 BEGIN TRY
5523 BEGIN TRANSACTION;
5524
5525
5526 --Take the return value and throw error if 0 because we cannot proceed of we don't know
5527 --which set of sps to call.
5528 SET @ValidSource = DBO.ValidateDataSource(@RecordSource);
5529
5530 IF @ValidSource =0
5531 BEGIN
5532 SET @Success =0;
5533 SELECT @ErrorStatus = '-13100 Invalid Record source';
5534 RAISERROR(@ErrorStatus,16,1) with log;
5535 --Raise Error Here because the source is unknown.
5536 END
5537
5538 --Insert into Person and take the new personID for further use.
5539 BEGIN
5540 EXEC DBO.pInsertPerson @Title,@FirstName,@MiddleName,@LastName,@Suffix, @DateOfBirth,@EmailAddress,@EmailContactPreference,@ModifiedBy,@NewPersonID Output,@Succ Output, @ErrorMsg Output;
5541 SET @NewPersonIDout = @NewPersonID;
5542 IF @Succ =0 -- Failure!
5543 BEGIN
5544 SET @Success = @Succ;
5545 SELECT @ErrorStatus = '-13200 Sub Pro Fail'+ @ErrorMsg;
5546 RAISERROR(@ErrorStatus,16,1) with log;
5547 END
5548 END
5549
5550 --IF the source is from Food Shelf we cannot assume that we will need to call the address or phone SPs because they
5551 --are not required to take that information.
5552 --IF we have a good PersonID returned, we continue to Address
5553
5554
5555 IF @NewPersonID > 0 AND @NewPersonID IS NOT NULL
5556 BEGIN
5557 IF (@RecordSource <> 'FOOD') AND ((LTRIM(RTRIM(@PhysicalAddress1)) ='') OR (LTRIM(RTRIM(@PhysicalAddress1)) IS NULL)) --This is a problem because address is required
5558 BEGIN
5559 SET @Succ =0;
5560 SET @ErrorStatus ='-13300 Address Required for Non foodshelf intake.';
5561 RAISERROR(@ErrorStatus,16,1) with log;
5562 END
5563
5564 IF (((LTRIM(RTRIM(@PhysicalAddress1)) <> '') AND (@PhysicalAddress1 IS NOT NULL))) OR @RecordSource = 'FOOD'
5565 BEGIN
5566 EXEC DBO.pInsertAddress @NewPersonID, @PhysicalAddress1,@PhysicalAddress2, @PhysicalCity,@PhysicalCounty,@PhysicalState,@PhysicalPostalCOde,@PhysicalAddressTypeID,@ModifiedBy, @NewPhysicalAddressID Output,@Succ Output, @ErrorMsg Output ;
5567
5568 IF @Succ =0 --Failed, Rollback!
5569 BEGIN
5570 SET @Success =0;
5571 SELECT @ErrorStatus = '-13200 Sub proc PhyAddr call returned error' + @ErrorMsg;
5572 RAISERROR (@ErrorSTatus, 16,1) with log;
5573 END
5574
5575 END
5576
5577 IF (((LTRIM(RTRIM(@MailAddress1)) <> '') AND (@MailAddress1 IS NOT NULL))) /*OR @RecordSource = 'FOOD' Removed. Not necessary*/
5578 BEGIN
5579 EXEC DBO.pInsertAddress @NewPersonID, @MailAddress1,@MailAddress2, @MailCity,@MailCounty,@MailState,@MailPostalCOde,@MailAddressTypeID,@ModifiedBy, @NewMailAddressID Output,@Succ Output, @ErrorMsg Output ;
5580
5581 IF @Succ =0 --Failed, Rollback!
5582 BEGIN
5583 SET @Success =0;
5584 SELECT @ErrorStatus = '-13200 Sub proc MailAddr call returned error' + @ErrorMsg;
5585 RAISERROR (@ErrorSTatus, 16,1) with log;
5586 END
5587
5588 END
5589
5590 --We now need to check for a mailing address
5591
5592
5593
5594 --Insert Phone Number
5595 BEGIN
5596 IF ((@RecordSource <> 'FOOD') AND (LTRIM(RTRIM(@PhoneNumber)) ='') OR (LTRIM(RTRIM(@PhoneNumber)) IS NULL) )--This is a problem because Phone Number is required
5597 BEGIN
5598 SET @Succ =0;
5599 SET @ErrorStatus ='-13400 Phone Number Required for Non foodshelf intake.';
5600 RAISERROR(@ErrorStatus,16,1) with log;
5601 END
5602
5603 IF (LTRIM(RTRIM(@PhoneNumber))<>'' AND @PhoneNumber IS NOT NULL)
5604 BEGIN
5605 EXEC DBO.pInsertPhone @NewPersonID,@PhoneNumber, @PhoneExtension,@PhoneTypeID,@ModifiedBy,@NewPhoneID output, @Succ output, @ErrorMsg output ;
5606 END
5607
5608 IF @Succ =0
5609 BEGIN
5610 SET @Success =0;
5611 SELECT @ErrorStatus = '-13200 Sub proc Insert phone returned fail' + @ErrorMsg;
5612 RAISERROR(@ErrorStatus, 16,1) with log;
5613 END
5614 END
5615
5616 --Insert Cell Phone. This is not a required field so we do not do the same checks as with regular phone.
5617 IF (LTRIM(RTRIM(@PhoneNumber2))<>'' AND @PhoneNumber2 IS NOT NULL)
5618 BEGIN
5619 EXEC DBO.pInsertPhone @NewPersonID,@PhoneNumber2, @PhoneExtension2,@PhoneTypeID2,@ModifiedBy,@NewPhoneID output, @Succ output, @ErrorMsg output ;
5620 END
5621
5622 IF @Succ =0
5623 BEGIN
5624 SET @Success =0;
5625 SELECT @ErrorStatus = '-13200 Sub proc Insert Phone returned fail' + @ErrorMsg;
5626 RAISERROR(@ErrorStatus, 16,1) with log;
5627 END
5628
5629 --Insert Demographics
5630 BEGIN
5631
5632 EXEC dbo.pInsertDemographics @NewPersonID,@EducationCategoryID ,@HousingStatus,@NumberInHousehold,@Gender,@Race,@CountryOfOrigin,@Ethnicity,@Disability,@CSFP,@Veteran,@HealthInsurance,@FamilyStatusType,@InsuranceType,@FoodStamps,@HomeboundDelivery,@ModifiedBy,@NewDemographicsID OUTPUT,@Succ OUTPUT, @ErrorMsg OUTPUT;
5633
5634 IF @Succ = 0
5635 BEGIN
5636 SET @Success =0;
5637 SELECT @ErrorStatus = '-2021 Insert Failed Demographics' + @ErrorMsg;
5638 RAISERROR(@ErrorStatus,16,1) with log;
5639
5640 END
5641 END
5642
5643 --Insert Income Source. We are doing this directly but it could be put into a stored procedure. This may be modified for multiple entry later on but we assume 1 to 1 relationship a this point
5644 IF @IncomeSourceID <> 0
5645 BEGIN
5646 INSERT INTO PERSON.Income (IncomeSourceID,PersonID,ModifiedBy,ModifiedDate) Values (@IncomeSourceID,@NewPersonID,@ModifiedBy,SYSDATETIME())
5647
5648 END
5649 IF @Succ =0
5650 BEGIN
5651 SET @Success =0;
5652 SET @ErrorStatus = 'Fail on Insert Income';
5653 RAISERROR (@ErrorSTatus,16,1) with log;
5654 END
5655 --Insert Client Notes if they exist. This insert procedure is for the client, so we do not have
5656 --A value for HouseholdMemberPersonID so we hard code it to 0.
5657 IF LTRIM(RTRIM(@notes))<>'' AND @Notes IS NOT NULL
5658 BEGIN
5659 EXEC DBO.pInsertHouseholdNotes @NewPersonID, 0,@Notes,@ModifiedBy,@NewClientNotesID OUTPUT,@Succ OUTPUT,@ErrorMsg OUTPUT;
5660 IF @Succ =0
5661 BEGIN
5662 SET @Success =0
5663 SET @ErrorStatus = '-14001 Insert Failed Notes' + @ErrorMsg;
5664 RAISERROR(@ErrorStatus,16,1) with log;
5665 END
5666
5667 END
5668
5669 --IF source is foodshelf, we need to capture whether they were in for bread/produce or groceries
5670
5671 IF @RecordSource ='FOOD' and @IsUpdateBreadGroceries = 1
5672 BEGIN
5673 EXEC DBO.pInsertFoodTypeGiven @NewPersonID,@FoodReceivedDate,@FoodGiven,@ModifiedBy,@NewFoodTypeGivenID OUTPUT, @Succ OUTPUT, @ErrorMsg OUTPUT;
5674 IF @Succ =0
5675 BEGIN
5676 SET @Success =0;
5677 SELECT @ErrorStatus ='-600021 Insert FoodType fail' + @ErrorMsg;
5678 RAISERROR (@ErrorStatus,16,1) with log;
5679 END
5680 END
5681
5682
5683
5684 --We are using nested transactions to make sure one exists in case
5685 --of a rollback in subordinate Stored Procedure
5686 IF @@TRANCOUNT > 0
5687 BEGIN
5688 SET @Success = 1;
5689 COMMIT TRANSACTION;
5690 END
5691END
5692END TRY
5693
5694BEGIN CATCH
5695 IF @@TRANCOUNT >0
5696 BEGIN
5697 SET @Success = 0
5698 SET @ErrorStatus =@ErrorStatus + ' ' +@@Error
5699 ROLLBACK TRANSACTION;
5700
5701 RAISERROR(@ErrorStatus,16,1) with log;
5702 END
5703END CATCH
5704
5705 -- Insert statements for procedure here
5706 END
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727GO
5728/****** Object: StoredProcedure [dbo].[pInsertContactType] Script Date: 10/16/2020 7:31:03 PM ******/
5729SET ANSI_NULLS ON
5730GO
5731SET QUOTED_IDENTIFIER ON
5732GO
5733
5734
5735
5736
5737
5738/*************************************************************************************************
5739*Author: Gary Savard
5740*Date: 9 Oct 10
5741*Table Name: LUContactType
5742Description: Inserts data to LUContactType.
5743**************************************************************************************************/
5744
5745CREATE PROCEDURE [dbo].[pInsertContactType](
5746 @Name Nvarchar(50) ,
5747 @ModifiedBy Name,
5748 @NewContactTypeID int Output,
5749 @Success bit Output,
5750 @ErrorStatus NVarchar(50) Output
5751 )
5752AS
5753SET NOCOUNT ON;
5754BEGIN
5755 DECLARE
5756 @TempNewContactID int
5757
5758 SET @TempNewContactID =0;
5759 SET @Success = 0;
5760 SET @ErrorStatus ='';
5761
5762
5763/****************************************************************************/
5764
5765
5766
5767 BEGIN
5768 BEGIN TRY
5769 BEGIN TRANSACTION;
5770 SELECT @TempNewContactID = ContactTypeID
5771 FROM person.LUContactType
5772 WHERE Name = Rtrim(Ltrim(@Name))
5773 If @TempNewContactID <>0
5774 BEGIN
5775 SET @ErrorStatus = ' -60022 Contact Type already exists in LUContactType';
5776 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
5777
5778 END
5779
5780/****************************************************************************/
5781
5782 IF @@Error <> 0
5783 BEGIN
5784 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60020';
5785 SET @Success = 0;
5786 RAISERROR(@ErrorStatus, 16,1);
5787 END
5788
5789 INSERT Person.LUContactType(Name,ModifiedDate,ModifiedBy)
5790 VALUES (@Name,SYSDATETIME(),@ModifiedBy)
5791
5792 set @NewContactTypeID =@@IDENTITY;
5793 set @success =1;
5794 set @ErrorStatus =0;
5795 COMMIT TRANSACTION;
5796
5797 END TRY
5798
5799 BEGIN CATCH
5800 ROLLBACK TRANSACTION;
5801 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
5802 --We only care if the error was not raised by SSE
5803 IF @@ERROR <> 50000
5804 BEGIN
5805 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
5806 END
5807 SET @Success =0;
5808 SELECT @ErrorStatus= @ErrorStatus + '-60021 Insert Failed on LUContactType';
5809 RAISERROR(@ErrorStatus, 16, 1);
5810
5811
5812 END CATCH
5813
5814 END
5815END
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826GO
5827/****** Object: StoredProcedure [dbo].[pInsertCountryOfOrigin] Script Date: 10/16/2020 7:31:03 PM ******/
5828SET ANSI_NULLS ON
5829GO
5830SET QUOTED_IDENTIFIER ON
5831GO
5832
5833
5834
5835
5836
5837
5838/*************************************************************************************************
5839*Author: Gary Savard
5840*Date: 9 Oct 10
5841*Table Name: LUCountryOfOrigin
5842Description: Inserts data to LUCountryOfOrigin.
5843**************************************************************************************************/
5844
5845CREATE PROCEDURE [dbo].[pInsertCountryOfOrigin](
5846 @CountryAbbreviation Nvarchar(30) ='',
5847 @CountryName Nvarchar(50),
5848 @FIPSCode NVarchar(2)='',
5849 @ModifiedBy Name,
5850 @NewCountryID int Output,
5851 @Success bit Output,
5852 @ErrorStatus NVarchar(50) Output
5853 )
5854AS
5855SET NOCOUNT ON;
5856BEGIN
5857 DECLARE
5858 @TempNewCountryID int
5859
5860 SET @TempNewCountryID =0;
5861 SET @Success = 0;
5862 SET @ErrorStatus ='';
5863
5864
5865/****************************************************************************/
5866
5867
5868
5869
5870 BEGIN
5871 BEGIN TRY
5872 BEGIN TRANSACTION;
5873 SELECT @TempNewCountryID = CountryID
5874 FROM person.LUCountryOfOrigin
5875 WHERE CountryName = Rtrim(Ltrim(@CountryName))
5876 If @TempNewCountryID <>0
5877 BEGIN
5878 SET @ErrorStatus = ' -60032 Country already exists in LUCountryOfOrigin';
5879 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
5880
5881 END
5882
5883/****************************************************************************/
5884
5885 IF @@Error <> 0
5886 BEGIN
5887 SELECT @ErrorStatus = @@ERROR + '-60030';
5888 SET @Success = 0;
5889 RAISERROR(@ErrorStatus, 16,1);
5890 END
5891 INSERT Person.LUCountryOfOrigin(CountryAbbreviation,CountryName,FIPSCode,ModifiedDate,ModifiedBy)
5892 VALUES (@CountryAbbreviation,@CountryName,@FIPSCode,SYSDATETIME(),@ModifiedBy)
5893
5894 set @NewCountryID =@@IDENTITY;
5895 set @success =1;
5896 set @ErrorStatus =0;
5897 COMMIT TRANSACTION;
5898
5899 END TRY
5900
5901 BEGIN CATCH
5902 ROLLBACK TRANSACTION;
5903 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
5904 --We only care if the error was not raised by SSE
5905 IF @@ERROR <> 50000
5906 BEGIN
5907 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
5908 END
5909 SET @Success =0;
5910 SELECT @ErrorStatus= @ErrorStatus + '-60031 Insert Failed Rollback';
5911 RAISERROR(@ErrorStatus, 16, 1);
5912
5913
5914 END CATCH
5915
5916 END
5917END
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929GO
5930/****** Object: StoredProcedure [dbo].[pInsertCounty] Script Date: 10/16/2020 7:31:03 PM ******/
5931SET ANSI_NULLS ON
5932GO
5933SET QUOTED_IDENTIFIER ON
5934GO
5935
5936
5937
5938
5939
5940
5941/*************************************************************************************************
5942*Author: Gary Savard
5943*Date: 9 Oct 10
5944*Table Name: LUCounty
5945Description: Inserts data to LUCounty.
5946**************************************************************************************************/
5947
5948CREATE PROCEDURE [dbo].[pInsertCounty](
5949 @CountyName NVarchar(20),
5950 @StateID int,
5951 @CityID int = 0,--Default cityID to 0 just in case it comes in later.
5952 @ModifiedBy Name,
5953 @NewCountyID int Output,
5954 @Success bit Output,
5955 @ErrorStatus NVarchar(50) Output
5956 )
5957AS
5958SET NOCOUNT ON;
5959BEGIN
5960 DECLARE
5961 @TempCountyID int
5962
5963 SET @TempCountyID =0;
5964 SET @Success = 0;
5965 SET @ErrorStatus ='';
5966
5967
5968
5969
5970 BEGIN
5971 BEGIN TRY
5972 BEGIN TRANSACTION;
5973 IF @StateID = 0 --Must have a state before we can have a county!
5974 BEGIN
5975 SELECT @ErrorStatus = '-60065 StateID cant be NULL or 0';
5976 SET @Success = 0;
5977 RAISERROR(@ErrorStatus, 16,1);
5978 END
5979
5980/****************************************************************************/
5981
5982 SELECT @TempCountyID = CountyID
5983 FROM person.LUCounty
5984 WHERE CountyName = Rtrim(Ltrim(@CountyName)) and StateID = @StateID
5985 If @TempCountyID <>0
5986 BEGIN
5987 SET @ErrorStatus = ' -60062 County exists in LUCounty';
5988 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
5989
5990 END
5991
5992/****************************************************************************/
5993
5994 IF @@Error <> 0
5995 BEGIN
5996 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60060';
5997 SET @Success = 0;
5998 RAISERROR(@ErrorStatus, 16,1);
5999 END
6000
6001 INSERT Person.LUCounty(StateID,CityID,CountyName, ModifiedDate,ModifiedBy)
6002 VALUES (@StateID,@CityID,@CountyName,SYSDATETIME(),@ModifiedBy)
6003
6004 set @NewCountyID =@@IDENTITY;
6005 set @success =1;
6006 set @ErrorStatus =0;
6007 COMMIT TRANSACTION;
6008
6009 END TRY
6010
6011 BEGIN CATCH
6012 ROLLBACK TRANSACTION;
6013 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
6014 --We only care if the error was not raised by SSE
6015 IF @@ERROR <> 50000
6016 BEGIN
6017 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
6018 END
6019 SET @Success =0;
6020 SELECT @ErrorStatus= @ErrorStatus +'-60061 Insert Failed LUCounty ';
6021 RAISERROR(@ErrorStatus, 16, 1);
6022
6023
6024 END CATCH
6025
6026 END
6027END
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039GO
6040/****** Object: StoredProcedure [dbo].[pInsertDemographics] Script Date: 10/16/2020 7:31:03 PM ******/
6041SET ANSI_NULLS ON
6042GO
6043SET QUOTED_IDENTIFIER ON
6044GO
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064/*************************************************************************************************
6065
6066*Author: Gary Savard
6067*Date: 8 Oct 10
6068*Table Name: Demographics
6069Description: Inserts data to Demographics table
6070Revisions:1 Nov 10. Added housing status to demographics table and altered stored procedures accordingly.
607114 December 10. Added Country of Origin. GS
607214 March 11. Added FamilyStatusType and Insurance Type GS
6073**************************************************************************************************/
6074CREATE PROCEDURE [dbo].[pInsertDemographics](
6075 @PersonID int,
6076 @EducationCategoryID int,
6077 @HousingStatus NVarchar(50)=NULL,
6078 @NumberInHousehold int,
6079 @Gender NVarchar(2) ='',
6080 @Race Nvarchar(20) = NULL,
6081 @CountryOfOrigin NVarchar(70) =NULL,--This could have used an ID, but keeping it simple since end users will be doing own crystal reports.
6082 @Ethnicity Nvarchar(20) = Null,
6083 @Disability NoYesMaybe =0,
6084 @CSFP NoYesMaybe = 0,
6085 @Veteran NoYesMaybe=0,
6086 @HealthInsurance NoYesMaybe=0 ,
6087 @FamilyStatusType Nvarchar(50),
6088 @InsuranceType Nvarchar(50),
6089 @FoodStamps NoYesMaybe =0,
6090 @HomeboundDelivery NoYesMaybe =0,
6091 @ModifiedBy Name,
6092 @NewDemographicsID int Output,
6093 @Success bit Output,
6094 @ErrorStatus Nvarchar(50) Output
6095 )
6096AS
6097SET NOCOUNT ON;
6098BEGIN
6099 DECLARE
6100 @TempDemographicsID int,
6101 @TempPersonId int
6102
6103 SET @TempPersonID =0;
6104 SET @Success = 0;
6105 SET @ErrorStatus ='';
6106 SET @TempDemographicsID =0;
6107
6108
6109
6110
6111 BEGIN
6112 BEGIN TRY
6113 BEGIN TRANSACTION;
6114 SELECT @TempDemographicsID = DemographicsID
6115 FROM person.Demographics
6116 WHERE PersonID = @PersonID
6117
6118 IF @TEMPDemographicsID <> 0 --If not zero then already exists.
6119 BEGIN
6120 SELECT @ErrorStatus = '-2005 DemogID already exists for PersonID';
6121 SET @ErrorStatus =0;
6122 RAISERROR(@ErrorStatus,16,1);
6123 END
6124
6125 IF @@Error <> 0
6126 BEGIN
6127 SELECT @ErrorStatus = CONVERT(nVarchar(20),@@ERROR) + ' -1000';
6128 SET @Success = 0;
6129 RAISERROR(@ErrorStatus, 16, 1);
6130 END
6131
6132 INSERT Person.Demographics(PersonID,
6133 EducationCategoryID,
6134 HousingStatus,
6135 NumberInHousehold,
6136 Gender,
6137 Race,
6138 CountryOfOrigin,
6139 Ethnicity,
6140 Disability,
6141 CSFP,
6142 Veteran,
6143 HealthInsurance,
6144 FamilyStatusType,
6145 InsuranceType,
6146 FoodStamps,
6147 HomeboundDelivery,
6148 ModifiedDate,
6149 ModifiedBy)
6150 VALUES (@PersonID,
6151 @EducationCategoryID,
6152 @HousingStatus,
6153 @NumberInHousehold,
6154 @Gender,
6155 @Race,
6156 @CountryOfOrigin,
6157 @Ethnicity,
6158 @Disability,
6159 @CSFP,
6160 @Veteran,
6161 @HealthInsurance,
6162 @FamilyStatusType,
6163 @InsuranceType,
6164 @FoodStamps,
6165 @HomeboundDelivery,SYSDATETIME(),@ModifiedBy)
6166
6167 set @NewDemographicsID =@@IDENTITY;
6168 set @success =1;
6169 set @ErrorStatus ='';
6170 COMMIT TRANSACTION;
6171
6172 END TRY
6173
6174 BEGIN CATCH
6175 ROLLBACK TRANSACTION;
6176 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
6177 --We only care if the error was not raised by SSE
6178 IF @@ERROR <> 50000
6179 BEGIN
6180 SELECT @ErrorStatus = Convert (Nvarchar(20),@@Error);
6181 END
6182 SET @Success =0;
6183 SELECT @ErrorStatus= @ErrorStatus +'-2001 Insert Fail Demographics';
6184 RAISERROR(@ErrorStatus, 15, 1);
6185
6186
6187 END CATCH
6188
6189 END
6190END
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211GO
6212/****** Object: StoredProcedure [dbo].[pInsertEducationCategory] Script Date: 10/16/2020 7:31:03 PM ******/
6213SET ANSI_NULLS ON
6214GO
6215SET QUOTED_IDENTIFIER ON
6216GO
6217
6218
6219
6220
6221
6222
6223/*************************************************************************************************
6224*Author: Gary Savard
6225*Date: 9 Oct 10
6226*Table Name: LUEducationCategory
6227Description: Inserts data to LUEducationCategory.
6228**************************************************************************************************/
6229
6230CREATE PROCEDURE [dbo].[pInsertEducationCategory](
6231 @EducationLevel NVarchar(50),
6232 @ModifiedBy Name,
6233 @NewEducationCategoryID int Output,
6234 @Success bit Output,
6235 @ErrorStatus NVarchar(50) Output
6236 )
6237AS
6238SET NOCOUNT ON;
6239BEGIN
6240 DECLARE
6241 @TempEducationCategoryID int
6242
6243 SET @TempEducationCategoryID =0;
6244 SET @Success = 0;
6245 SET @ErrorStatus ='';
6246
6247/****************************************************************************/
6248
6249
6250 BEGIN
6251 BEGIN TRY
6252 BEGIN TRANSACTION;
6253
6254 SELECT @TempEducationCategoryID = EducationCategoryID
6255 FROM person.LUEducationCategory
6256 WHERE EducationLevel = Rtrim(Ltrim(@EducationLevel))
6257 If @TempEducationCategoryID <>0
6258 BEGIN
6259 SET @ErrorStatus = ' -60072 Education Catgory aready exists in LUEducationCategory';
6260 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
6261
6262 END
6263
6264/****************************************************************************/
6265
6266 IF @@Error <> 0
6267 BEGIN
6268 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60070';
6269 SET @Success = 0;
6270 RAISERROR(@ErrorStatus, 16,1);
6271 END
6272 INSERT Person.LUEducationCategory(EducationLevel, ModifiedDate,ModifiedBy)
6273 VALUES (@EducationLevel,SYSDATETIME(),@ModifiedBy)
6274
6275 set @NewEducationCategoryID =@@IDENTITY;
6276 set @success =1;
6277 set @ErrorStatus =0;
6278 COMMIT TRANSACTION;
6279
6280 END TRY
6281
6282 BEGIN CATCH
6283 ROLLBACK TRANSACTION;
6284 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
6285 --We only care if the error was not raised by SSE
6286 IF @@ERROR <> 50000
6287 BEGIN
6288 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
6289 END
6290 SET @Success =0;
6291 SELECT @ErrorStatus= @ErrorStatus + '-60071 Insert Failed Education Category';
6292 RAISERROR(@ErrorStatus, 16, 1);
6293
6294
6295 END CATCH
6296
6297 END
6298END
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310GO
6311/****** Object: StoredProcedure [dbo].[pInsertEthnicity] Script Date: 10/16/2020 7:31:03 PM ******/
6312SET ANSI_NULLS ON
6313GO
6314SET QUOTED_IDENTIFIER ON
6315GO
6316
6317
6318
6319
6320
6321
6322/*************************************************************************************************
6323*Author: Gary Savard
6324*Date: 9 Oct 10
6325*Table Name: LUEthnicity
6326Description: Inserts data to LUEthnicity.
6327**************************************************************************************************/
6328CREATE PROCEDURE [dbo].[pInsertEthnicity](
6329 @EthnicityAbbreviation NVarchar(10),
6330 @EthnicityDescription NVarchar(50),
6331 @ModifiedBy Name,
6332 @NewEthnicityID int Output,
6333 @Success bit Output,
6334 @ErrorStatus NVarchar(50) Output
6335 )
6336AS
6337SET NOCOUNT ON;
6338BEGIN
6339 DECLARE
6340 @TempEthnicityID int
6341
6342 SET @TempEthnicityID =0;
6343 SET @Success = 0;
6344 SET @ErrorStatus ='';
6345
6346/****************************************************************************/
6347
6348
6349
6350
6351 BEGIN
6352 BEGIN TRY
6353 BEGIN TRANSACTION;
6354 SELECT @TempEthnicityID = EthnicityID
6355 FROM person.LUEthnicity
6356 WHERE EthnicityAbbreviation = Rtrim(Ltrim(@EthnicityAbbreviation)) --Be a bit paranoid and trim the input for white spaces
6357 If @TempEthnicityID <>0
6358 BEGIN
6359 SET @ErrorStatus = ' -60082 Ethnicity already exists'; --Failed in lookup table
6360 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
6361
6362 END
6363
6364/****************************************************************************/
6365
6366 IF @@Error <> 0
6367 BEGIN
6368 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60080';
6369 SET @Success = 0;
6370 RAISERROR(@ErrorStatus, 16,1);
6371 END
6372
6373 INSERT Person.LUEthnicity(EthnicityAbbreviation,EthnicityDescription, ModifiedDate,ModifiedBy)
6374 VALUES (@EthnicityAbbreviation,@EthnicityDescription,SYSDATETIME(),@ModifiedBy)
6375
6376 set @NewEthnicityID =@@IDENTITY;
6377 set @success =1;
6378 set @ErrorStatus =0;
6379 COMMIT TRANSACTION;
6380
6381 END TRY
6382
6383 BEGIN CATCH
6384 ROLLBACK TRANSACTION;
6385 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
6386 --We only care if the error was not raised by SSE
6387 IF @@ERROR <> 50000
6388 BEGIN
6389 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
6390 END
6391 SET @Success =0;
6392 SELECT @ErrorStatus= @ErrorStatus +'-60081 Insert Failed Ethnicity';
6393 RAISERROR(@ErrorStatus, 16, 1);
6394
6395
6396 END CATCH
6397
6398 END
6399END
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411GO
6412/****** Object: StoredProcedure [dbo].[pInsertFamilyRelationship] Script Date: 10/16/2020 7:31:03 PM ******/
6413SET ANSI_NULLS ON
6414GO
6415SET QUOTED_IDENTIFIER ON
6416GO
6417
6418
6419
6420
6421
6422
6423
6424/*************************************************************************************************
6425*Author: Gary Savard
6426*Date: 9 Oct 10
6427*Table Name: FamilyRelationships
6428Description: Inserts data to FamilyRelationships. Do not confuse with the sp that inserts to the
6429family relationship LU table! This stored procedure is not called directly and its superior sps do the validation, so it is left out
6430**************************************************************************************************/
6431
6432CREATE PROCEDURE [dbo].[pInsertFamilyRelationship](
6433 @PersonID int,
6434 @ClientPersonID int ,
6435 @RelationshipID int,
6436 @RelationshipDescription nVarchar(50)='',
6437 @ModifiedBy Name,
6438 @NewFamilyRelationshipID int Output,
6439 @Success bit Output,
6440 @ErrorStatus NVarchar(50) Output
6441 )
6442AS
6443SET NOCOUNT ON;
6444BEGIN
6445 DECLARE
6446 @TempFamilyRelationshipID int
6447
6448 SET @TempFamilyRelationshipID =0;
6449 SET @Success = 0;
6450 SET @ErrorStatus ='';
6451
6452
6453/****************************************************************************/
6454--This stored procedure is not called directly and its superior sps do the validation, so it is left out
6455
6456 BEGIN TRY
6457 BEGIN TRANSACTION;
6458
6459
6460 IF @@Error <> 0
6461 BEGIN
6462 SELECT @ErrorStatus = Convert(nVarchar(50),@@ERROR) + '-60040';
6463 SET @Success = 0;
6464 RAISERROR(@ErrorStatus, 16,1);
6465 END
6466
6467
6468
6469 BEGIN
6470
6471 INSERT Person.FamilyRelationships(PersonId,ClientPersonID,RelationshipID,RelationDescription,ModifiedDate,ModifiedBy)
6472 VALUES (@PersonID,@ClientPersonID,@RelationshipID,@RelationshipDescription,SYSDATETIME(),@ModifiedBy)
6473
6474 set @NewFamilyRelationshipID =@@IDENTITY;
6475 set @success =1;
6476 set @ErrorStatus =0;
6477 COMMIT TRANSACTION;
6478 END
6479
6480 END TRY
6481
6482 BEGIN CATCH
6483 ROLLBACK TRANSACTION;
6484 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
6485 --We only care if the error was not raised by SSE
6486 IF @@ERROR <> 50000
6487 BEGIN
6488 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
6489 END
6490 SET @Success =0;
6491 SELECT @ErrorStatus= @ErrorStatus +'-18001 Insert Failed on FamilyRelationships';
6492 RAISERROR(@ErrorStatus, 16, 1);
6493
6494
6495 END CATCH
6496
6497 END
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511GO
6512/****** Object: StoredProcedure [dbo].[pInsertFamilyStatusType] Script Date: 10/16/2020 7:31:03 PM ******/
6513SET ANSI_NULLS ON
6514GO
6515SET QUOTED_IDENTIFIER ON
6516GO
6517
6518
6519
6520
6521
6522
6523/*************************************************************************************************
6524*Author: Gary Savard
6525*Date: 14 March 11
6526*Table Name: LUFamilyStatusType
6527Description: Inserts data to pInsertFamilyStatusType
6528**************************************************************************************************/
6529
6530CREATE PROCEDURE [dbo].[pInsertFamilyStatusType](
6531 @FamilyStatusType Nvarchar(50) ,
6532 @ModifiedBy Name,
6533 @NewFamilyStatusTypeID int Output,
6534 @Success bit Output,
6535 @ErrorStatus NVarchar(50) Output
6536 )
6537AS
6538SET NOCOUNT ON;
6539BEGIN
6540 DECLARE
6541 @TempNewFamilyStatusTypeID int
6542
6543 SET @TempNewFamilyStatusTypeID =0;
6544 SET @Success = 0;
6545 SET @ErrorStatus ='';
6546
6547
6548/****************************************************************************/
6549
6550
6551
6552 BEGIN
6553 BEGIN TRY
6554 BEGIN TRANSACTION;
6555 SELECT @NewFamilyStatusTypeID = FamilyStatusTypeID
6556 FROM person.LUFamilyStatusType
6557 WHERE FamilyStatusType = Rtrim(Ltrim(@FamilyStatusType))
6558 If @TempNewFamilyStatusTypeID <>0
6559 BEGIN
6560 SET @ErrorStatus = ' -60022 Insurance Type already exists in LUFamilyStatusType';
6561 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
6562
6563 END
6564
6565/****************************************************************************/
6566
6567 IF @@Error <> 0
6568 BEGIN
6569 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60020';
6570 SET @Success = 0;
6571 RAISERROR(@ErrorStatus, 16,1);
6572 END
6573
6574 INSERT Person.LUFamilyStatusType(FamilyStatusType,ModifiedDate,ModifiedBy)
6575 VALUES (@FamilyStatusType,SYSDATETIME(),@ModifiedBy)
6576
6577 set @NewFamilyStatusTypeID =@@IDENTITY;
6578 set @success =1;
6579 set @ErrorStatus =0;
6580 COMMIT TRANSACTION;
6581
6582 END TRY
6583
6584 BEGIN CATCH
6585 ROLLBACK TRANSACTION;
6586 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
6587 --We only care if the error was not raised by SSE
6588 IF @@ERROR <> 50000
6589 BEGIN
6590 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
6591 END
6592 SET @Success =0;
6593 SELECT @ErrorStatus= @ErrorStatus + '-60021 Insert Failed on LUFamilyStatusType';
6594 RAISERROR(@ErrorStatus, 16, 1);
6595
6596
6597 END CATCH
6598
6599 END
6600END
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612GO
6613/****** Object: StoredProcedure [dbo].[pInsertFoodshelfCertification] Script Date: 10/16/2020 7:31:03 PM ******/
6614SET ANSI_NULLS ON
6615GO
6616SET QUOTED_IDENTIFIER ON
6617GO
6618-- Batch submitted through debugger: SQLQuery6.sql|0|0|C:\Users\gSavard.WIN-QGO8QRSVG73\AppData\Local\Temp\3\~vs5A24.sql
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631/*************************************************************************************************
6632
6633*Author: Gary Savard
6634*Date: 8 Oct 10
6635*Table Name: Foodshelf.Certification, Foodshelf.Signature
6636Description: Inserts Food Shelf Certifications
6637Revisions: 28 March 11. Added CertificationTextID as a parameter
66381 April 2011 Added Paper Certification Logic
6639**************************************************************************************************/
6640CREATE PROCEDURE [dbo].[pInsertFoodshelfCertification](
6641 @PersonID int,
6642 @CertificationDate DateTime,
6643 @Signature NVarchar(MAX),
6644 @ModifiedBy Name,
6645 @CertificationTextID int =0,--Default to this because paper certification does not have an id
6646 @IsPaperCertification bit,
6647 @PaperCertificationDate DateTime,
6648 @NewFoodShelfCertificationID int Output,
6649 @NewSignatureID int Output,
6650 @Success bit Output,
6651 @ErrorStatus Nvarchar(50) Output
6652 )
6653AS
6654SET NOCOUNT ON;
6655BEGIN
6656 DECLARE
6657 @TempPersonId int
6658
6659 SET @TempPersonID =0;
6660 SET @Success = 0;
6661 SET @ErrorStatus ='';
6662
6663
6664 BEGIN
6665 BEGIN TRY
6666 BEGIN TRANSACTION;
6667
6668 --IF @TempPersonID = 0 OR @TempPersonID IS NULL--Person Does Not Exist, Bail!
6669 -- BEGIN
6670 -- SET @Success = 0;
6671 -- SET @ErrorStatus ='-16005 PersonID cant be null/0';
6672 -- RAISERROR(@ErrorStatus,16,1);
6673 -- END
6674
6675 SELECT @TempPersonID = PersonID
6676 FROM person.Person
6677 WHERE PersonID = @PersonID
6678
6679 IF @TempPersonID = 0 OR @TempPersonID IS NULL
6680 BEGIN
6681 SET @Success =0;
6682 SET @ErrorStatus ='-16008 PersonID does not exist in Person';
6683 RAISERROR (@ErrorStatus,16,1);
6684 END
6685
6686 --IF @CertificationTextID =0 OR @CertificationTExtID IS NULL
6687 --BEGIN
6688 -- SET @Success =0;
6689 -- SET @ErrorStatus ='CertificationTextID is mandatory';
6690 -- RAISERROR (@ErrorStatus, 16, 1)
6691 --END
6692
6693 IF @@Error <> 0
6694 BEGIN
6695 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -16000';
6696 SET @Success = 0;
6697 RAISERROR(@ErrorStatus, 16, 1);
6698 END
6699/*IF this is a paper certification then we will have a CertificationTextID of 0*/
6700 INSERT Foodshelf.FoodShelfCertification (PersonID,CertificationTextID,LastCertificationDate,IsPaperCertification,PaperCertificationDate,ModifiedDate,ModifiedBy)
6701 VALUES (@PersonID,@CertificationTextID,@CertificationDate,@IsPaperCertification,@PaperCertificationDate,SYSDATETIME(),@ModifiedBy);
6702
6703 IF @@Error <> 0
6704 BEGIN
6705 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -16001 insert Failed FoodShelfCertification';
6706 SET @Success = 0;
6707 RAISERROR(@ErrorStatus, 16, 1);
6708 END
6709
6710 set @NewFoodshelfCertificationID =@@IDENTITY;
6711 set @success =1;
6712 set @ErrorStatus ='';
6713 --We only call Foodshelf.Signature if this is an electronic certification
6714 If @IsPaperCertification =0
6715 Begin
6716 INSERT Foodshelf.Signature (PersonID,FoodShelfCertificationID,Signature,ModifiedDate, ModifiedBy)
6717 VALUES (@PersonID,@NewFoodshelfCertificationID,@Signature,SYSDATETIME(),@ModifiedBy);
6718 END
6719
6720 IF @@Error <> 0
6721 BEGIN
6722 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -16001 insert Failed Signature';
6723 SET @Success = 0;
6724 RAISERROR(@ErrorStatus, 16, 1);
6725 END
6726 SET @NewSignatureID = @@IDENTITY;
6727 SET @Success =1;
6728 SET @ErrorStatus ='';
6729
6730
6731 COMMIT TRANSACTION;
6732
6733 END TRY
6734
6735 BEGIN CATCH
6736 ROLLBACK TRANSACTION;
6737 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
6738 --We only care if the error was not raised by SSE
6739 IF @@ERROR <> 50000
6740 BEGIN
6741 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
6742 END
6743 SET @Success =0;
6744 SELECT @ErrorStatus= @ErrorStatus +'-16001 Insert Fail Certification ';
6745 RAISERROR(@ErrorStatus, 15, 1);
6746
6747
6748 END CATCH
6749
6750 END
6751END
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765GO
6766/****** Object: StoredProcedure [dbo].[pInsertFoodTypeGiven] Script Date: 10/16/2020 7:31:03 PM ******/
6767SET ANSI_NULLS ON
6768GO
6769SET QUOTED_IDENTIFIER ON
6770GO
6771
6772/*************************************************************************************************
6773*Author: Gary Savard
6774*Date: 9 Oct 10
6775*Table Name: FoodTypeGiven
6776Description: Inserts data to FoodTypeGiven. This SP requires PersonID, to be valid on input
6777in order to capture the appropriate information. ReceivedDate should also be a valid date/time since we need to be able
6778to return up to 90 days history for each client in reports. This date is not tested since we have to assume
6779that the record may have been input on paper for some reason, so we cannot use system date to test validity.
6780**************************************************************************************************/
6781CREATE PROCEDURE [dbo].[pInsertFoodTypeGiven](
6782 @PersonID int ,
6783 @ReceivedDate DateTime,
6784 @FoodGiven FoodShelf.GroceryOrBreadProduce,
6785 @ModifiedBy Name,
6786 @NewFoodTypeGivenID int Output,
6787 @Success bit Output,
6788 @ErrorStatus NVarchar(50) Output
6789 )
6790AS
6791SET NOCOUNT ON;
6792BEGIN
6793 DECLARE
6794 @TempPersonID int
6795
6796 SET @TempPersonID =0;
6797
6798 SET @Success = 0;
6799 SET @ErrorStatus ='';
6800/****************************************************************************/
6801
6802 BEGIN
6803 BEGIN TRY
6804 BEGIN TRANSACTION;
6805 --Make sure that we do not have bad data
6806 IF (@PersonID = 0) OR (@PersonID IS NULL)
6807 BEGIN
6808 SELECT @ErrorStatus = ' -600011 PersonID/ not valid';
6809 SET @Success = 0;
6810 RAISERROR(@ErrorStatus,16,1);
6811 END
6812
6813 --We now have a valid range for each ID, but need to be sure that they exist in the database before trying the insert. We check the PersonProgramServicesUsed
6814 --table since that ties the three IDs together. We have to assume that the record has already been insert to this table since this
6815 --is a child of that table
6816 SELECT @TempPersonID = PersonID
6817 FROM person.Person
6818 WHERE PersonID=@PersonID
6819
6820 IF (@TempPersonID =0) OR (@TempPersonID IS NULL)
6821 BEGIN
6822 SET @ErrorStatus = ' -600014 Person record does not exist in Person';
6823 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
6824
6825 END
6826
6827/****************************************************************************/
6828
6829 IF @@Error <> 0
6830 BEGIN
6831 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-600010';
6832 SET @Success = 0;
6833 RAISERROR(@ErrorStatus, 16,1);
6834 END
6835
6836 INSERT Foodshelf.FoodTypeGiven(PersonID,ReceivedDate,FoodGiven,ModifiedDate,ModifiedBy)
6837 VALUES (@PersonID,@ReceivedDate,@FoodGiven,SYSDATETIME(),@ModifiedBy)
6838
6839 set @NewFoodTypeGivenID =@@IDENTITY;
6840 set @success =1;
6841 set @ErrorStatus =0;
6842 COMMIT TRANSACTION;
6843
6844 END TRY
6845
6846 BEGIN CATCH
6847 ROLLBACK TRANSACTION;
6848 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
6849 --We only care if the error was not raised by SSE
6850 IF @@ERROR <> 50000
6851 BEGIN
6852 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
6853 END
6854 SET @Success =0;
6855 SELECT @ErrorStatus= @ErrorStatus + '-600011 Insert Failed on FoodTypeGiven';
6856 RAISERROR(@ErrorStatus, 16, 1);
6857
6858 END CATCH
6859 END
6860END
6861
6862
6863
6864GO
6865/****** Object: StoredProcedure [dbo].[pInsertHouseholdNotes] Script Date: 10/16/2020 7:31:03 PM ******/
6866SET ANSI_NULLS ON
6867GO
6868SET QUOTED_IDENTIFIER ON
6869GO
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884/*************************************************************************************************
6885*Author: Gary Savard
6886*Date: 2 NOV 10
6887*Table Name: FoodShelf.Household Notes
6888Description: Inserts data to FoodShelf.HouseHoldNotes table.This table is for the notes associated with the
6889food shelf intake screens. There are 3 ID fields, the HouseholdNotesID is the identity. ClientPersonID
6890is the PersonID of the individual on which the note was written. The HouseholdMemberPersonID is optional, and
6891If this person is not the client, but a household member, this value will be the Client's personID. We
6892may not need this field, but it is added for potential future functionality
6893Revisions:
6894**************************************************************************************************/
6895
6896CREATE PROCEDURE [dbo].[pInsertHouseholdNotes](
6897 @ClientPersonID int,
6898 @HouseholdMemberPersonID int,
6899 @Notes Nvarchar(MAX),
6900 @ModifiedBy Name,
6901 @NewHouseholdNotesID int Output,
6902 @Success bit Output,
6903 @ErrorStatus Nvarchar(50) Output
6904 )
6905AS
6906SET NOCOUNT ON;
6907BEGIN
6908 DECLARE
6909 @TempHouseholdNotesID int,
6910 @TempClientPersonID int,
6911 @TempHouseholdMemberPersonID int
6912
6913 SET @TempHouseholdNotesID =0;
6914 SET @TempClientPersonID = 0;
6915 SET @Success = 0;
6916 SET @ErrorStatus ='';
6917
6918
6919
6920
6921 BEGIN TRY
6922 BEGIN TRANSACTION;
6923 /****************************************************************************/
6924 --Validate both IDs coming in. Only the ClientPersonID is mandatory, so we check the HouseholdMemberPersonID only if it is not
6925 --0 or NULL
6926 SELECT @TempClientPersonID = PersonID
6927 FROM person.Person
6928 WHERE PersonID = @ClientPersonID
6929
6930 If @TempClientPersonID = 0 or @TempClientPersonID IS NULL
6931 BEGIN
6932 SET @ErrorStatus = ' -14032 ClientPersonID does not exist in Person'; --Failed in person table
6933 SET @Success =0;
6934 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
6935
6936 END
6937
6938 --Since this is an optional field, we only check it if it has a value other than 0 or NULL
6939 IF @HouseholdMemberPersonID <> 0 AND @HouseholdMemberPersonID IS NOT NULL
6940 BEGIN
6941 SELECT @TempHouseholdMemberPersonID = @HouseholdMemberPersonID
6942 FROM Person.Person
6943 WHERE PersonID = @HouseholdMemberPersonID
6944
6945 IF @TempHouseholdMemberPersonID = 0 OR @TempHouseholdMemberPersonID IS NULL
6946 BEGIN
6947 SET @ErrorStatus =' -14016 HouseholdMemberPersonID does not exist, though not NULL/0';
6948 SET @Success =0;
6949 RAISERROR(@ErrorStatus,16,1);
6950 END
6951 END
6952
6953 /****************************************************************************/
6954
6955
6956 IF @@Error <> 0
6957 BEGIN
6958 SELECT @ErrorStatus = Convert(nVarchar(50),@@ERROR) + '-14000';
6959 SET @Success = 0;
6960 RAISERROR (@ErrorStatus,16,1);
6961 END
6962
6963 INSERT Foodshelf.HouseholdNotes (ClientPersonID, HouseholdMemberPersonID, Notes,ModifiedBy, ModifiedDate)
6964 Values(@ClientPersonID,@HouseholdMemberPersonID,@Notes,@ModifiedBy,SYSDATETIME());
6965
6966 SET @NewHouseholdNotesID =@@IDENTITY;
6967 SET @success =1;
6968 SET @ErrorStatus =0;
6969 COMMIT TRANSACTION;
6970
6971 END TRY
6972
6973 BEGIN CATCH
6974 ROLLBACK TRANSACTION;
6975 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
6976 --We only care if the error was not raised by SSE
6977 IF @@ERROR <> 50000
6978 BEGIN
6979 SET @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
6980 END
6981
6982
6983 SELECT @ErrorStatus =@ErrorStatus + ' -14001' +' Insert Failed HouseholdNotes';
6984 SET @Success =0;
6985
6986 RAISERROR(@ErrorStatus, 16, 1);
6987
6988
6989 END CATCH
6990
6991
6992END
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008GO
7009/****** Object: StoredProcedure [dbo].[pInsertHouseholdTransferOptions] Script Date: 10/16/2020 7:31:03 PM ******/
7010SET ANSI_NULLS ON
7011GO
7012SET QUOTED_IDENTIFIER ON
7013GO
7014
7015
7016
7017/*************************************************************************************************
7018*Author: Gary Savard
7019*Date: 22 April 11
7020*Table Name: LUInsertHouseholdTransferOptions
7021Description: Inserts data to LUInsertHouseholdTransferOptions. This is a free format input so there is
7022a strong possibility that we will have duplicates, but those should be easily eliminated by the maintenance screens.
7023Revisions:
7024
7025**************************************************************************************************/
7026CREATE PROCEDURE [dbo].[pInsertHouseholdTransferOptions](
7027 @ActionToTake Nvarchar(50),
7028 @ActionToTakeDescription NVarchar(MAX),
7029 @ModifiedBy Name,
7030 @NewActionToTakeID int Output,
7031 @Success bit Output,
7032 @ErrorStatus Nvarchar(50) Output
7033 )
7034AS
7035SET NOCOUNT ON;
7036
7037BEGIN
7038 DECLARE
7039 @TempActionToTakeID int
7040
7041 SET @TempActionToTakeID =0;
7042 SET @Success = 0;
7043 SET @ErrorStatus ='';
7044
7045
7046
7047
7048
7049 BEGIN TRY
7050 BEGIN TRANSACTION;
7051
7052 /****************************************************************************/
7053 --Avoid Duplicate Rows! However, a typo on input such as 'Hmoe' instead of 'Home' will do an isert.
7054 --Can't avoid finger problems!
7055
7056 SELECT @TempActionToTakeID = HouseholdTransferActionID
7057 FROM dbo.LUHouseholdTransferOptions
7058 WHERE ActionToTake = Rtrim(Ltrim(@ActionToTake)) --Be a bit paranoid and trim the input for white spaces
7059 If @TempActionToTakeID <> 0 --Already Exists
7060 BEGIN
7061 SELECT @ErrorStatus = '-7015 Action Already Exists';
7062 SET @Success =0;
7063 RAISERROR(@ErrorStatus, 16, 1);
7064 END
7065
7066 /****************************************************************************/
7067
7068 IF @@Error <> 0
7069 BEGIN
7070 SELECT @ErrorStatus = Convert (nVarchar(50),@@ERROR) + ' -6010';
7071 SET @Success = 0;
7072 RAISERROR(@ErrorStatus, 16, 1);
7073 END
7074
7075
7076 INSERT dbo.LUHouseholdTransferOptions(ActionToTake,ActionToTakeDescription,ModifiedDate, ModifiedBy)
7077 VALUES (@ActionToTake,@ActionToTakeDescription,SYSDATETIME(),@ModifiedBy)
7078
7079 set @NewActionToTakeID =@@IDENTITY;
7080 set @success =1;
7081 set @ErrorStatus ='';
7082 COMMIT TRANSACTION;
7083
7084 END TRY
7085
7086 BEGIN CATCH
7087
7088 ROLLBACK TRANSACTION;
7089 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
7090 --We only care if the error was not raised by SSE
7091 IF @@ERROR <> 50000
7092 BEGIN
7093 SET @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
7094 END
7095
7096
7097 SET @Success =0;
7098 SELECT @ErrorStatus = @ErrorStatus + 'Rollback -6011';
7099 RAISERROR(@ErrorStatus, 16, 1);
7100
7101
7102 END CATCH
7103
7104
7105END
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115GO
7116/****** Object: StoredProcedure [dbo].[pInsertHousingStatus] Script Date: 10/16/2020 7:31:03 PM ******/
7117SET ANSI_NULLS ON
7118GO
7119SET QUOTED_IDENTIFIER ON
7120GO
7121
7122
7123
7124
7125/*************************************************************************************************
7126*Author: Gary Savard
7127*Date: 9 Oct 10
7128*Table Name: LUHousingStatus
7129Description: Inserts data to LUHousingStatus.
7130**************************************************************************************************/
7131
7132CREATE PROCEDURE [dbo].[pInsertHousingStatus](
7133 @HousingStatus NVarchar(20),
7134 @ModifiedBy Name,
7135 @NewHousingStatusID int Output,
7136 @Success bit Output,
7137 @ErrorStatus NVarchar(50) Output
7138 )
7139AS
7140SET NOCOUNT ON;
7141BEGIN
7142 DECLARE
7143 @TempHousingStatusID int
7144
7145 SET @TempHousingStatusID =0;
7146 SET @Success = 0;
7147 SET @ErrorStatus ='';
7148
7149
7150
7151 BEGIN TRY
7152 BEGIN TRANSACTION;
7153 /****************************************************************************/
7154
7155 SELECT @NewHousingStatusID = HousingStatusID
7156 FROM person.LUHousingStatus
7157 WHERE HousingStatus = Rtrim(Ltrim(@HousingStatus)) --Be a bit paranoid and trim the input for white spaces
7158 If @TempHousingStatusID <>0
7159 BEGIN
7160 SET @ErrorStatus = ' -60092 already exists LUHousingStatus'; --Failed in lookup table
7161 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
7162
7163 END
7164
7165 /****************************************************************************/
7166
7167 IF @@Error <> 0
7168 BEGIN
7169 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60020';
7170 SET @Success = 0;
7171 RAISERROR(@ErrorStatus, 16,1);
7172 END
7173
7174 BEGIN
7175
7176 INSERT Person.LUHousingStatus(HousingStatus, ModifiedDate,ModifiedBy)
7177 VALUES (@HousingStatus,SYSDATETIME(),@ModifiedBy)
7178
7179 set @NewHousingStatusID =@@IDENTITY;
7180 set @success =1;
7181 set @ErrorStatus =0;
7182 COMMIT TRANSACTION;
7183 END
7184
7185
7186
7187 END TRY
7188
7189 BEGIN CATCH
7190 ROLLBACK TRANSACTION;
7191 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
7192 --We only care if the error was not raised by SSE
7193 IF @@ERROR <> 50000
7194 BEGIN
7195 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
7196 END
7197 SET @Success =0;
7198 SELECT @ErrorStatus= @ErrorStatus + +'-60021 Insert Failed Housing Status';
7199 RAISERROR(@ErrorStatus, 16, 1);
7200
7201
7202 END CATCH
7203
7204END
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214GO
7215/****** Object: StoredProcedure [dbo].[pInsertIncomeSource] Script Date: 10/16/2020 7:31:03 PM ******/
7216SET ANSI_NULLS ON
7217GO
7218SET QUOTED_IDENTIFIER ON
7219GO
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230/*************************************************************************************************
7231
7232*Author: Gary Savard
7233*Date: 8 Oct 10
7234*Table Name: Address
7235Description: Inserts data to LUIncomeSource table.
7236Revisions:
7237**************************************************************************************************/
7238
7239CREATE PROCEDURE [dbo].[pInsertIncomeSource](
7240 @IncomeSourceAbbreviation NVarchar(10),
7241 @IncomeSourceDescription Nvarchar(50),
7242 @ModifiedBy Name,
7243 @NewIncomeSourceID int Output,
7244 @Success bit Output,
7245 @ErrorStatus Nvarchar(50) Output
7246 )
7247AS
7248SET NOCOUNT ON;
7249BEGIN
7250 DECLARE
7251 @TempIncomeSourceID int
7252
7253 SET @TempIncomeSourceID =0;
7254 SET @Success = 0;
7255 SET @ErrorStatus ='';
7256
7257
7258/****************************************************************************/
7259
7260
7261 BEGIN TRY
7262 BEGIN TRANSACTION;
7263 --the address, so we need to be sure that the data matches an address type before continuing.
7264 SELECT @TempIncomeSourceID = IncomeSourceID
7265 FROM person.LUIncomeSource
7266 WHERE IncomeSourceAbbreviation = Rtrim(Ltrim(@IncomeSourceAbbreviation)) --Be a bit paranoid and trim the input for white spaces
7267
7268 If @TempIncomeSourceID <> 0
7269 BEGIN
7270 SET @ErrorStatus = ' -6092 Income Source exists in LUIncomeSource'; --Failed in lookup table
7271 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
7272
7273 END
7274/****************************************************************************/
7275
7276 IF @@Error <> 0
7277 BEGIN
7278 SELECT @ErrorStatus = @@ERROR + '-6090';
7279 SET @Success = 0;
7280 RAISERROR (@ErrorStatus,16,1);
7281 END
7282
7283
7284
7285 INSERT Person.LUIncomeSource(IncomeSourceAbbreviation,IncomeSourceDescription,ModifiedDate, ModifiedBy)
7286 VALUES (@IncomeSourceAbbreviation, @IncomeSourceDescription, SYSDATETIME(),@ModifiedBy)
7287
7288 set @NewIncomeSourceID =@@IDENTITY;
7289 set @success =1;
7290 set @ErrorStatus =0;
7291 COMMIT TRANSACTION;
7292
7293 END TRY
7294
7295 BEGIN CATCH
7296 ROLLBACK TRANSACTION;
7297 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
7298 --We only care if the error was not raised by SSE
7299 IF @@ERROR <> 50000
7300 BEGIN
7301 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
7302 END
7303 SELECT @ErrorStatus =@ErrorStatus + ' -6091' +' Insert Failed LUIncomeSource';
7304 SET @Success =0;
7305
7306 RAISERROR(@ErrorStatus, 16, 1);
7307
7308
7309 END CATCH
7310
7311
7312END
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324GO
7325/****** Object: StoredProcedure [dbo].[pInsertInsuranceType] Script Date: 10/16/2020 7:31:03 PM ******/
7326SET ANSI_NULLS ON
7327GO
7328SET QUOTED_IDENTIFIER ON
7329GO
7330
7331
7332
7333
7334
7335
7336/*************************************************************************************************
7337*Author: Gary Savard
7338*Date: 14 March 11
7339*Table Name: LUInsuranceType
7340Description: Inserts data to pInsertInsuranceType
7341**************************************************************************************************/
7342
7343CREATE PROCEDURE [dbo].[pInsertInsuranceType](
7344 @InsuranceType Nvarchar(50) ,
7345 @ModifiedBy Name,
7346 @NewInsuranceTypeID int Output,
7347 @Success bit Output,
7348 @ErrorStatus NVarchar(50) Output
7349 )
7350AS
7351SET NOCOUNT ON;
7352BEGIN
7353 DECLARE
7354 @TempNewInsuranceTypeID int
7355
7356 SET @TempNewInsuranceTypeID =0;
7357 SET @Success = 0;
7358 SET @ErrorStatus ='';
7359
7360
7361/****************************************************************************/
7362
7363
7364
7365 BEGIN
7366 BEGIN TRY
7367 BEGIN TRANSACTION;
7368 SELECT @NewInsuranceTypeID = InsuranceTypeID
7369 FROM person.LUInsuranceType
7370 WHERE InsuranceType = Rtrim(Ltrim(@InsuranceType))
7371 If @TempNewInsuranceTypeID <>0
7372 BEGIN
7373 SET @ErrorStatus = ' -60022 Insurance Type already exists in LUInsuranceType';
7374 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
7375
7376 END
7377
7378/****************************************************************************/
7379
7380 IF @@Error <> 0
7381 BEGIN
7382 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60020';
7383 SET @Success = 0;
7384 RAISERROR(@ErrorStatus, 16,1);
7385 END
7386
7387 INSERT Person.LUInsuranceType(InsuranceType,ModifiedDate,ModifiedBy)
7388 VALUES (@InsuranceType,SYSDATETIME(),@ModifiedBy)
7389
7390 set @NewInsuranceTypeID =@@IDENTITY;
7391 set @success =1;
7392 set @ErrorStatus =0;
7393 COMMIT TRANSACTION;
7394
7395 END TRY
7396
7397 BEGIN CATCH
7398 ROLLBACK TRANSACTION;
7399 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
7400 --We only care if the error was not raised by SSE
7401 IF @@ERROR <> 50000
7402 BEGIN
7403 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
7404 END
7405 SET @Success =0;
7406 SELECT @ErrorStatus= @ErrorStatus + '-60021 Insert Failed on LUInsuranceType';
7407 RAISERROR(@ErrorStatus, 16, 1);
7408
7409
7410 END CATCH
7411
7412 END
7413END
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425GO
7426/****** Object: StoredProcedure [dbo].[pInsertJournalClientFamilyChanges] Script Date: 10/16/2020 7:31:03 PM ******/
7427SET ANSI_NULLS ON
7428GO
7429SET QUOTED_IDENTIFIER ON
7430GO
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442/*************************************************************************************************
7443*Author: Gary Savard
7444*Date: 25 April 2011
7445*Table Name: JournalClientFamilyChanges
7446Description: Inserts data to journal requested changes to a family member's household. A volunteer doing intake
7447may find that a household member potentially exists under a different client. The volunteer checks an appropriate box
7448for investigation, changes. The request is stored here along with the previous and new client's ID, if appropriate since
7449there may be reason to delete one of the persons involved.
7450
745113 July 11 - Temporarily removed check for @PreviousClientID
7452**************************************************************************************************/
7453
7454
7455
7456CREATE PROCEDURE [dbo].[pInsertJournalClientFamilyChanges](
7457 @HouseholdMembersID int ,
7458 @PreviousClientsID int ,
7459 @NewClientsID int,
7460 @ActionTaken nVarchar(50),
7461 @Notes nVarchar(MAX),
7462 @ModifiedBy Name,
7463 @Success bit Output,
7464 @ErrorStatus NVarchar(50) Output
7465 )
7466AS
7467SET NOCOUNT ON;
7468
7469BEGIN
7470
7471
7472-- SET @Success =0;
7473-- SET @ErrorStatus ='';
7474
7475
7476/****************************************************************************/
7477
7478 BEGIN TRY
7479 BEGIN TRANSACTION;
7480
7481
7482 IF @@Error <> 0
7483 BEGIN
7484 SELECT @ErrorStatus = Convert(nVarchar(50),@@ERROR) + '-60040';
7485 SET @Success = 0;
7486 RAISERROR(@ErrorStatus, 16,1);
7487 END
7488
7489 --Checking for some things that have to have a value
7490 IF @HouseholdMembersID =0 OR @HouseholdMembersID IS NULL
7491 BEGIN
7492 SELECT @ErrorStatus ='Household Member ID cannot be null or 0';
7493 SET @Success =0;
7494 RAISERROR (@Errorstatus,16,1);
7495 END
7496 --Do them individually instead of one big IF statement for clarity
7497 --IF @PreviousClientsID = 0 or @PreviousClientsID IS NULL
7498 -- BEGIN
7499 -- SELECT @ErrorStatus ='PreviousClientsID cannot be null or 0';
7500 -- SET @Success =0;
7501 -- RAISERROR(@ErrorSTatus,16,1);
7502 -- END
7503-- This could be a delete request so we do not care if @NewClientsID is null or 0
7504--
7505
7506--Must have an action
7507 IF @ActionTaken IS NULL or @ActionTaken =''
7508 BEGIN
7509 SELECT @ErrorStatus ='Action taken must have a value';
7510 SET @Success =0;
7511 RAISERROR(@ErrorSTatus,16,1);
7512 END
7513
7514
7515 BEGIN
7516
7517 --Add the entry
7518 INSERT dbo.JournalClientFamilyChanges
7519 (
7520 HouseholdMembersID,
7521 PreviousClientsID,
7522 NewClientsID,
7523 ActionTaken,
7524 Notes,
7525 ModifiedBy,
7526 ModifiedDate
7527 )
7528 VALUES
7529 (
7530 @HouseholdMembersID,
7531 @PreviousClientsID,
7532 @NewClientsID,
7533 @ActionTaken,
7534 @Notes,
7535 @ModifiedBy,
7536 SYSDATETIME()
7537
7538 )
7539
7540
7541 SET @success =1;
7542 SET @ErrorStatus ='';
7543 COMMIT TRANSACTION;
7544 END
7545
7546 END TRY
7547
7548 BEGIN CATCH
7549 ROLLBACK TRANSACTION;
7550 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
7551 --We only care if the error was not raised by SSE
7552 IF @@ERROR <> 50000
7553 BEGIN
7554 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
7555 END
7556 SET @Success =0;
7557 SELECT @ErrorStatus= @ErrorStatus +'-18001 Insert Failed on JournalClientFamilyChanges';
7558 RAISERROR(@ErrorStatus, 16, 1);
7559
7560
7561 END CATCH
7562
7563 END
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581GO
7582/****** Object: StoredProcedure [dbo].[pInsertJournalLookupTableChanges] Script Date: 10/16/2020 7:31:03 PM ******/
7583SET ANSI_NULLS ON
7584GO
7585SET QUOTED_IDENTIFIER ON
7586GO
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599/*************************************************************************************************
7600*Author: Gary Savard
7601*Date: 25 April 2011
7602*Table Name: JournalLookupTableChanges
7603Description: Inserts data to journal requested changes to Lookup tables..
7604**************************************************************************************************/
7605
7606
7607CREATE PROCEDURE [dbo].[pInsertJournalLookupTableChanges](
7608 @LUChangeTable LUTableChanges READONLY,
7609 @ModifiedBy Name
7610
7611 )
7612AS
7613SET NOCOUNT ON;
7614
7615BEGIN
7616DECLARE
7617@ROWCOUNT int,
7618@LoopCount int
7619
7620SET @ROWCOUNT=0;
7621SET @LoopCount =1;
7622
7623
7624
7625/****************************************************************************/
7626
7627 BEGIN TRY
7628 BEGIN TRANSACTION;
7629 --How many records do we process
7630 SELECT @ROWCOUNT = (SELECT COUNT(*) FROM @LUChangeTable)
7631
7632 BEGIN
7633
7634 --WHILE @LoopCount<=@RowCount
7635 -- BEGIN
7636
7637
7638 --Add the entry
7639 INSERT INTO dbo.JournalLookupTableChanges
7640 (
7641 TableName,
7642 ActionTaken,
7643 OldValue,
7644 OldLUTableID,
7645 NewValue,
7646 ModifiedBy,
7647 ModifiedDate
7648 )
7649 SELECT t.TableName, t.ActionTaken, t.OldValue,t.OldLUTableID, t.NewValue,@ModifiedBy,SYSDATETIME() from @LUChangeTable as t
7650 --VALUES
7651 -- (
7652 -- @TableName,
7653 -- @ActionTaken,
7654 -- @OldValue,
7655 -- @OldLUTableID,
7656 -- @NewValue,
7657 -- @ModifiedBy,
7658 -- SYSDATETIME()
7659 -- )
7660 -- SET @LoopCount =@LoopCount +1
7661 --END--End While @Rowcount
7662
7663
7664
7665 COMMIT TRANSACTION;
7666 END
7667
7668 END TRY
7669
7670 BEGIN CATCH
7671 ROLLBACK TRANSACTION;
7672 --Not doing error handling in this sp. Not needed other than rollback
7673
7674
7675 END CATCH
7676
7677 END
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696GO
7697/****** Object: StoredProcedure [dbo].[pInsertLanguage] Script Date: 10/16/2020 7:31:03 PM ******/
7698SET ANSI_NULLS ON
7699GO
7700SET QUOTED_IDENTIFIER ON
7701GO
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711/*************************************************************************************************
7712*Author: Gary Savard
7713*Date: 15 Oct 10
7714*Table Name: LULanguage
7715Description: Inserts data to LULangage. This table Contains the most common languages and dialects in the world.Dialects
7716are comma demlmited. Example: Chinese, Mandarin.
7717Revisions:
7718**************************************************************************************************/
7719
7720CREATE PROCEDURE [dbo].[pInsertLanguage](
7721 @LanguageName Nvarchar(50),
7722 @ModifiedBy Name,
7723 @NewLanguageID int Output,
7724 @Success bit Output,
7725 @ErrorStatus Nvarchar(50) Output
7726 )
7727AS
7728SET NOCOUNT ON;
7729BEGIN
7730 DECLARE
7731 @TempLanguageID int
7732
7733 SET @TempLanguageID =0;
7734 SET @Success = 0;
7735 SET @ErrorStatus ='';
7736
7737
7738 BEGIN TRY
7739 BEGIN TRANSACTION;
7740 /****************************************************************************/
7741 --Since some languages are comma delimited by dialect, we will use Soundex to test if the language already exists
7742 --in the db
7743 SELECT @TempLanguageID = LanguageID
7744 FROM person.LULanguage
7745 WHERE LanguageName = Soundex(Rtrim(Ltrim(@LanguageName))) --Be a bit paranoid and trim the input for white spaces
7746
7747
7748 /****************************************************************************/
7749 IF @@Error <> 0
7750 BEGIN
7751 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6060';
7752 SET @Success = 0;
7753 RAISERROR(@ErrorStatus,16,1);
7754 END
7755
7756
7757 IF @TempLanguageID = 0 --If they don't exist in the database then
7758 BEGIN
7759
7760 INSERT Person.LULanguage (LanguageName,ModifiedDate, ModifiedBy)
7761 VALUES (@LanguageName,SYSDATETIME(),@ModifiedBy)
7762
7763 set @NewLanguageID =@@IDENTITY;
7764 set @success =1;
7765 set @ErrorStatus =0;
7766 COMMIT TRANSACTION;
7767 END
7768
7769 END TRY
7770
7771 BEGIN CATCH
7772 ROLLBACK TRANSACTION;
7773 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
7774 --We only care if the error was not raised by SSE
7775 IF @@ERROR <> 50000
7776 BEGIN
7777 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
7778 END
7779 SET @Success =0;
7780 SELECT @ErrorStatus= @ErrorStatus + 'LULanguage-6061';
7781 RAISERROR(@ErrorStatus, 16, 1);
7782
7783
7784 END CATCH
7785
7786 END
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798GO
7799/****** Object: StoredProcedure [dbo].[pInsertLanguagesSpoken] Script Date: 10/16/2020 7:31:03 PM ******/
7800SET ANSI_NULLS ON
7801GO
7802SET QUOTED_IDENTIFIER ON
7803GO
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814/*************************************************************************************************
7815*Author: Gary Savard
7816*Date: 15 Oct 10
7817*Table Name: LanguagesSpoken
7818Description: Inserts data to LanguagesSpoken. An individual may speak more than one language so this is assumed to
7819be one to many. We need to check to ensure the languageID exists in the language lookup table.
7820Revisions:
7821**************************************************************************************************/
7822
7823CREATE PROCEDURE [dbo].[pInsertLanguagesSpoken](
7824 @LanguageID int,
7825 @PersonID int,
7826 @IsPrimaryLanguage bit,
7827 @ModifiedBy Name,
7828 @NewLanguagesSpokenID int Output,
7829 @Success bit Output,
7830 @ErrorStatus Nvarchar(50) Output
7831 )
7832AS
7833SET NOCOUNT ON;
7834BEGIN
7835 DECLARE
7836 @TempLanguageID int,
7837 @TempPersonID int,
7838 @TempLanguagesSpokenID int
7839
7840 SET @TempLanguageID =0;
7841 SET @TempPersonId =0;
7842 SET @TempLanguagesSpokenID =0;
7843 SET @Success = 0;
7844 SET @ErrorStatus ='';
7845
7846
7847 BEGIN TRY
7848 BEGIN TRANSACTION;
7849 /****************************************************************************/
7850 IF ((@PersonID = 0) OR (@PersonID IS NULL)) OR ((@LanguageID =0) OR (@LanguageID IS NULL))
7851 BEGIN
7852 SELECT @ErrorStatus = '-11005 PersonID/LanguageID cant be 0/NULL';
7853 SET @Success =0;
7854 RAISERROR(@ErrorStatus,16,1);
7855 END
7856
7857 SELECT @TempLanguageID = LanguageID
7858 FROM person.LULanguage
7859 WHERE LanguageID = @LanguageID
7860
7861 SELECT @TempPersonID = PersonID
7862 FROM Person.Person
7863 Where PersonID = @PersonID
7864
7865 IF @TempLanguageID = 0 OR @TempLanguageID IS NULL
7866 BEGIN
7867 SELECT @ErrorStatus ='-11008 LanguageID does not exist in LULanguage';
7868 SET @Success =0;
7869 RAISERROR(@ErrorStatus,16,1);
7870 END
7871 IF @TempPersonID = 0 OR @TempPersonID IS NULL
7872 BEGIN
7873 SELECT @ErrorStatus ='-11008 PersonID does not exist in Person';
7874 SET @Success=0;
7875 RAISERROR(@ErrorStatus,16,1);
7876 END
7877
7878 --Final check to be sure this is not a duplicate
7879
7880 SELECT @TempLanguagesSpokenID = LanguagesSpokenID
7881 FROM Person.LanguagesSpoken
7882 WHERE LanguageID = @LanguageID AND PersonID =@PersonID
7883
7884 IF @TempLanguagesSpokenID <> 0
7885 --This already exists! Duplicate Row Error
7886 BEGIN
7887 SELECT @ErrorStatus = '-11009 Duplicate Row Exists';
7888 SET @Success =0;
7889 RAISERROR(@ErrorStatus,16,1);
7890 END
7891
7892
7893
7894 /****************************************************************************/
7895 IF @@Error <> 0
7896 BEGIN
7897 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6060';
7898 SET @Success = 0;
7899 RAISERROR(@ErrorStatus,16,1);
7900 END
7901
7902
7903 --If they don't exist in the database then
7904
7905
7906 INSERT Person.LanguagesSpoken(LanguageID,PersonID,IsPrimaryLanguage,ModifiedDate, ModifiedBy)
7907 VALUES (@LanguageID,@PersonID,@IsPrimaryLanguage,SYSDATETIME(),@ModifiedBy)
7908
7909 set @NewLanguagesSpokenID =@@IDENTITY;
7910 set @success =1;
7911 set @ErrorStatus =0;
7912 COMMIT TRANSACTION;
7913
7914
7915 END TRY
7916
7917 BEGIN CATCH
7918 ROLLBACK TRANSACTION;
7919 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
7920 --We only care if the error was not raised by SSE
7921 IF @@ERROR <> 50000
7922 BEGIN
7923 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
7924 END
7925 SET @Success =0;
7926 SELECT @ErrorStatus= @ErrorStatus + 'Languages Spoken -11001';
7927 RAISERROR(@ErrorStatus, 16, 1);
7928
7929
7930 END CATCH
7931
7932 END
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945GO
7946/****** Object: StoredProcedure [dbo].[pInsertLUfamilyRelationships] Script Date: 10/16/2020 7:31:03 PM ******/
7947SET ANSI_NULLS ON
7948GO
7949SET QUOTED_IDENTIFIER ON
7950GO
7951
7952
7953
7954
7955
7956/*************************************************************************************************
7957*Author: Gary Savard
7958*Date: 9 Oct 10
7959*Table Name: LUFamilyRelationships
7960Description: Inserts data to LUFamilyRelationships.
7961**************************************************************************************************/
7962
7963CREATE PROCEDURE [dbo].[pInsertLUfamilyRelationships](
7964 @RelationshipCode Nvarchar(30),
7965 @RelationshipDescription Nvarchar(50) ='',
7966 @ModifiedBy Name,
7967 @NewFamilyRelationshipID int Output,
7968 @Success bit Output,
7969 @ErrorStatus NVarchar(50) Output
7970 )
7971AS
7972SET NOCOUNT ON;
7973BEGIN
7974 DECLARE
7975 @TempFamilyRelationshipID int
7976
7977 SET @TempFamilyRelationshipID =0;
7978 SET @Success = 0;
7979 SET @ErrorStatus ='';
7980
7981
7982/****************************************************************************/
7983
7984
7985 BEGIN TRY
7986 BEGIN TRANSACTION;
7987 SELECT @TempFamilyRelationshipID = FamilyRelationshipID
7988 FROM person.LUFamilyRelationship
7989 WHERE RelationshipCode = Rtrim(Ltrim(@RelationshipCode))
7990 IF @TempFamilyRelationshipID <>0
7991 BEGIN
7992 SET @ErrorStatus = ' -60042 Relationship exists in LUFamilyRelationship';
7993 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
7994
7995 END
7996
7997 IF @@Error <> 0
7998 BEGIN
7999 SELECT @ErrorStatus = Convert(nVarchar(50),@@ERROR) + '-60040';
8000 SET @Success = 0;
8001 RAISERROR(@ErrorStatus, 16,1);
8002 END
8003
8004
8005 IF @TempFamilyRelationshipID = 0 -- Don't really need this with the above raise error, but for clarity.If they don't exist in the database then
8006 BEGIN
8007
8008 INSERT Person.LUFamilyRelationship(RelationshipCode,RelationshipDescription,ModifiedDate,ModifiedBy)
8009 VALUES (@RelationshipCode,@RelationshipDescription,SYSDATETIME(),@ModifiedBy)
8010
8011 set @NewFamilyRelationshipID =@@IDENTITY;
8012 set @success =1;
8013 set @ErrorStatus =0;
8014 COMMIT TRANSACTION;
8015 END
8016
8017 END TRY
8018
8019 BEGIN CATCH
8020 ROLLBACK TRANSACTION;
8021 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
8022 --We only care if the error was not raised by SSE
8023 IF @@ERROR <> 50000
8024 BEGIN
8025 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
8026 END
8027 SET @Success =0;
8028 SELECT @ErrorStatus= @ErrorStatus +'-60041 Insert Failed on LUFamilyRelationship';
8029 RAISERROR(@ErrorStatus, 16, 1);
8030
8031
8032 END CATCH
8033
8034 END
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046GO
8047/****** Object: StoredProcedure [dbo].[pInsertPerson] Script Date: 10/16/2020 7:31:03 PM ******/
8048SET ANSI_NULLS ON
8049GO
8050SET QUOTED_IDENTIFIER ON
8051GO
8052
8053
8054
8055
8056
8057
8058
8059/*************************************************************************************************
8060*Lookup Table Stored Procedure Template. Change XXX in name to the name of the table that will get the insert. This is to be used
8061*for single table inserts only.
8062*Author: Gary Savard
8063*Date: 8 Oct 10
8064*Table Name: Person
8065Description: Iserts data to Person table
8066Revisions:
8067**************************************************************************************************/
8068CREATE PROCEDURE [dbo].[pInsertPerson](
8069 @Title NVarchar(8) =NULL,
8070 @FirstName Name,
8071 @MiddleName Name = Null,
8072 @LastName Name,
8073 @Suffix NVarchar(10) = Null,
8074 @DateOfBirth DateTime,
8075 @EmailAddress Nvarchar(50) = Null,
8076 @EmailContactPreference NoYes =0,
8077 @ModifiedBy Name,
8078 @NewPersonID int Output,
8079 @Success bit Output,
8080 @ErrorStatus Nvarchar(50) Output
8081 )
8082AS
8083SET NOCOUNT ON;
8084BEGIN
8085 DECLARE
8086 @TempPersonID int,
8087 @PersonID int;
8088
8089 SET @TempPersonID =0;
8090 SET @Success = 0;
8091 SET @ErrorStatus ='';
8092 SET @TempPersonID =0;
8093
8094
8095
8096BEGIN TRY
8097 BEGIN TRANSACTION;
8098
8099 SELECT @TempPersonID = PersonID
8100 FROM person.Person
8101 WHERE Firstname = @FirstName AND LastName = @LastName AND
8102 DateOfBirth =@DateOfBirth
8103 IF @TempPersonID <>0
8104 BEGIN
8105 SELECT @ErrorStatus = 'Person Already Exists -1017';
8106 SET @Success = 0;
8107 RAISERROR(@ErrorStatus,16,1);
8108 END
8109
8110 IF @@Error <> 0
8111 BEGIN
8112 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-1000';
8113 SET @Success = 0;
8114 RAISERROR(@ErrorStatus,16,1);
8115 END
8116
8117
8118 INSERT Person.Person(Title,FirstName,MiddleName,LastName, Suffix,DateOfBirth, EmailAddress, EmailContactPreference, ModifiedDate, ModifiedBy, IsDeleted)
8119 VALUES (@Title, @FirstName, @MiddleName,@LastName,@Suffix,@DateOfBirth,@EmailAddress,@EmailContactPreference,SYSDATETIME(),@ModifiedBy, 0)
8120
8121 set @NewPersonID =@@IDENTITY;
8122 set @success =1;
8123 set @ErrorStatus =0;
8124 COMMIT TRANSACTION;
8125
8126 END TRY
8127
8128 BEGIN CATCH
8129 ROLLBACK TRANSACTION;
8130 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
8131 --We only care if the error was not raised by SSE
8132 IF @@ERROR <> 50000
8133 BEGIN
8134 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
8135 END
8136 SET @Success =0;
8137 SET @ErrorStatus= @ErrorStatus + '-1001';
8138 RAISERROR(@ErrorStatus, 15, 1);
8139
8140
8141 END CATCH
8142
8143 END
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153GO
8154/****** Object: StoredProcedure [dbo].[pInsertPersonType] Script Date: 10/16/2020 7:31:03 PM ******/
8155SET ANSI_NULLS ON
8156GO
8157SET QUOTED_IDENTIFIER ON
8158GO
8159
8160
8161
8162
8163
8164
8165/*************************************************************************************************
8166*Author: Gary Savard
8167*Date: 9 Oct 10
8168*Table Name: LUPersonType
8169Description: Inserts data to LUPersonType.
8170Revisions:
8171**************************************************************************************************/
8172
8173CREATE PROCEDURE [dbo].[pInsertPersonType](
8174 @PersonType NVarchar(20),
8175 @ModifiedBy Name,
8176 @NewPersonTypeID int Output,
8177 @Success bit Output,
8178 @ErrorStatus NVarchar(50) Output
8179 )
8180AS
8181SET NOCOUNT ON;
8182BEGIN
8183 DECLARE
8184 @TempPersonTypeID int
8185
8186 SET @TempPersonTypeID =0;
8187 SET @Success = 0;
8188 SET @ErrorStatus ='';
8189
8190
8191BEGIN TRY
8192 BEGIN TRANSACTION;
8193 /****************************************************************************/
8194 --Does it already exist? If so, don't insert it.
8195 SELECT @TempPersonTypeID = PersonTypeID
8196 FROM person.LUPersonType
8197 WHERE PersonType = Rtrim(Ltrim(@PersonType))
8198
8199/****************************************************************************/
8200 IF @TempPersonTypeID <> 0
8201 BEGIN
8202 SELECT @ErrorStatus = @@ERROR + '-600007 PersonType already exists';
8203 SET @Success = 0;
8204 RAISERROR(@ErrorStatus, 16,1);
8205 END
8206
8207 IF @@Error <> 0
8208 BEGIN
8209 SELECT @ErrorStatus = @@ERROR + '-600000';
8210 SET @Success = 0;
8211 RAISERROR(@ErrorStatus, 16,1);
8212 END
8213
8214
8215
8216 BEGIN
8217
8218 INSERT Person.LUPersonType(PersonType,ModifiedDate,ModifiedBy)
8219 VALUES (@PersonType,SYSDATETIME(),@ModifiedBy)
8220
8221 set @NewPersonTypeID =@@IDENTITY;
8222 set @success =1;
8223 set @ErrorStatus =0;
8224 COMMIT TRANSACTION;
8225 END
8226END TRY
8227
8228 BEGIN CATCH
8229 ROLLBACK TRANSACTION;
8230 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
8231 --We only care if the error was not raised by SSE
8232 IF @@ERROR <> 50000
8233 BEGIN
8234 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
8235 END
8236 SET @Success =0;
8237 SELECT @ErrorStatus= @ErrorStatus +'-600001 Insert Failed Person Type';
8238 RAISERROR(@ErrorStatus, 16, 1);
8239
8240
8241 END CATCH
8242
8243 END
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255GO
8256/****** Object: StoredProcedure [dbo].[pInsertPhone] Script Date: 10/16/2020 7:31:03 PM ******/
8257SET ANSI_NULLS ON
8258GO
8259SET QUOTED_IDENTIFIER ON
8260GO
8261
8262
8263/*************************************************************************************************
8264*Author: Gary Savard
8265*Date: 8 Oct 10
8266*Table Name: Phone
8267Description: Inserts data to phone table. The row is tied to the person.personid. This Stored proc/table does not directly
8268access the LUPhoneType table. The type is selected by the user from a dropdown and we just store the ID from the dropdown behind the scenes
8269 for simplicity
8270**************************************************************************************************/
8271
8272CREATE PROCEDURE [dbo].[pInsertPhone](
8273 @PersonID int,
8274 @PhoneNumber Phone,
8275 @PhoneExtension NVarchar(8),
8276 @PhoneType int,
8277 @ModifiedBy Name,
8278 @PhoneID int Output,
8279 @Success bit Output,
8280 @ErrorStatus Nvarchar(50) Output
8281 )
8282AS
8283SET NOCOUNT ON;
8284
8285 DECLARE
8286 @TempPhoneID int,
8287 @TempPersonID int
8288
8289 SET @TempPhoneID =0;
8290 SET @TempPersonID =0;
8291 SET @Success = 0;
8292 SET @ErrorStatus ='';
8293
8294 BEGIN TRY
8295 BEGIN TRANSACTION;
8296 IF @PersonID = 0 OR @PersonID IS NULL -- This has to be valid or we bail out!
8297 BEGIN
8298 SET @Success =0;
8299 SET @ErrorStatus = '8008: PersonID must be valid';
8300
8301 RAISERROR(@ErrorStatus,16,1);
8302 END
8303 IF @@Error <> 0
8304 BEGIN
8305 SELECT @ErrorStatus = @@ERROR + '-8030';
8306 SET @Success = 0;
8307 RAISERROR(@ErrorStatus, 16, 1);
8308 END
8309
8310
8311 INSERT Person.Phone(PersonID,PhoneNumber,PhoneExtension, PhoneType,ModifiedDate, ModifiedBy)
8312 VALUES (@PersonID,@PhoneNumber,@PhoneExtension, @PhoneType,SYSDATETIME(),@ModifiedBy)
8313
8314 set @PhoneID =@@IDENTITY;
8315 set @success =1;
8316 set @ErrorStatus =0;
8317
8318 COMMIT TRANSACTION;
8319
8320 END TRY
8321
8322 BEGIN CATCH
8323 ROLLBACK TRANSACTION;
8324 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
8325 --We only care if the error was not raised by SSE
8326 IF @@ERROR <> 50000
8327 BEGIN
8328 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
8329 END
8330
8331 SELECT @ErrorStatus= @ErrorStatus + '8001';
8332 RAISERROR(@ErrorStatus, 16, 1);
8333 SET @Success =0;
8334
8335
8336 END CATCH
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353GO
8354/****** Object: StoredProcedure [dbo].[pInsertPhoneType] Script Date: 10/16/2020 7:31:03 PM ******/
8355SET ANSI_NULLS ON
8356GO
8357SET QUOTED_IDENTIFIER ON
8358GO
8359
8360
8361
8362
8363/*************************************************************************************************
8364
8365*Author: Gary Savard
8366*Date: 12 Oct 10
8367*Table Name: LUPhoneType
8368Description: Inserts Phone Type to the LUPhoneType table.The data in this table could easily become
8369poor if the user does not take care when inserting phone types. A mis-spelling can cause unintential duplicate
8370records.
8371Revisions:
8372**************************************************************************************************/
8373
8374CREATE PROCEDURE [dbo].[pInsertPhoneType](
8375 @PhoneType int,
8376 @ModifiedBy Name,
8377 @NewPhoneTypeID int Output,
8378 @Success bit Output,
8379 @ErrorStatus Nvarchar(50) Output
8380 )
8381AS
8382SET NOCOUNT ON;
8383BEGIN
8384 DECLARE
8385 @TempPhoneTypeID int
8386
8387 SET @TempPhoneTypeID =0;
8388 SET @Success = 0;
8389 SET @ErrorStatus ='';
8390
8391
8392
8393
8394BEGIN TRY
8395 BEGIN TRANSACTION;
8396 /****************************************************************************/
8397 --Check to be sure that the Phone Type doesn't already exist.
8398 SELECT @TempPhoneTypeID = PhoneTypeID
8399 FROM person.LUPhoneType
8400 WHERE PhoneType = ltrim(rtrim(@PhoneType))
8401
8402 IF @TempPhoneTypeID <> 0
8403 BEGIN
8404 SET @ErrorStatus = '-6082' + ' PhoneType exists in LUPhoneType' ; --Failed in lookup table
8405 RAISERROR(@ErrorStatus,15,1);--Could use WITH LOG for event log
8406
8407 END
8408
8409
8410 IF @@Error <> 0
8411 BEGIN
8412 SET @ErrorStatus = '-6080';
8413 SET @Success = 0;
8414 RAISERROR (@ErrorStatus,16,1);
8415 END
8416
8417 INSERT Person.LUPhoneType(PhoneType,ModifiedDate, ModifiedBy)
8418 VALUES (@PhoneType, SYSDATETIME(),@ModifiedBy)
8419
8420 set @NewPhoneTypeID =@@IDENTITY;
8421 set @success =1;
8422 set @ErrorStatus ='';
8423 COMMIT TRANSACTION;
8424
8425 END TRY
8426
8427 BEGIN CATCH
8428 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
8429 --We only care if the error was not raised by SSE
8430 IF @@ERROR <> 50000
8431 BEGIN
8432 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
8433 END
8434 SET @Success =0;
8435
8436 SET @ErrorStatus= @Errorstatus + ' -6081' +'Insert Failed on Phone Type';
8437 RAISERROR(@ErrorStatus, 16, 1);
8438
8439 ROLLBACK TRANSACTION;
8440 END CATCH
8441
8442
8443END
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453GO
8454/****** Object: StoredProcedure [dbo].[pInsertPostalCode] Script Date: 10/16/2020 7:31:03 PM ******/
8455SET ANSI_NULLS ON
8456GO
8457SET QUOTED_IDENTIFIER ON
8458GO
8459
8460
8461
8462
8463
8464
8465
8466
8467/*************************************************************************************************
8468
8469*Author: Gary Savard
8470*Date: 12 Oct 10
8471*Table Name: Address
8472Description: Inserts Postal Code to the Postal Code table.This requires that the CityID be passed in as a
8473paramter. It is unlikely that a new city will be build, requiring a new postal code, but it is very likely
8474that a new postal code will be needed in a city.
8475Revisions:
8476**************************************************************************************************/
8477
8478CREATE PROCEDURE [dbo].[pInsertPostalCode](
8479 @CityID int,
8480 @PostalCode Nvarchar(10),
8481 @ModifiedBy Name,
8482 @NewPostalCodeID int Output,
8483 @Success bit Output,
8484 @ErrorStatus Nvarchar(50) Output
8485 )
8486AS
8487SET NOCOUNT ON;
8488BEGIN
8489 DECLARE
8490 @TempCityID int
8491
8492
8493 SET @TempCityID =0;
8494 SET @Success = 0;
8495 SET @ErrorStatus ='';
8496
8497
8498
8499
8500BEGIN TRY
8501 BEGIN TRANSACTION;
8502 /****************************************************************************/
8503 --Check to be sure that the city does exist in the city table before we go on.
8504 SELECT @TempCityID = CityID
8505 FROM person.LUCity
8506 WHERE CityID = @CityID
8507
8508 IF @TempCityID = 0
8509 BEGIN
8510 SET @ErrorStatus = '-6072' + ' CityID doesnt exist LUCity, cant insert PostalCode' ; --Failed in lookup table
8511 RAISERROR(@ErrorStatus,15,1);--Could use WITH LOG for event log
8512
8513 END
8514/****************************************************************************/
8515
8516 IF @@Error <> 0
8517 BEGIN
8518 SET @ErrorStatus = '-6070';
8519 SET @Success = 0;
8520 RAISERROR (@ErrorStatus,16,1);
8521 END
8522
8523
8524 INSERT Person.LUPostalCode(CityID,PostalCode,ModifiedDate, ModifiedBy)
8525 VALUES (@CityID, @PostalCode, SYSDATETIME(),@ModifiedBy)
8526
8527 set @NewPostalCodeID =@@IDENTITY;
8528 set @success =1;
8529 set @ErrorStatus ='';
8530 COMMIT TRANSACTION;
8531
8532END TRY
8533
8534 BEGIN CATCH
8535 ROLLBACK TRANSACTION;
8536 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
8537 --We only care if the error was not raised by SSE
8538 IF @@ERROR <> 50000
8539 BEGIN
8540 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
8541 END
8542 SET @Success =0;
8543 SET @ErrorStatus='-6071' +'Insert Failed on PostalCode';
8544 RAISERROR(@ErrorStatus, 16, 1);
8545
8546
8547 END CATCH
8548
8549
8550END
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560GO
8561/****** Object: StoredProcedure [dbo].[pInsertPrograms] Script Date: 10/16/2020 7:31:03 PM ******/
8562SET ANSI_NULLS ON
8563GO
8564SET QUOTED_IDENTIFIER ON
8565GO
8566
8567
8568
8569/*************************************************************************************************
8570
8571*Author: Gary Savard
8572*Date: 8 Oct 10
8573*Table Name: Programs
8574Description: Inserts data to Programs table. This table creates the one to many relationship between a person and programs. Each person
8575may use 0 or more programs. If they are not using a program, we will not do an insert to this table.
8576Revisions:
8577**************************************************************************************************/
8578CREATE PROCEDURE [dbo].[pInsertPrograms](
8579 @PersonID int,
8580 @ProgramID int,
8581 @ModifiedBy Name,
8582 @NewProgramsID int output,
8583 @Success bit Output,
8584 @ErrorStatus Nvarchar(50) Output
8585 )
8586AS
8587SET NOCOUNT ON;
8588BEGIN
8589 DECLARE
8590 @TempProgramID int,
8591 @TempPersonID int
8592
8593 SET @TempPersonID =0;
8594 SET @TempProgramID =0;
8595 SET @Success = 0;
8596 SET @ErrorStatus ='';
8597
8598
8599 BEGIN
8600 BEGIN TRY
8601 BEGIN TRANSACTION;
8602 IF (((@PersonID = 0)OR (@PersonID IS NULL)) OR ((@ProgramID =0) OR (@ProgramID IS NULL)))
8603 BEGIN
8604 SELECT @ErrorStatus =' -9005 PersonID/ProgramID Cant be 0/NULL';
8605 SET @Success =0;
8606 RAISERROR (@ErrorStatus,16,1);
8607 END
8608
8609
8610 --Are these valid ids?
8611 SELECT @TempPersonID = PersonID
8612 FROM person.Person
8613 WHERE PersonID = @PersonID
8614
8615 SELECT @TempProgramID = @ProgramID
8616 FROM Person.LUProgramType
8617 WHERE ProgramTypeID = @ProgramID
8618
8619 IF @TempPersonID = 0 OR @TempPersonID IS NULL--Cant have these!
8620 BEGIN
8621 SELECT @ErrorStatus = '-9005 PersonID doesnt exist';
8622 SET @Success =0;
8623 RAISERROR(@ErrorStatus,16,1);
8624 END
8625
8626 IF @TempProgramID = 0 OR @TempProgramID IS NULL
8627 BEGIN
8628 SELECT @ErrorStatus = '-9006 ProgramID doesnt exist';
8629 SET @Success =0;
8630 RAISERROR (@ErrorStatus,16,1);
8631 END
8632
8633 IF @@Error <> 0
8634 BEGIN
8635 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -1000';
8636 SET @Success = 0;
8637 RAISERROR(@ErrorStatus, 16, 1);
8638 END
8639
8640 INSERT Person.Programs(PersonID,ProgramID,ModifiedDate, ModifiedBy)
8641 VALUES (@PersonID, @ProgramID, SYSDATETIME(),@ModifiedBy)
8642
8643 SET @NewProgramsID = @@IDENTITY;
8644 SET @success =1;
8645 SET @ErrorStatus =0;
8646 COMMIT TRANSACTION;
8647
8648 END TRY
8649
8650 BEGIN CATCH
8651 ROLLBACK TRANSACTION;
8652 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
8653 --We only care if the error was not raised by SSE
8654 IF @@ERROR <> 50000
8655 BEGIN
8656 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
8657 END
8658 SET @Success =0;
8659 SELECT @ErrorStatus= @ErrorStatus +'-9011 Insert Fail Programs';
8660 RAISERROR(@ErrorStatus, 15, 1);
8661
8662
8663 END CATCH
8664
8665 END
8666END
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677GO
8678/****** Object: StoredProcedure [dbo].[pInsertProgramServicesUsed] Script Date: 10/16/2020 7:31:03 PM ******/
8679SET ANSI_NULLS ON
8680GO
8681SET QUOTED_IDENTIFIER ON
8682GO
8683
8684
8685
8686/*************************************************************************************************
8687*Author: Gary Savard
8688*Date: 8 Oct 10
8689*Table Name: ProgramServicesUsed
8690Description: Inserts data to child of Services.The IDs (PersonID,ProgramID,ProgramServiceID) must all be correct to do an insert.
8691Revisions:
8692**************************************************************************************************/
8693
8694CREATE PROCEDURE [dbo].[pInsertProgramServicesUsed](
8695 @ProgramServiceID int,
8696 @PersonID int,
8697 @ProgramID int,
8698 @ModifiedBy Name,
8699 @NewProgramServiceUsedID int Output,
8700 @Success bit Output,
8701 @ErrorStatus Nvarchar(50) Output
8702 )
8703AS
8704SET NOCOUNT ON;
8705BEGIN
8706 DECLARE
8707 @TempProgramServiceID int,
8708 @TempPersonID int,
8709 @TempProgramID int
8710
8711 SET @TempProgramServiceID =0;
8712 SET @TempPersonID =0;
8713 SET @TempProgramID=0;
8714 SET @Success = 0;
8715 SET @ErrorStatus ='';
8716
8717
8718BEGIN TRY
8719 BEGIN TRANSACTION;
8720 --All have to be valid
8721 IF (@PersonID = 0 OR @PersonID IS NULL) OR (@ProgramID =0 OR @ProgramID IS NULL) OR (@ProgramServiceID = 0 OR @ProgramServiceID IS NULL)
8722 BEGIN
8723 SELECT @ErrorStatus ='-10005 PersonId,ProgramID,ProgramServiceID cant be 0/NULL';
8724 SET @Success =0;
8725 RAISERROR(@ErrorStatus,16,1);
8726 END
8727
8728 --Now check to see that each ID exists in the appropriate table
8729
8730 SELECT @TempPersonID = PersonID
8731 FROM Person.Person
8732 WHERE PersonID = @PersonID
8733
8734 SELECT @TempProgramID = ProgramTypeID
8735 FROM Person.LUProgramType
8736 WHERE ProgramTypeID = @ProgramID
8737
8738 SELECT @TempProgramServiceID = ProgramServiceTypeID
8739 FROM Person.LUProgramServiceType
8740 WHERE ProgramServiceTypeID = @ProgramServiceID
8741
8742 IF (@TempPersonID = 0 OR @TempPersonID IS NULL) OR (@TempProgramID =0 OR @TempProgramID IS NULL) OR (@TempProgramServiceID = 0 OR @TempProgramServiceID IS NULL)
8743 BEGIN
8744 SELECT @ErrorStatus ='-10008 PersonId,ProgramID or ProgramServiceID does not exist';
8745 SET @Success =0;
8746 RAISERROR(@ErrorStatus,16,1);
8747 END
8748
8749
8750
8751 IF @@Error <> 0
8752 BEGIN
8753 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6040';
8754 SET @Success = 0;
8755 RAISERROR(@ErrorStatus, 16,1);
8756 END
8757
8758
8759 BEGIN
8760 INSERT Person.ProgramServicesUsed(PersonID,ProgramID,ProgramServiceID,ModifiedDate, ModifiedBy)
8761 VALUES (@PersonID,@ProgramID,@ProgramServiceID,SYSDATETIME(),@ModifiedBy)
8762
8763 set @NewProgramServiceUsedID =@@IDENTITY;
8764 set @success =1;
8765 set @ErrorStatus =0;
8766 COMMIT TRANSACTION;
8767 END
8768
8769 END TRY
8770
8771 BEGIN CATCH
8772 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
8773 --We only care if the error was not raised by SSE
8774 IF @@ERROR <> 50000
8775 BEGIN
8776 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
8777 END
8778 ROLLBACK TRANSACTION;
8779 SET @Success =0;
8780 SET @ErrorStatus=@@ERROR +@ErrorStatus+ '-10001';
8781 RAISERROR(@ErrorStatus, 16, 1);
8782
8783
8784 END CATCH
8785
8786 END
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798GO
8799/****** Object: StoredProcedure [dbo].[pInsertProgramServiceType] Script Date: 10/16/2020 7:31:03 PM ******/
8800SET ANSI_NULLS ON
8801GO
8802SET QUOTED_IDENTIFIER ON
8803GO
8804
8805
8806
8807
8808/*************************************************************************************************
8809*Author: Gary Savard
8810*Date: 8 Oct 10
8811*Table Name: LUProgramServiceType
8812Description: Inserts data to LUProgramServiceType. This table matches the Program with the service being
8813used by the client.
8814Revisions:
8815**************************************************************************************************/
8816
8817CREATE PROCEDURE [dbo].[pInsertProgramServiceType](
8818 @ServiceCode Nvarchar(20),
8819 @ServiceDescription NVarchar(50),
8820 @ModifiedBy Name,
8821 @NewProgramTypeID int Output,
8822 @Success bit Output,
8823 @ErrorStatus Nvarchar(50) Output
8824 )
8825AS
8826SET NOCOUNT ON;
8827BEGIN
8828 DECLARE
8829 @TempProgramServiceTypeID int
8830
8831 SET @TempProgramServiceTypeID =0;
8832 SET @Success = 0;
8833 SET @ErrorStatus ='';
8834
8835/****************************************************************************/
8836
8837 SELECT @TempProgramServiceTypeID = ProgramServiceTypeID
8838 FROM person.LUProgramServiceType
8839 WHERE ServiceCode = Rtrim(Ltrim(@ServiceCode)) --Be a bit paranoid and trim the input for white spaces
8840
8841
8842/****************************************************************************/
8843BEGIN TRY
8844 BEGIN TRANSACTION;
8845 IF @@Error <> 0
8846 BEGIN
8847 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6040';
8848 SET @Success = 0;
8849 RAISERROR(@ErrorStatus, 16,1);
8850 END
8851
8852
8853 IF @TempProgramServiceTypeID = 0 --If they don't exist in the database then
8854 BEGIN
8855
8856 INSERT Person.LUProgramServiceType(ServiceCode,ServiceDescription,ModifiedDate, ModifiedBy)
8857 VALUES (@ServiceCode,@ServiceDescription,SYSDATETIME(),@ModifiedBy)
8858
8859 set @TempProgramServiceTypeID =@@IDENTITY;
8860 set @success =1;
8861 set @ErrorStatus =0;
8862 COMMIT TRANSACTION;
8863 END
8864
8865 END TRY
8866
8867 BEGIN CATCH
8868 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
8869 --We only care if the error was not raised by SSE
8870 IF @@ERROR <> 50000
8871 BEGIN
8872 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
8873 END
8874 ROLLBACK TRANSACTION;
8875 SET @Success =0;
8876 SET @ErrorStatus=@@ERROR +@ErrorStatus+ '-6051';
8877 RAISERROR(@ErrorStatus, 16, 1);
8878
8879
8880 END CATCH
8881
8882 END
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893GO
8894/****** Object: StoredProcedure [dbo].[pInsertProgramType] Script Date: 10/16/2020 7:31:03 PM ******/
8895SET ANSI_NULLS ON
8896GO
8897SET QUOTED_IDENTIFIER ON
8898GO
8899
8900
8901
8902
8903
8904
8905/*************************************************************************************************
8906*Author: Gary Savard
8907*Date: 8 Oct 10
8908*Table Name: LUProgramType
8909Description: Inserts data to LUProgramType. This table matches the Program with the user.
8910Revisions:
8911**************************************************************************************************/
8912
8913CREATE PROCEDURE [dbo].[pInsertProgramType](
8914 @ProgramName Nvarchar(20),
8915 @ProgramDescription NVarchar(50),
8916 @ModifiedBy Name,
8917 @NewProgramTypeID int Output,
8918 @Success bit Output,
8919 @ErrorStatus Nvarchar(50) Output
8920 )
8921AS
8922SET NOCOUNT ON;
8923BEGIN
8924 DECLARE
8925 @TempProgramTypeID int
8926
8927 SET @TempProgramTypeID =0;
8928 SET @Success = 0;
8929 SET @ErrorStatus ='';
8930
8931
8932BEGIN TRY
8933 BEGIN TRANSACTION;
8934 /****************************************************************************/
8935 --This is a bit different than some procedures because there is a lookup table associated with
8936 --the address, so we need to be sure that the data matches a program type before continuing.
8937 SELECT @TempProgramTypeID = ProgramTypeID
8938 FROM person.LUProgramType
8939 WHERE ProgramName = Rtrim(Ltrim(@ProgramName)) --Be a bit paranoid and trim the input for white spaces
8940
8941
8942/****************************************************************************/
8943 IF @@Error <> 0
8944 BEGIN
8945 SELECT @ErrorStatus = @@ERROR + ' -6040';
8946 SET @Success = 0;
8947 END
8948
8949
8950 IF @TempProgramTypeID = 0 --If they don't exist in the database then
8951 BEGIN
8952
8953 INSERT Person.LUProgramType(ProgramName,ProgramDescription,ModifiedDate, ModifiedBy)
8954 VALUES (@ProgramName,@ProgramDescription,SYSDATETIME(),@ModifiedBy)
8955
8956 set @NewProgramTypeID =@@IDENTITY;
8957 set @success =1;
8958 set @ErrorStatus =0;
8959 COMMIT TRANSACTION;
8960 END
8961
8962 END TRY
8963
8964 BEGIN CATCH
8965 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
8966 --We only care if the error was not raised by SSE
8967 IF @@ERROR <> 50000
8968 BEGIN
8969 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
8970 END
8971 ROLLBACK TRANSACTION;
8972 SET @Success =0;
8973 SET @ErrorStatus= @ErrorStatus +' -6041 Insert Failed on Program Type';
8974 RAISERROR(@ErrorStatus, 16, 1);
8975
8976
8977 END CATCH
8978
8979 END
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991GO
8992/****** Object: StoredProcedure [dbo].[pInsertRace] Script Date: 10/16/2020 7:31:03 PM ******/
8993SET ANSI_NULLS ON
8994GO
8995SET QUOTED_IDENTIFIER ON
8996GO
8997
8998
8999
9000
9001
9002/*************************************************************************************************
9003*Author: Gary Savard
9004*Date: 9 Oct 10
9005*Table Name: LURace
9006Description: Inserts data to LURace. This table matches the Race with a U.S Census race category
9007Revisions:
9008**************************************************************************************************/
9009
9010CREATE PROCEDURE [dbo].[pInsertRace](
9011 @RaceAbbreviation NVarchar(10),
9012 @RaceDescription NVarchar(50),
9013 @ModifiedBy Name,
9014 @NewRaceID int Output,
9015 @Success bit Output,
9016 @ErrorStatus NVarchar(50) Output
9017 )
9018AS
9019SET NOCOUNT ON;
9020BEGIN
9021 DECLARE
9022 @TempRaceID int
9023
9024 SET @TempRaceID =0;
9025 SET @Success = 0;
9026 SET @ErrorStatus ='';
9027
9028
9029BEGIN TRY
9030 BEGIN TRANSACTION;
9031/****************************************************************************/
9032 --This is a bit different than some procedures because there is a lookup table associated with
9033 --the race, so we need to be sure that the data matches a race type before continuing. Hopefully, the
9034 --abbreviations will be consistent so that we do not have duplicates. There is no sure way to code this.
9035 --White, Black(AA or Negro).American Indian or Alaskan native.,Asian Indian,Chinese,Filipino, Other Asian, Japanese,
9036 --Korean, Vietnamese, Native Hawaiian, Guanamanian or Chamorro, Samoan, Other pacific Islander.
9037 SELECT @TempRaceID = RaceID
9038 FROM person.LURace
9039 WHERE RaceAbbreviation = Rtrim(Ltrim(@RaceAbbreviation)) --Be a bit paranoid and trim the input for white spaces
9040
9041
9042/****************************************************************************/
9043 IF @@Error <> 0
9044 BEGIN
9045 SELECT @ErrorStatus = @@ERROR + '-6020';
9046 SET @Success = 0;
9047 RAISERROR(@ErrorStatus, 16,1);
9048 END
9049
9050
9051 IF @TempRaceID = 0 --If they don't exist in the database then
9052 BEGIN
9053
9054 INSERT Person.LURace(RaceAbbreviation,RaceDescription, ModifiedDate,ModifiedBy)
9055 VALUES (@RaceAbbreviation,@RaceDescription,SYSDATETIME(),@ModifiedBy)
9056
9057 set @NewRaceID =@@IDENTITY;
9058 set @success =1;
9059 set @ErrorStatus =0;
9060 COMMIT TRANSACTION;
9061 END
9062END TRY
9063
9064 BEGIN CATCH
9065 ROLLBACK TRANSACTION;
9066 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
9067 --We only care if the error was not raised by SSE
9068 IF @@ERROR <> 50000
9069 BEGIN
9070 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
9071 END
9072 SET @Success =0;
9073 SELECT @ErrorStatus= @ErrorStatus +'-6021 Insert Failed Race Type';
9074 RAISERROR(@ErrorStatus, 16, 1);
9075
9076
9077 END CATCH
9078
9079 END
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090GO
9091/****** Object: StoredProcedure [dbo].[pInsertSSN] Script Date: 10/16/2020 7:31:03 PM ******/
9092SET ANSI_NULLS ON
9093GO
9094SET QUOTED_IDENTIFIER ON
9095GO
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106/*************************************************************************************************
9107*Author: Gary Savard
9108*Date: 15 Oct 10
9109*Table Name: SSN.SSN
9110Description: Inserts data to SSN. Only Certain federal programs require that SSN be captured, so we only want to
9111use this sparingly.
9112Revisions:
9113**************************************************************************************************/
9114
9115CREATE PROCEDURE [dbo].[pInsertSSN](
9116 @PersonID int,
9117 @SSN NVarchar(9),
9118 @ModifiedBy Name,
9119 @NewSSNID int Output,
9120 @Success bit Output,
9121 @ErrorStatus Nvarchar(50) Output
9122 )
9123AS
9124SET NOCOUNT ON;
9125BEGIN
9126 DECLARE
9127 @TempPersonID int,
9128 @TempSSNID int
9129
9130 SET @TempPersonId =0;
9131 SET @TempSSNID =0;
9132 SET @Success = 0;
9133 SET @ErrorStatus ='';
9134
9135
9136 BEGIN TRY
9137 BEGIN TRANSACTION;
9138 SELECT @SSN = ltrim(rtrim(@SSN)); --Get rid of spaces before we begin!
9139 /****************************************************************************/
9140 IF ((@PersonID = 0) OR (@PersonID IS NULL))
9141 BEGIN
9142 SELECT @ErrorStatus = '-12005 PersonID cant be 0/NULL';
9143 SET @Success =0;
9144 RAISERROR(@ErrorStatus,16,1);
9145
9146 END
9147 IF ((LEN(@SSN)<9) OR (@SSN IS NULL))
9148 BEGIN
9149 SELECT @ErrorStatus = '-11006 Invalid SSN';
9150 SET @Success =0;
9151 RAISERROR(@ErrorStatus,16,1);
9152
9153 END
9154
9155
9156 SELECT @TempPersonID = PersonID
9157 FROM Person.Person
9158 Where PersonID = @PersonID
9159
9160
9161 IF @TempPersonID = 0 OR @TempPersonID IS NULL
9162 BEGIN
9163 SELECT @ErrorStatus ='-12008 PersonID does not exist in Person';
9164 SET @Success=0;
9165 RAISERROR(@ErrorStatus,16,1);
9166 END
9167
9168 --Final check to be sure this is not a duplicate
9169
9170 SELECT @TempSSNID = SSNID
9171 FROM SSN.SSN
9172 WHERE PersonID = @PersonID AND SSN =@SSN
9173
9174 IF @TempSSNID <> 0
9175 --This already exists! Duplicate Row Error
9176 BEGIN
9177 SELECT @ErrorStatus = '-12009 Duplicate Row Exists';
9178 SET @Success =0;
9179 RAISERROR(@ErrorStatus,16,1);
9180 END
9181
9182
9183
9184 /****************************************************************************/
9185 IF @@Error <> 0
9186 BEGIN
9187 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6060';
9188 SET @Success = 0;
9189 RAISERROR(@ErrorStatus,16,1);
9190 END
9191
9192
9193 --If they don't exist in the database then
9194
9195
9196 INSERT SSN.SSN (PersonID,SSN,ModifiedDate, ModifiedBy)
9197 VALUES (@PersonID,@SSN,SYSDATETIME(),@ModifiedBy)
9198
9199 SET @NewSSNID =@@IDENTITY;
9200 SET @success =1;
9201 SET @ErrorStatus =0;
9202
9203 COMMIT TRANSACTION;
9204
9205
9206 END TRY
9207
9208 BEGIN CATCH
9209 ROLLBACK TRANSACTION;
9210 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
9211 --We only care if the error was not raised by SSE
9212 IF @@ERROR <> 50000
9213 BEGIN
9214 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
9215 END
9216 SET @Success =0;
9217 SELECT @ErrorStatus= @ErrorStatus + 'SSN -12001';
9218 RAISERROR(@ErrorStatus, 16, 1);
9219
9220
9221 END CATCH
9222
9223 END
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236GO
9237/****** Object: StoredProcedure [dbo].[pInsertState] Script Date: 10/16/2020 7:31:03 PM ******/
9238SET ANSI_NULLS ON
9239GO
9240SET QUOTED_IDENTIFIER ON
9241GO
9242
9243
9244
9245
9246/*************************************************************************************************
9247*Author: Gary Savard
9248*Date: 8 Oct 10
9249*Table Name: LUState
9250Description: Inserts data to LUState. This table matches the State with a State ID for ties to County, City and Zip Code.
9251Revisions:
9252**************************************************************************************************/
9253
9254CREATE PROCEDURE [dbo].[pInsertState](
9255 @StateCode Nvarchar(2),
9256 @Name Nvarchar(50),
9257 @ModifiedBy Name,
9258 @NewStateID int Output,
9259 @Success bit Output,
9260 @ErrorStatus Nvarchar(50) Output
9261 )
9262AS
9263SET NOCOUNT ON;
9264BEGIN
9265 DECLARE
9266 @TempStateID int
9267
9268 SET @TempStateID =0;
9269 SET @Success = 0;
9270 SET @ErrorStatus ='';
9271
9272
9273BEGIN TRY
9274 BEGIN TRANSACTION;
9275 /****************************************************************************/
9276 --This is a bit different than some procedures because we do not want duplicates in the table associated with
9277 --the state, so we need to be sure that the data matches a state before continuing.
9278 SELECT @TempStateID = StateID
9279 FROM person.LUState
9280 WHERE StateCode = Rtrim(Ltrim(@StateCode)) --Be a bit paranoid and trim the input for white spaces
9281
9282/****************************************************************************/
9283 IF @@Error <> 0
9284 BEGIN
9285 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-6030';
9286 SET @Success = 0;
9287 RAISERROR(@ErrorStatus, 16, 1);
9288 END
9289 IF @TempStateID <>0
9290 BEGIN
9291 SELECT @ErrorStatus = 'State Already exists -6037'
9292 SET @Success =0;
9293 RAISERROR(@ErrorStatus, 16,1);
9294 END
9295
9296
9297 INSERT Person.LUState(StateCode,Name,ModifiedDate, ModifiedBy)
9298 VALUES (@StateCode,@Name,SYSDATETIME(),@ModifiedBy)
9299
9300 set @NewStateID =@@IDENTITY;
9301 set @success =1;
9302 set @ErrorStatus =0;
9303 COMMIT TRANSACTION;
9304
9305
9306 END TRY
9307
9308 BEGIN CATCH
9309 ROLLBACK TRANSACTION;
9310 SET @Success =0;
9311 SET @ErrorStatus= @ErrorStatus + @@ERROR + '-6031 Insert Failed on State';--6030-6039 is for this table
9312 RAISERROR(@ErrorStatus, 16, 1);
9313
9314
9315 END CATCH
9316
9317 END
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329GO
9330/****** Object: StoredProcedure [dbo].[pInsertUpdateFoodShelfCertification] Script Date: 10/16/2020 7:31:03 PM ******/
9331SET ANSI_NULLS ON
9332GO
9333SET QUOTED_IDENTIFIER ON
9334GO
9335
9336
9337
9338
9339
9340
9341
9342/*************************************************************************************************
9343*Author: Gary Savard
9344*Date: 8 Oct 10
9345*Table Name: Foodshelf.FoodShelfCertification
9346Description: Inserts OR updates data to Foodshelf.FoodShelfCertification. This procedure sets the last date of client
9347 certification using the passed in PersonID. If the PersonID already exists in the Table, then the
9348 SP will update that row to the "LastCertificationDate", Else it will Insert a new row.
9349 This stored procedure should only be called if the person needs to certify or recertify.
9350Revisions:28 March 11. GS added CertificationTextID
9351**************************************************************************************************/
9352
9353CREATE PROCEDURE [dbo].[pInsertUpdateFoodShelfCertification](
9354 @PersonID int,
9355 @LastCertificationDate Date,
9356 @CertificationTextID int,
9357 @ModifiedBy Name,
9358 @NewFoodShelfCertificationID int Output,
9359 @Success bit Output,
9360 @ErrorStatus Nvarchar(50) Output
9361 )
9362AS
9363
9364Set NoCount ON;
9365
9366
9367 DECLARE
9368 @TempFoodShelfCertificationID int;
9369
9370 SET @TempFoodShelfCertificationID =0;
9371 SET @Success = 0;
9372 SET @ErrorStatus ='';
9373
9374
9375
9376
9377BEGIN TRY
9378/****************************************************************************/
9379
9380 SELECT @TempFoodShelfCertificationID = FoodshelfCertificationID
9381 FROM Foodshelf.FoodShelfCertification
9382 WHERE Foodshelf.FoodShelfCertification.PersonID = @PersonID
9383
9384/****************************************************************************/
9385
9386 IF @TempFoodShelfCertificationID = 0 --If they don't exist in the database then
9387
9388 BEGIN
9389
9390 BEGIN TRANSACTION;
9391 IF @CertificationTextID = 0 or @CertificationTextID IS NULL
9392 BEGIN
9393 SET @Success = 0;
9394 SET @ErrorStatus ='-16005 CertificationTextID cannot be null/0';
9395 RAISERROR(@ErrorStatus,16,1);
9396 END
9397 IF @@Error <> 0
9398 BEGIN
9399 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-6040';
9400 SET @Success = 0;
9401 RAISERROR (@Errorstatus, 16,1);
9402 END
9403
9404 INSERT Foodshelf.FoodShelfCertification(PersonID,CertificationTextID,LastCertificationDate,ModifiedDate, ModifiedBy)
9405 VALUES (@PersonID,@CertificationTextID,@LastCertificationDate,SYSDATETIME(),@ModifiedBy)
9406
9407 set @TempFoodShelfCertificationID =@@IDENTITY;
9408 set @success =1;
9409 set @ErrorStatus =0;
9410 COMMIT TRANSACTION;
9411
9412
9413 END
9414 ELSE --The person exists so Update to the new certification date and verbiage.
9415 BEGIN
9416 IF @CertificationTextID = 0 or @CertificationTextID IS NULL
9417 BEGIN
9418 SET @Success = 0;
9419 SET @ErrorStatus ='-16005 CertificationTextID cannot be null/0';
9420 RAISERROR(@ErrorStatus,16,1);
9421 END
9422
9423 BEGIN TRANSACTION;
9424
9425 UPDATE Foodshelf.FoodShelfCertification
9426 SET LastCertificationDate = @LastCertificationDate,
9427 CertificationTextID = @CertificationTextID
9428 WHERE PersonID = @PersonID AND FoodShelfCertificationID = @TempFoodShelfCertificationID
9429 COMMIT TRANSACTION;
9430 END
9431 END TRY
9432
9433
9434 BEGIN CATCH
9435 ROLLBACK TRANSACTION;
9436 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
9437 --We only care if the error was not raised by SSE
9438 IF @@ERROR <> 50000
9439 BEGIN
9440 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
9441 END
9442 SET @Success =0;
9443 SELECT @ErrorStatus = @ErrorStatus + ' -8001 Insert Fail ProgramSvcType';
9444 RAISERROR(@ErrorStatus, 16, 1);
9445
9446
9447 END CATCH
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467GO
9468/****** Object: StoredProcedure [dbo].[pInsertVolunteerContactInformation] Script Date: 10/16/2020 7:31:03 PM ******/
9469SET ANSI_NULLS ON
9470GO
9471SET QUOTED_IDENTIFIER ON
9472GO
9473
9474-- =============================================
9475-- Author: Gary Savard
9476-- Create date: 06/01/2011
9477-- Description: Inserts volunteer contact information
9478-- =============================================
9479CREATE PROCEDURE [dbo].[pInsertVolunteerContactInformation]
9480 -- Add the parameters for the stored procedure here
9481 @ContactFirstName Name,
9482 @ContactLastName Name,
9483 @ContactAddres1 NVarchar(50),
9484 @ContactAddress2 NVarchar(50)=NULL,
9485 @ContactHomePhone Phone,
9486 @ContactWorkPhone Phone,
9487 @ContactCellPhone Phone,
9488 @ContactPager Nvarchar(20),
9489 @ContactEmail NVarchar(50),
9490 @VolunteerTypeID int,
9491 @IsActive bit,
9492 @ModifiedBy Name,
9493 @VolunteerPersonID int Output,
9494 @Error NVarchar(50) Output,
9495 @ErrorNo int output,
9496 @Success bit Output
9497AS
9498BEGIN
9499 -- SET NOCOUNT ON added to prevent extra result sets from
9500 -- interfering with SELECT statements.
9501 SET NOCOUNT ON;
9502DECLARE
9503
9504@ErrNo int =0,
9505@ErrMsg NVarchar(50)=''
9506
9507BEGIN TRY
9508
9509
9510 --Data is Valid, start the transaction
9511 BEGIN TRANSACTION
9512
9513 INSERT Volunteer.ContactInformation(
9514 VolunteerPersonID,
9515 ContactFirstName,
9516 ContactLastName,
9517 ContactAddress1,
9518 ContactAddress2,
9519 ContactEmail,
9520 ContactHomePhone,
9521 ContactCellPhone,
9522 ContactWorkPhone,
9523 ContactPager,
9524 Volunteertypeid,
9525 IsActive,
9526 ModifiedBy,
9527 ModifiedDate)
9528
9529 VALUES
9530 (@VolunteerPersonID,
9531 @ContactFirstName,
9532 @ContactLastName,
9533 @ContactAddres1,
9534 @ContactAddress2,
9535 @ContactEmail,
9536 @ContactHomePhone,
9537 @ContactCellPhone,
9538 @ContactWorkPhone,
9539 @ContactPager,
9540 @VolunteerTypeID,
9541 @IsActive,
9542 @ModifiedBy,
9543 SYSDATETIME()
9544 )
9545
9546 SELECT @ErrNo = @@ERROR
9547
9548 IF @ErrNo <>0--<> Error!
9549 BEGIN
9550 RAISERROR(@ErrNo,16,0)
9551 END
9552 SET @Success =1;
9553
9554 COMMIT TRANSACTION
9555
9556 SELECT @VolunteerPersonID = @@IDENTITY
9557
9558
9559
9560 END TRY
9561
9562 BEGIN CATCH
9563 ROLLBACK TRANSACTION
9564 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
9565 --We only care if the error was not raised by SSE
9566
9567 SET @Success =0;
9568
9569 IF RTRIM(LTRIM(@errmsg)) =''
9570 BEGIN
9571 SELECT @Error ='Failure in InsertPersonContactInformation Rollback'
9572 END
9573 ELSE
9574 BEGIN
9575 SELECT @Error = @ErrMsg
9576 END
9577
9578 SET @ErrorNo = @ErrNo
9579
9580 END CATCH
9581
9582END
9583
9584
9585GO
9586/****** Object: StoredProcedure [dbo].[pInsertVolunteerEmergencyContactInformation] Script Date: 10/16/2020 7:31:03 PM ******/
9587SET ANSI_NULLS ON
9588GO
9589SET QUOTED_IDENTIFIER ON
9590GO
9591-- =============================================
9592-- Author: Gary Savard
9593-- Create date: 06/01/2011
9594-- Description: Inserts volunteer emergency contact information
9595-- =============================================
9596create PROCEDURE [dbo].[pInsertVolunteerEmergencyContactInformation]
9597 -- Add the parameters for the stored procedure here
9598 @VolunteerPersonID int,
9599 @ContactInformation NVARCHAR(MAX),
9600 @ModifiedBy Name,
9601 @EmergencyContactInformationID int Output,
9602 @Error NVarchar(50) Output,
9603 @ErrorNo int output,
9604 @Success bit Output
9605AS
9606BEGIN
9607 -- SET NOCOUNT ON added to prevent extra result sets from
9608 -- interfering with SELECT statements.
9609 SET NOCOUNT ON;
9610DECLARE
9611
9612@ErrNo int =0,
9613@ErrMsg NVarchar(50)=''
9614
9615BEGIN TRY
9616
9617
9618 --Data is Valid, start the transaction
9619 BEGIN TRANSACTION
9620
9621 IF @VolunteerPersonID =0 OR @VolunteerPersonID IS NULL
9622 BEGIN
9623 SELECT @ErrNo =999999
9624 SELECT @ErrMsg='VolunteerPersonID cannot be 0 or NULL'
9625 RAISERROR(@ErrNo,16,0)
9626 END
9627
9628 INSERT Volunteer.VolunteerEmergencyContact(
9629 VolunteerPersonID,
9630 ContactInformation,
9631 ModifiedBy,
9632 ModifiedDate)
9633
9634 VALUES
9635 (@VolunteerPersonID,
9636 @ContactInformation,
9637 @ModifiedBy,
9638 SYSDATETIME()
9639 )
9640
9641 SELECT @ErrNo = @@ERROR
9642
9643 IF @ErrNo <>0--<> Error!
9644 BEGIN
9645 RAISERROR(@ErrNo,16,0)
9646 END
9647 SET @Success =1;
9648
9649 COMMIT TRANSACTION
9650
9651 SELECT @VolunteerPersonID = @@IDENTITY
9652
9653
9654
9655 END TRY
9656
9657 BEGIN CATCH
9658 ROLLBACK TRANSACTION
9659 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
9660 --We only care if the error was not raised by SSE
9661
9662 SET @Success =0;
9663
9664 IF RTRIM(LTRIM(@errmsg)) =''
9665 BEGIN
9666 SELECT @Error ='Failure in InsertVolEmergencyContactInfo Rollback'
9667 END
9668 ELSE
9669 BEGIN
9670 SELECT @Error = @ErrMsg
9671 END
9672
9673 SET @ErrorNo = @ErrNo
9674
9675 END CATCH
9676
9677END
9678
9679GO
9680/****** Object: StoredProcedure [dbo].[pInsertVolunteerNotes] Script Date: 10/16/2020 7:31:03 PM ******/
9681SET ANSI_NULLS ON
9682GO
9683SET QUOTED_IDENTIFIER ON
9684GO
9685-- =============================================
9686-- Author: Gary Savard
9687-- Create date: 06/01/2011
9688-- Description: Inserts volunteer Notes
9689-- =============================================
9690create PROCEDURE [dbo].[pInsertVolunteerNotes]
9691 -- Add the parameters for the stored procedure here
9692 @VolunteerPersonID int,
9693 @Notes NVARCHAR(MAX),
9694 @ModifiedBy Name,
9695 @EmergencyContactInformationID int Output,
9696 @Error NVarchar(50) Output,
9697 @ErrorNo int output,
9698 @Success bit Output
9699AS
9700BEGIN
9701 -- SET NOCOUNT ON added to prevent extra result sets from
9702 -- interfering with SELECT statements.
9703 SET NOCOUNT ON;
9704DECLARE
9705
9706@ErrNo int =0,
9707@ErrMsg NVarchar(50)=''
9708
9709BEGIN TRY
9710
9711
9712 --Data is Valid, start the transaction
9713 BEGIN TRANSACTION
9714
9715 IF @VolunteerPersonID =0 OR @VolunteerPersonID IS NULL
9716 BEGIN
9717 SELECT @ErrNo =999999
9718 SELECT @ErrMsg='VolunteerPersonID cannot be 0 or NULL'
9719 RAISERROR(@ErrNo,16,0)
9720 END
9721
9722 INSERT Volunteer.VolunteerNotes(
9723 VolunteerPersonID,
9724 Note,
9725 ModifiedBy,
9726 ModifiedDate)
9727
9728 VALUES
9729 (@VolunteerPersonID,
9730 @Notes,
9731 @ModifiedBy,
9732 SYSDATETIME()
9733 )
9734
9735 SELECT @ErrNo = @@ERROR
9736
9737 IF @ErrNo <>0--<> Error!
9738 BEGIN
9739 RAISERROR(@ErrNo,16,0)
9740 END
9741 SET @Success =1;
9742
9743 COMMIT TRANSACTION
9744
9745 SELECT @VolunteerPersonID = @@IDENTITY
9746
9747
9748
9749 END TRY
9750
9751 BEGIN CATCH
9752 ROLLBACK TRANSACTION
9753 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
9754 --We only care if the error was not raised by SSE
9755
9756 SET @Success =0;
9757
9758 IF RTRIM(LTRIM(@errmsg)) =''
9759 BEGIN
9760 SELECT @Error ='Failure in InsertVolNotes Rollback'
9761 END
9762 ELSE
9763 BEGIN
9764 SELECT @Error = @ErrMsg
9765 END
9766
9767 SET @ErrorNo = @ErrNo
9768
9769 END CATCH
9770
9771END
9772
9773GO
9774/****** Object: StoredProcedure [dbo].[pUpdateAddress] Script Date: 10/16/2020 7:31:03 PM ******/
9775SET ANSI_NULLS ON
9776GO
9777SET QUOTED_IDENTIFIER ON
9778GO
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788/*************************************************************************************************
9789
9790*Author: Gary Savard
9791*Date: 8 Oct 10
9792*Table Name: Address
9793Description: Updates data to Address table.This table has the possibility of duplicate rows because
9794 persons can have more than one address. We can check to see if an address is a duplicate, but that will have
9795 limited use since we would have to count on a combination of free-format fields since it is possible to have more than
9796 one address in the same city, zipcode, state, county, etc.
9797Revisions:
9798**************************************************************************************************/
9799CREATE PROCEDURE [dbo].[pUpdateAddress](
9800 @PersonID int =0,--Having a default may seem strange for a mandatory field but it is here only to deal with NULL, if one should occur.
9801 @AddressID int =0,--Having a default may seem strange for a mandatory field but it is here only to deal with NULL, if one should occur.
9802 @AddressLine1 Nvarchar(60),
9803 @AddressLine2 Nvarchar(60) = NULL,
9804 @City NVarchar(30),
9805 @County NVarchar(30),
9806 @State NVarchar(2),
9807 @PostalCode NVarchar(10) ,
9808 @AddressTypeID int,
9809 @ModifiedBy Name,
9810 @Success bit Output,
9811 @ErrorStatus Nvarchar(50) Output
9812 )
9813AS
9814SET NOCOUNT ON;
9815BEGIN
9816 DECLARE
9817 @TempAddressTypeID int,
9818 @TempPersonID int,
9819 @TempAddressID int
9820
9821 SET @TempAddressTypeID =0;
9822 SET @Success = 0;
9823 SET @ErrorStatus ='';
9824 SET @TempAddressID =0;
9825 SET @TempAddressID = 0;
9826/*The personID and AddressID must be non-zero because they are needed to update the row. If either is zero, we
9827exit the update*/
9828BEGIN TRY
9829 BEGIN TRANSACTION;
9830 IF ((@PersonID = 0) OR (@PersonID IS NULL)) OR ((@AddressID =0) OR (@AddressID IS NULL))
9831 BEGIN
9832 SET @ErrorStatus = ' -7014. PersonID, AddressID cannot be zero or null for update';
9833 RAISERROR(@ErrorStatus, 16,1);
9834 END
9835
9836
9837
9838/****************************************************************************/
9839 --This is a bit different than some procedures because there is a lookup table associated with
9840 --the address, so we need to be sure that the data matches an address type before continuing.
9841 SELECT @TempAddressTypeID = AddressTypeID
9842 FROM person.LUAddressType
9843 WHERE AddressTypeID = @AddressTypeID --Be a bit paranoid and trim the input for white spaces
9844
9845 If @TempAddressTypeID = 0
9846 BEGIN
9847 SET @ErrorStatus = ' -7002 Address Type does not exist in LUAddressType, Cannot Update'; --Failed in lookup table
9848 RAISERROR(@ErrorStatus,15,1);--Could use WITH LOG for event log
9849
9850 END
9851
9852
9853/****************************************************************************/
9854
9855 IF @@Error <> 0
9856 BEGIN
9857 SELECT @ErrorStatus = @@ERROR + '-7000 pUpdateAddress';
9858 SET @Success = 0;
9859 RAISERROR (@ErrorStatus,16,1);
9860 END
9861
9862
9863
9864 Update Person.Address
9865 SET PersonID = @PersonID,
9866 AddressLine1 = @AddressLine1,
9867 AddressLine2 =@AddressLine2,
9868 City = @City,
9869 State = @State,
9870 PostalCode = @PostalCode,
9871 AddressTypeID = @AddressTypeID,
9872 ModifiedDate = SYSDATETIME(),
9873 ModifiedBy = @ModifiedBy
9874 WHERE
9875 PersonID= @PersonID AND AddressID = @AddressID;
9876
9877 set @success =1;
9878 set @ErrorStatus =0;
9879 COMMIT TRANSACTION;
9880
9881 END TRY
9882
9883 BEGIN CATCH
9884 ROLLBACK TRANSACTION;
9885 SELECT @ErrorStatus =@ErrorStatus + ' -7012' +' Update Failed on Address';
9886 SET @Success =0;
9887
9888 RAISERROR(@ErrorStatus, 16, 1);
9889
9890
9891 END CATCH
9892
9893
9894END
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905GO
9906/****** Object: StoredProcedure [dbo].[pUpdateAddressType] Script Date: 10/16/2020 7:31:03 PM ******/
9907SET ANSI_NULLS ON
9908GO
9909SET QUOTED_IDENTIFIER ON
9910GO
9911
9912
9913
9914/*************************************************************************************************
9915*Author: Gary Savard
9916*Date: 8 Oct 10
9917*Table Name: LUAddressType
9918Description: Update data to LUAddressType. This table matches the address with an address type
9919Revisions:
9920G.S. - 20 Oct 10. Fixed problem with error handler not firing on preliminary lookup.
9921**************************************************************************************************/
9922CREATE PROCEDURE [dbo].[pUpdateAddressType](
9923 @AddressTypeID int,
9924 @AddressType Nvarchar(10),
9925 @ModifiedBy Name,
9926 @Success bit Output,
9927 @ErrorStatus Nvarchar(50) Output
9928 )
9929AS
9930SET NOCOUNT ON;
9931
9932BEGIN
9933 DECLARE
9934 @TempAddressTypeID int
9935
9936 SET @TempAddressTypeID =0;
9937 SET @Success = 0;
9938 SET @ErrorStatus ='';
9939
9940
9941
9942
9943
9944 BEGIN TRY
9945 BEGIN TRANSACTION;
9946
9947 /****************************************************************************/
9948 --Avoid Duplicate Rows! However, a typo on input such as 'Hmoe' instead of 'Home' will do an isert.
9949 --Can't avoid finger problems!
9950
9951 SELECT @TempAddressTypeID = AddressTypeID
9952 FROM person.LUAddressType
9953 WHERE AddressTypeID = @AddressTypeID
9954
9955 If @TempAddressTypeID = 0 --Cant Update if it doesnt exist
9956 BEGIN
9957 SELECT @ErrorStatus = '-6015 Address Type Does Not Exists';
9958 SET @Success =0;
9959 RAISERROR(@ErrorStatus, 16, 1);
9960 END
9961
9962 /****************************************************************************/
9963
9964 IF @@Error <> 0
9965 BEGIN
9966 SELECT @ErrorStatus = Convert (nVarchar(50),@@ERROR) + ' -6010';
9967 SET @Success = 0;
9968 RAISERROR(@ErrorStatus, 16, 1);
9969 END
9970
9971
9972 UPDATE Person.LUAddressType
9973 SET AddressType = @AddressType,
9974 ModifiedBy = @ModifiedBy,
9975 ModifiedDate = SYSDATETIME()
9976 WHERE
9977 AddressTypeID =@AddressTypeID;
9978
9979
9980
9981 set @success =1;
9982 set @ErrorStatus ='';
9983 COMMIT TRANSACTION;
9984
9985 END TRY
9986
9987 BEGIN CATCH
9988
9989 ROLLBACK TRANSACTION;
9990 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
9991 --We only care if the error was not raised by SSE
9992 IF @@ERROR <> 50000
9993 BEGIN
9994 SET @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
9995 END
9996
9997
9998 SET @Success =0;
9999 SELECT @ErrorStatus = @ErrorStatus + 'Update Failed Rollback -6011';
10000 RAISERROR(@ErrorStatus, 16, 1);
10001
10002
10003 END CATCH
10004
10005
10006END
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016GO
10017/****** Object: StoredProcedure [dbo].[pUpdateCertificationText] Script Date: 10/16/2020 7:31:03 PM ******/
10018SET ANSI_NULLS ON
10019GO
10020SET QUOTED_IDENTIFIER ON
10021GO
10022
10023
10024
10025
10026
10027
10028
10029/*************************************************************************************************
10030*Author: Gary Savard
10031*Date: 3/29/2011
10032*Table Name: LUertificationText
10033Description: Update data to LUCertificationText.
10034This updates the LUCertificationText table. The updates should only be done to correct errors and only by an
10035ageny designated representative.
10036**************************************************************************************************/
10037
10038CREATE PROCEDURE [dbo].[pUpdateCertificationText](
10039 @CertificationTextID int,
10040 @CertificationText NVarchar(MAX),
10041 @GuidelinesText NVarchar(MAX),
10042 @ModifiedBy Name,
10043 @Success bit Output,
10044 @ErrorStatus NVarchar(50) Output
10045 )
10046AS
10047SET NOCOUNT ON;
10048BEGIN
10049 DECLARE
10050 @TempCertificationTextID int
10051
10052 SET @TempCertificationTextID =0;
10053 SET @Success = 0;
10054 SET @ErrorStatus ='';
10055
10056
10057
10058 BEGIN
10059 BEGIN TRY
10060 BEGIN TRANSACTION;
10061 IF (@CertificationTextID =0) --Must have a non zero value!
10062 BEGIN
10063 SELECT @ErrorStatus = '-60055 CertificationTextID cannot be NULL or 0';
10064 SET @Success = 0;
10065 RAISERROR(@ErrorStatus, 16,1);
10066 END
10067
10068/****************************************************************************/
10069 --Double check to see that we can find it in the LUCertificationText table before changing things
10070 SELECT @CertificationTextID = CertificationTextID
10071 FROM Foodhself.LUCertificationText
10072 WHERE CertificationTextID = @CertificationTextID
10073
10074 If (@TempCertificationTextID = NULL) OR (@TempCertificationTextID= 0)
10075 BEGIN
10076 SET @ErrorStatus = ' -60052 CertificationTextID Doesnot Exist in LUCertificationText';
10077 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
10078
10079 END
10080
10081/****************************************************************************/
10082
10083 IF @@Error <> 0
10084 BEGIN
10085 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60050';
10086 SET @Success = 0;
10087 RAISERROR(@ErrorStatus, 16,1);
10088 END
10089
10090 --StateID is not updated because that should not change!
10091 UPDATE Foodshelf.LUCertificationText
10092 SET CertificationText = @CertificationText,
10093 GuidelinesText = @GuidelinesText,
10094 ModifiedBy = @ModifiedBy,
10095 ModifiedDate = SYSDATETIME()
10096 WHERE
10097 CertificationTextID = @CertificationTextID
10098 set @success =1;
10099 set @ErrorStatus =0;
10100 COMMIT TRANSACTION;
10101
10102 END TRY
10103
10104 BEGIN CATCH
10105 ROLLBACK TRANSACTION;
10106 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
10107 --We only care if the error was not raised by SSE
10108 IF @@ERROR <> 50000
10109 BEGIN
10110 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
10111 END
10112
10113 SET @Success =0;
10114 SELECT @ErrorStatus= @ErrorStatus +'-60051 Update Failed on CertificationText ';
10115 RAISERROR(@ErrorStatus, 16, 1);
10116
10117
10118 END CATCH
10119
10120 END
10121END
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134GO
10135/****** Object: StoredProcedure [dbo].[pUpdateCity] Script Date: 10/16/2020 7:31:03 PM ******/
10136SET ANSI_NULLS ON
10137GO
10138SET QUOTED_IDENTIFIER ON
10139GO
10140
10141
10142
10143
10144
10145/*************************************************************************************************
10146*Author: Gary Savard
10147*Date: 9 Oct 10
10148*Table Name: LUCity
10149Description: Update data to LUCity.
10150The CityID and StateID must not be 0 when passed in. Both are needed to make the tie.
10151Ideally we would have information on the county as well as the state before we add the city. However,
10152we cannot assume that we have a county, so we will have it to default to 0, if no value is entered.
10153Revisions:
10154GS 20 Oct fixed failure in error handler due to implicit conversion of @@Error, worked intermittantly
10155**************************************************************************************************/
10156
10157CREATE PROCEDURE [dbo].[pUpdateCity](
10158 @CityID int,
10159 @CityName NVarchar(30),
10160 @CityAbbreviation Nvarchar(30) ='',
10161 @StateID int,
10162 @CountyID int = 0,--Default countyID to 0 just in case it comes in later.
10163 @PostalCodeID int =0,--Might be Zero..
10164 @ModifiedBy Name,
10165 @NewCityID int Output,
10166 @Success bit Output,
10167 @ErrorStatus NVarchar(50) Output
10168 )
10169AS
10170SET NOCOUNT ON;
10171BEGIN
10172 DECLARE
10173 @TempCityID int
10174
10175 SET @TempCityID =0;
10176 SET @Success = 0;
10177 SET @ErrorStatus ='';
10178
10179
10180
10181 BEGIN
10182 BEGIN TRY
10183 BEGIN TRANSACTION;
10184 IF (@CityID =0) or (@StateID) = 0 --Must have a state AND city to update!
10185 BEGIN
10186 SELECT @ErrorStatus = '-60055 StateID/CityID cant be NULL or 0';
10187 SET @Success = 0;
10188 RAISERROR(@ErrorStatus, 16,1);
10189 END
10190
10191/****************************************************************************/
10192 --Double check to see that we can find it in the LUCity table before changing things
10193 SELECT @TempCityID = CityID
10194 FROM person.LUCity
10195 WHERE CityID = @CityID and StateID = @StateID
10196
10197 If (@TempCityID = NULL) OR (@TempCityID= 0)
10198 BEGIN
10199 SET @ErrorStatus = ' -60052 City Doesnt Exist in LUCity';
10200 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
10201
10202 END
10203
10204/****************************************************************************/
10205
10206 IF @@Error <> 0
10207 BEGIN
10208 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60050';
10209 SET @Success = 0;
10210 RAISERROR(@ErrorStatus, 16,1);
10211 END
10212
10213 --StateID is not updated because that should not change!
10214 UPDATE Person.LUCity
10215 SET CountyID = @CountyID,
10216 PostalCodeID = @PostalCodeID,
10217 CityName = @CityName,
10218 CityAbbreviation= @CityAbbreviation,
10219 ModifiedBy = @ModifiedBy,
10220 ModifiedDate = SYSDATETIME()
10221 WHERE
10222 STATEID = @StateID and CITYID = @CityID--Could just use City ID
10223
10224 set @success =1;
10225 set @ErrorStatus =0;
10226 COMMIT TRANSACTION;
10227
10228 END TRY
10229
10230 BEGIN CATCH
10231 ROLLBACK TRANSACTION;
10232 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
10233 --We only care if the error was not raised by SSE
10234 IF @@ERROR <> 50000
10235 BEGIN
10236 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
10237 END
10238
10239 SET @Success =0;
10240 SELECT @ErrorStatus= @ErrorStatus +'-60051 Update Failed on City ';
10241 RAISERROR(@ErrorStatus, 16, 1);
10242
10243
10244 END CATCH
10245
10246 END
10247END
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258GO
10259/****** Object: StoredProcedure [dbo].[pUpdateClientFamilyRecord] Script Date: 10/16/2020 7:31:03 PM ******/
10260SET ANSI_NULLS ON
10261GO
10262SET QUOTED_IDENTIFIER ON
10263GO
10264
10265
10266
10267
10268
10269
10270-- =============================================
10271-- Author: Gary Savard
10272-- Create date: 26 Oct 2010
10273-- Description: This is the main stored procedure to update a family member for a client
10274-- in the system. It calls several other stored procedures to do updates into
10275-- selected parts of the DB. Clients and Family members of clients have similar data, but
10276--will use separate stored procedures for clarity. A note can either be a new note or an update to an exising one. If it is a new note, then
10277--the IsNewNoteflag must be passed in with 1 as value.
10278--FOOD. Same idea with the rest of the programs.
10279--IDs that are important such as 'address type' from that lookup table need to be passed in here since they
10280--were selected by the user. No need to try to figure them out in the SP
10281--Certification has its own button so we have a separate stored procedure to deal with that functionality and the same for
10282--family members since they do not have some of the information that we need for the client.
10283
10284--Revisions: 4 Nov 10- Added Client notes insert procedure call
10285-- 13 Dec 10- Added Gender to Update Demographics call
10286-- 1 April 11 - Removed some fields based on Champlain Charity requirements. Added some fields.
10287-- 5 April remove @numberInHousehold, @HomeboundDelivery,@ISPrimaryLanguage,@LanguageId,@Title,@Suffix,@AddressId,@PhoneID
10288-- 11 July 11, Added RTRIM, LTRIM to client's name
10289-- =============================================
10290CREATE PROCEDURE [dbo].[pUpdateClientFamilyRecord] (
10291 @RecordSource NVarchar(8),
10292 @FamilyRelationshipID int,--This is how we know whicy person is being updated, we do not want dupes in the system. A person should be in the familyRelationship table 0to1 times
10293 @PersonID int, --This is the family member that we will be updating
10294 @ClientPersonID int,--This is the client to whom the family member belongs
10295 @DemographicsID int,
10296 @NotesID int =0,
10297 @FirstName Name,
10298 @MiddleName Name = NULL,
10299 @LastName Name,
10300 @DateOfBirth DateTime,
10301 @RelationshipID int,
10302 @RelationshipDescription NVarchar(50)='',
10303 @FamilyStatusType NVarchar(50),
10304 @HousingStatus nVarchar(50),--The TEXT value from the lookup table. Saves having to query by ID later
10305 @Disability NoYesMaybe =0,
10306 @Gender NVarchar(2)='',--Foodshelf and WX may leave blank
10307 @CSFP NoYesMaybe = 0,
10308 @Veteran NoYesMaybe=0,
10309 @HealthInsurance NoYesMaybe =0 ,
10310 @InsuranceType NVarchar(50),
10311 @FoodStamps NoYesMaybe =0,--Three squares
10312 @EducationCategoryID int =0, --Not required for Food shelf
10313 @CountryOfOrigin nVarchar(70)='', --Not required for food shelf
10314 @Race NVarchar(20) =NULL,
10315 @Ethnicity NVarchar(20) =NULL,
10316 @IncomeSourceID int =0,
10317 @IsNewNote bit=0,
10318 @Notes NVarchar(MAX)=NULL,--A single person may have many notes. The notes will be specific to a particular program, so we will not have a single notes table
10319 @ModifiedBy Name,
10320 @NewHouseholdNotesID int Output,--This is only used if there is a new note sent in with the record.
10321 @Success bit Output,
10322 @ErrorStatus Nvarchar(50) Output
10323 )
10324AS
10325
10326
10327SET NOCOUNT ON;
10328 DECLARE
10329 @ValidSource int,
10330 @TempPersonID int,
10331 @Succ bit,
10332 @ErrorMsg NVarchar(50),
10333 @NewClientNotesID int,
10334 @TempClientPersonID int,
10335 @TempFamilyRelationshipID int,
10336 @TempIncomeSourceCount int,
10337 @TempIncomeSourceID int,
10338
10339 @DummyNumberInHousehold int, --just place holder with default of 0
10340 @DummyHomeboundDelivery int,
10341 @DummyIsPrimaryLanguage bit,
10342 @DummyLanguageID int,
10343 @DummyTitle NVarchar(8),
10344 @DummySuffix NVarchar(10),
10345 @DummyEmailAddress NVarchar(50),
10346 @DummyEmailContactPreference bit,
10347 @DummyAddress1 NVarchar (60),
10348 @DummyAddress2 NVarchar (60),
10349 @DummyCity NVarchar (30),
10350 @DummyState NVarchar(2),
10351 @DummyPostalCode NVarchar(10),
10352 @DummyAddressTypeID int,
10353 @DummyPhoneNumber Phone,
10354 @DummyPhoneExtension Nvarchar(8),
10355 @DummyPhoneTypeID int
10356
10357
10358
10359
10360 SET @ValidSource =0;
10361 SET @TempPersonID =0;
10362 SET @NewClientNotesID =0;
10363 SET @Succ =0;
10364 SET @ErrorMsg ='';
10365 SET @TempClientPersonID =0;
10366 SET @TempFamilyRelationshipID =0;
10367 SET @TempIncomeSourceCount =0;
10368 SET @TempIncomeSourceID =0;
10369
10370
10371 SET @DummyNumberInHousehold =0;
10372 SET @DummyHomeboundDelivery=2;--This is set to N/A
10373 SET @DummyIsPrimaryLanguage=0;
10374 SET @DummyLanguageID=0;
10375 SET @DummyTitle = NULL;
10376 SET @DummySuffix = NULL;
10377 SET @DummyEmailAddress =NULL;
10378 SET @DummyEmailContactPreference =0;
10379 SET @DummyAddress1 =NULL;
10380 SET @DummyAddress2 =NULL;
10381 SET @DummyCity = NULL;
10382 SET @DummyState =NULL;
10383 SET @DummyPostalCode =NULL;
10384 SET @DummyAddressTypeID =0;
10385 SET @DummyPhoneNumber =NULL;
10386 SET @DummyPhoneExtension =NULL;
10387 SET @DummyPhoneTypeID =0;
10388 SET @FirstName = LTRIM(RTRIM(@FirstName));
10389 SET @MiddleName = LTRIM(RTRIM(@MiddleName));
10390 SET @LastName = LTRIM(RTRIM(@LastName));
10391
10392 BEGIN TRY
10393 BEGIN TRANSACTION;
10394
10395
10396 --Take the return value and throw error if 0 because we cannot proceed of we don't know
10397 --which set of sps to call.
10398 SET @ValidSource = DBO.ValidateDataSource(@RecordSource);
10399
10400 IF @ValidSource =0
10401 BEGIN
10402 SET @Success =0;
10403 SELECT @ErrorStatus = '-18100 Invalid Record source';
10404 RAISERROR(@ErrorStatus,16,1);
10405 --Raise Error Here because the source is unknown.
10406 END
10407
10408
10409
10410 --The family member must be associated with a ClientPersonID or we bail.
10411
10412 IF @FamilyRelationshipID =0 OR @FamilyRelationshipID IS NULL--Can't update if this is not valid!
10413 BEGIN
10414 SET @Success =0;
10415 SET @ErrorStatus ='-185002 FamilyRelationshipID cant be 0/NULL';
10416 RAISERROR (@ErrorStatus,16,1);
10417 END
10418
10419 SELECT @TempFamilyRelationshipID = FamilyRelationshipID
10420 FROM Person.FamilyRelationships
10421 WHERE FamilyRelationshipID = @FamilyRelationshipID
10422
10423 IF @TempFamilyRelationshipID = 0 OR @TempFamilyRelationshipID IS NULL
10424 BEGIN
10425 SET @Success =0
10426 SET @ErrorStatus ='-185003 Record not found FamilyRelationships';
10427 RAISERROR (@ErrorStatus,16,1);
10428
10429 END
10430 IF @PersonID =0 or @PersonID IS NULL
10431 BEGIN
10432 SET @Success =0;
10433 SET @ErrorStatus = '-185004 PersonID cant be 0/NULL';
10434 RAISERROR(@ErrorStatus,16,1);
10435 END
10436
10437 SELECT @TempPersonID = @PersonID
10438 FROM Person.Person
10439 WHERE PersonID = @PersonID
10440
10441 IF @TempPersonID = 0 OR @TempPersonID IS NULL
10442 BEGIN
10443 SET @Success = 0;
10444 SET @ErrorStatus = '-185005 Person Doesnt exist in Person';
10445 RAISERROR(@ErrorStatus,16,1);
10446 END
10447
10448 IF @ClientPersonID = 0 OR @ClientPersonID IS NULL
10449 BEGIN
10450 SET @Success =0;
10451 SET @ErrorStatus = '-18500 Client does not exist in Person';
10452 RAISERROR(@ErrorStatus,16,1);
10453
10454 END
10455
10456 SELECT @TempClientPersonID = PersonID
10457 FROM Person.Person
10458 WHERE PersonID = @PersonID
10459
10460 IF @TempClientPersonID = 0 OR @TempClientPersonID IS NULL
10461 BEGIN
10462 SET @Success = 0;
10463 SET @ErrorStatus = '-185005 Person Doesnt exist in Person';
10464 RAISERROR(@ErrorStatus,16,1);
10465 END
10466
10467
10468
10469
10470 --Update Person.
10471 BEGIN
10472 EXEC DBO.pUpdatePerson @PersonID,@DummyTitle,@FirstName,@MiddleName,@LastName,@DummySuffix,@DateOfBirth,@DummyEmailAddress,@DummyEmailContactPreference,@ModifiedBy,@Succ OUTPUT,@ErrorMsg OUTPUT;
10473
10474 IF @Succ =0 -- Failure!
10475 BEGIN
10476 SET @Success = @Succ;
10477 SELECT @ErrorStatus = '-18200 Sub Pro UpdatePerson Fail'+ @ErrorMsg;
10478 RAISERROR(@ErrorStatus,16,1);
10479 END
10480 SET @Success =1;
10481 SET @ErrorStatus='';
10482 END
10483
10484 --IF the source is from Food Shelf we cannot assume that we will need to call the address or phone SPs because they
10485 --are not required to take that information. We will consider a NULL or 0 ID in AddressID to mean that this is a Foodshelf
10486
10487
10488 --The address should be the same as that of the client, but we will add it anyway because this person
10489 --may eventually become a client and we will already have an AddressID that we can use and modify the location.
10490
10491
10492 BEGIN
10493 --Commented out because this needs some thought as we go into alpha testing
10494 --IF ((@RecordSource <> 'FOOD') AND (LTRIM(RTRIM(@Address1)) ='') OR (LTRIM(RTRIM(@Address1)) IS NULL) )--This is a problem because address is required
10495 -- BEGIN
10496 -- SET @Succ =0;
10497 -- SET @ErrorStatus ='-18300 Address Required for Non foodshelf intake.';
10498 -- RAISERROR(@ErrorStatus,16,1);
10499 -- END
10500 --The family member is at the same address as the client so we do not put them in the address table. Query them from the family relationship
10501 --IF ((@AddressID <>0) AND (@AddressID IS NOT NULL))
10502 -- BEGIN
10503 -- EXEC DBO.pUpdateAddress @PersonID,@AddressID,@DummyAddress1,@DummyAddress2,@DummyCity,@DummyCounty,@DummyState,@DummyPostalCode,@DummyAddressTypeID,@ModifiedBy, @Succ Output, @ErrorMsg Output ;
10504
10505 -- IF @Succ =0 --Failed, Rollback!
10506 -- BEGIN
10507 -- SET @Success =0;
10508 -- SELECT @ErrorStatus = '-18200 Sub proc Update Address returned error' + @ErrorMsg;
10509 -- RAISERROR (@ErrorSTatus, 16,1);
10510 -- END
10511
10512 --END
10513
10514 --This has been removed because Champlain Charity does not collect family member phone numbers
10515 --Insert Phone Number
10516 --We allow phone number since they may have a cell.
10517 --BEGIN
10518 -- --May need in future
10519 -- --IF ((@RecordSource <> 'FOOD') AND (LTRIM(RTRIM(@PhoneNumber)) ='') OR (LTRIM(RTRIM(@PhoneNumber)) IS NULL) )--This is a problem because Phone Number is required
10520 -- -- BEGIN
10521 -- -- SET @Succ =0;
10522 -- -- SET @ErrorStatus ='-17400 Phone Number Required for Non foodshelf intake.';
10523 -- -- RAISERROR(@ErrorStatus,16,1);
10524 -- -- END
10525
10526 -- IF (@PhoneID<>0) AND (@PhoneID IS NOT NULL)
10527 -- BEGIN
10528 -- EXEC DBO.pUPdatePhone @PhoneID,@PersonID,@PhoneNumber,@PhoneExtension,@PhoneTypeID,@ModifiedBy, @Succ output, @ErrorMsg output ;
10529 -- END
10530
10531 -- IF @Succ =0
10532 -- BEGIN
10533 -- SET @Success =0;
10534 -- SELECT @ErrorStatus = '-18200 Sub proc Update Phone returned fail' + @ErrorMsg;
10535 -- RAISERROR(@ErrorStatus, 16,1);
10536 -- END
10537 --END
10538
10539 --Insert Demographics
10540 BEGIN
10541 EXEC dbo.pUpdateDemographics @DemographicsID,@PersonID,@EducationCategoryID ,@HousingStatus,@DummyNumberInHousehold,@Gender,@Race,@CountryOfOrigin,@Ethnicity,@Disability,@CSFP,@Veteran,@HealthInsurance,@InsuranceType,@FamilyStatusType,@FoodStamps,@DummyHomeboundDelivery,@ModifiedBy,@Succ OUTPUT, @ErrorMsg OUTPUT;
10542
10543 IF @Succ = 0
10544 BEGIN
10545 SET @Success =0;
10546 SELECT @ErrorStatus ='-18200 Sub proc Update Demographics returned fail' + @ErrorMsg;
10547 RAISERROR(@ErrorStatus,16,1);
10548
10549 END
10550 END
10551
10552 --Income source may could possibly be ID 0 which would not be updated since that indicates no selection. This will require a sp at some point
10553 --because there may be >1 income source. For now, we have a 1 to 1 relationship between person and income source. Yup, using a table scan for the
10554 --aggregate, but this will be chaning with future sp
10555 IF EXISTS(SELECT * from Person.Income WHERE PersonID=@PersonID) AND (@IncomeSourceID>0)--Assuming that a good IncomeSourceID is passed in.
10556 BEGIN
10557 Update Person.Income
10558 SET IncomeSourceID = @IncomeSourceID,
10559 ModifiedBy = @ModifiedBy,
10560 ModifiedDate = SYSDATETIME()
10561 WHERE PersonID = @PersonID;
10562 IF @@ERROR >0
10563 BEGIN
10564 SET @Success =0;
10565 SELECT @ErrorStatus ='-18200 Sub proc insert income returned fail' + @ErrorMsg;
10566 RAISERROR(@ErrorStatus,16,1);
10567 END
10568 END--End IF
10569
10570 ELSE
10571 BEGIN
10572 IF (@IncomeSourceID >0)--Only insert if there is a valid IncomeSourceId coming in --only works if we have 1 to 1 relationship and that is all we have for now
10573 BEGIN
10574 INSERT INTO PERSON.Income (IncomeSourceID, PersonID, ModifiedBy, ModifiedDate) VALUES (@IncomeSourceID,@PersonID,@ModifiedBy,SYSDATETIME());
10575 END
10576
10577 IF @@ERROR >0
10578 BEGIN
10579 SET @Success =0;
10580 SELECT @ErrorStatus ='-18200 Sub proc insert income returned fail' + @ErrorMsg;
10581 RAISERROR(@ErrorStatus,16,1);
10582 END
10583 END--End else
10584
10585
10586
10587 --Insert Client Notes if they exist. This insert procedure is for the client, so we do not have
10588 --A value for HouseholdMemberPersonID so we hard code it to 0.
10589
10590 IF (@IsNewNote =1) AND LTRIM(RTRIM(@Notes)) <> ''
10591 BEGIN
10592 EXEC DBO.pInsertHouseholdNotes @ClientPersonID,@PersonID, @Notes,@ModifiedBy,@NewHouseholdNotesID,@Succ OUTPUT,@ErrorMsg OUTPUT;
10593 IF @Succ =0
10594 BEGIN
10595 SET @Success =0;
10596 SET @ErrorStatus ='-18001 New Note Insert Failed';
10597 RAISERROR(@ErrorStatus,16,1);
10598 END
10599 SET @Success =1;
10600 SET @ErrorStatus ='';
10601
10602 END
10603
10604 IF (@IsNewNote = 0) AND (@NotesID)<>0 AND @NotesID IS NOT NULL
10605 BEGIN
10606 EXEC DBO.pUpdateHouseholdNotes @NotesID,@ClientPersonID,@PersonID,@Notes,@ModifiedBy,@Succ OUTPUT,@ErrorMsg OUTPUT;
10607 IF @Succ =0
10608 BEGIN
10609 SET @Success =0
10610 SET @ErrorStatus = '-18200 Update Failed Notes' + @ErrorMsg;
10611 RAISERROR(@ErrorStatus,16,1);
10612 END
10613
10614 END
10615
10616 --We have everything except for the relationship to the client, so we do that last.
10617
10618
10619 EXEC DBO.pUpdateFamilyRelationship @FamilyRelationshipID,@PersonID, @ClientPersonID,@RelationshipID,@RelationshipDescription,@ModifiedBy, @Succ OUTPUT, @ErrorMsg OUTPUT;
10620 IF @Succ =0
10621 BEGIN
10622 SET @Success =0;
10623 SET @ErrorStatus ='-17001 Insert Failed Family Relationship'+ @ErrorMsg
10624 RAISERROR(@ErrorStatus,16,1);
10625 END
10626
10627
10628
10629
10630
10631 --We are using nested transactions to make sure one exists in case
10632 --of a rollback in subordinate Stored Procedure
10633 IF @@TRANCOUNT > 0
10634 BEGIN
10635 SET @Success =1;
10636 SET @ErrorStatus='';
10637 COMMIT TRANSACTION;
10638 END
10639END
10640END TRY
10641
10642BEGIN CATCH
10643 IF @@TRANCOUNT >0
10644 BEGIN
10645 SET @Success =0
10646 SET @ErrorStatus =@ErrorStatus + ' ' +@@Error
10647 ROLLBACK TRANSACTION;
10648
10649 RAISERROR(@ErrorStatus,16,1);
10650 END
10651END CATCH
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671GO
10672/****** Object: StoredProcedure [dbo].[pUpdateClientRecord] Script Date: 10/16/2020 7:31:03 PM ******/
10673SET ANSI_NULLS ON
10674GO
10675SET QUOTED_IDENTIFIER ON
10676GO
10677
10678
10679
10680-- =============================================
10681-- Author: Gary Savard
10682-- Create date: 26 Oct 2010
10683-- Description: This is the main stored procedure to Update a new client
10684-- into the system. It calls several other stored procedures to do Updates into
10685-- selected parts of the DB. Clients and Family members of clients have similar data, but
10686--will use separate stored procedures for clarity.
10687--When updating we have to make some assumptions for food shelf.IF the client is in and their address has changed,
10688--we have to assume that the input FoodTypeGiven is for the current visit, so we do not update that. Instead, we insert a new
10689--row for the current visit.
10690--@RecordSource can be FOOD,WX,MICRO,TENANT,COMMACT,ADMIN. This will be used to only execute parts of the
10691--SP relevant to the client intake data brought in. For example, Foodshelf requires that a record be
10692--set for the type of food taken, but this is not required elsewhere so we only execute that SP If things come from
10693--FOOD. Same idea with the rest of the programs.
10694--IDs that are important such as 'address type' from that lookup table need to be passed in here since they
10695--were selected by the user. No need to try to figure them out in the SP
10696--Certification has its own button so we have a separate stored procedure to deal with that functionality and the same for
10697--family members since they do not have some of the information that we need for the client.
10698--4 April 2011. Added multiple addresses, FamilyStatusType, Insurance Type,Changed AddressTypeID to int
10699--19 April 2011 - Addes @IsUpdateBreadGroceries. If this is 1 then that SP is executed.
10700--19 July 2011- Added RTRIM, LTRIM to client name.
10701CREATE PROCEDURE [dbo].[pUpdateClientRecord] (
10702 @PersonID int,
10703 @HouseHoldPersonID int =0,--This will be null or zero on input if this is a client and not a family member
10704 @PhysicalAddressID int,
10705 @MailAddressID int,
10706 @DemographicsID int,
10707 @PhoneID1 int,
10708 @PhoneID2 int,
10709 @RecordSource NVarchar (8), --This allows for the sub sp's to be executed or skipped based on what data is to be saved
10710 @Title NVarchar(8) =NULL,
10711 @FirstName Name,
10712 @MiddleName Name = NULL,
10713 @LastName Name,
10714 @Suffix NVarchar(10) = NULL,
10715 @Gender NVarchar(2) = NULL,
10716 @DateOfBirth DateTime,
10717 @PhysicalAddress1 NVarchar(60) =NULL,--Only for Foodshelf!!
10718 @PhysicalAddress2 NVarchar(60) = NULL,
10719 @PhysicalCity NVarchar(30),
10720 @PhysicalCounty NVarchar(30) = NULL,
10721 @PhysicalState NVarchar(2),
10722 @PhysicalPostalCode NVarchar(10),
10723 @PhysicalAddressTypeID int,--From the Lookup based on user input. May not need if Foodshelf
10724 @MailAddress1 NVarchar(60) =NULL,--Only for Foodshelf!!
10725 @MailAddress2 NVarchar(60) = NULL,
10726 @MailCity NVarchar(30),
10727 @MailCounty NVarchar(30) = NULL,
10728 @MailState NVarchar(2),
10729 @MailPostalCode NVarchar(10),
10730 @MailAddressTypeID int,
10731 @EmailAddress Nvarchar(50) = NULL,
10732 @EmailContactPreference NoYes =0,
10733 @PhoneNumber Phone ='',
10734 @PhoneExtension Nvarchar(8) ='', --may not be implemented yet
10735 @PhoneTypeID int =0, --Food shelf again!
10736 @PhoneNumber2 Phone ='',
10737 @PhoneExtension2 Nvarchar(8) ='',
10738 @PhoneTypeID2 int =0,
10739 @FamilyStatusType NVarchar(50),
10740 @HousingStatus nVarchar(50),--The TEXT value from the lookup table. Saves having to query by ID later
10741 @Disability NoYesMaybe =0,
10742 @CSFP NoYesMaybe = 0,
10743 @Veteran NoYesMaybe=0,
10744 @HealthInsurance NoYesMaybe =0 ,
10745 @InsuranceType NVarchar(50),
10746 @FoodStamps NoYesMaybe =0,--Three squares
10747 @HomeboundDelivery NoYesMaybe =0,
10748 @LanguageID int =0,--This is only important for volunteers and that funtionality has not been developed yet.
10749 @IsPrimaryLanguage bit =0,
10750 @EducationCategoryID int =0,
10751 @CountryOfOrigin nVarchar(70)='',
10752 @Race NVarchar(20) =NULL,
10753 @Ethnicity NVarchar(20) =NULL,
10754 @NumberInHousehold int,
10755 @IncomeSourceID int =0,
10756 @HouseholdNotesID int=0, --Necessary if this is an existing note. Default to 0 if new note to avoid NULLs
10757 @Notes NVarchar(MAX)=NULL,--A single person may have many notes. The notes will be specific to a particular program, so we will not have a single notes table
10758 @IsNewNote bit,
10759 @FoodGiven FoodShelf.GroceryOrBreadProduce,
10760 @FoodReceivedDate DateTime,
10761 @IsUpdateBreadGroceries int,--Only if the client came in for these items
10762 @ModifiedBy Name,
10763 @NewPhysicalAddressID int Output,
10764 @NewMailAddressID int Output,
10765 @NewPhoneID int Output,
10766 @NewPhoneID2 int Output,
10767 @NewHouseholdNotesID int Output,
10768 @Success bit Output,
10769 @ErrorStatus Nvarchar(50) Output
10770 )
10771AS
10772
10773
10774SET NOCOUNT ON;
10775 DECLARE
10776 @ValidSource int,
10777 @CheckPersonID int,
10778 @CheckAddressID int,
10779 @CheckPhoneID int,
10780 @Succ bit,
10781 @ErrorMsg NVarchar(50),
10782 @CheckDemographicsID int, --Not using here, just a place holder!
10783 @NewFoodTypeGivenID int -- We don't do anything with this. Just receives SP output for now.
10784
10785 SET @ValidSource =0;
10786 SET @CheckPersonID =0;
10787 SET @CheckAddressID =0;
10788 SET @CheckPhoneID = 0;
10789 SET @CheckDemographicsID =0;
10790 SET @NewFoodTypeGivenID =0;
10791 SET @Succ =0;
10792 SET @Success =1;
10793 SET @ErrorMsg ='';
10794 SET @FirstName = LTRIM(RTRIM(@FirstName));
10795 SET @MiddleName = LTRIM(RTRIM(@MiddleName));
10796 SET @LastName = LTRIM(RTRIM(@LastName));
10797
10798BEGIN
10799 BEGIN TRY
10800 BEGIN TRANSACTION;
10801
10802
10803 --Take the return value and throw error if 0 because we cannot proceed of we don't know
10804 --which set of sps to call.
10805 SET @ValidSource = DBO.ValidateDataSource(@RecordSource);
10806
10807 IF @ValidSource =0
10808 BEGIN
10809 SET @Success =0;
10810 SELECT @ErrorStatus = '-13100 Invalid Record source';
10811 RAISERROR(@ErrorStatus,16,1);
10812 --Raise Error Here because the source is unknown.
10813 END
10814
10815 --Check to see if the person is in the DB. IF not, we are going to bail!
10816 BEGIN
10817 SELECT @CheckPersonID = PersonID
10818 FROM Person.Person
10819 WHERE PersonID = @PersonID
10820 IF @CheckPersonID = 0 OR @CheckPersonID IS NULL -- Not Good! Bail out!
10821 BEGIN
10822 SET @Success = 0;
10823 SET @ErrorStatus = '-1005 PersonId cant be 0/Null';
10824 RAISERROR(@ErrorStatus,16,1);
10825 END
10826
10827 EXEC DBO.pUpdatePerson @PersonID,@Title,@FirstName,@MiddleName,@LastName,@Suffix, @DateOfBirth,@EmailAddress,@EmailContactPreference,@ModifiedBy,@Succ Output, @ErrorMsg Output;
10828
10829 IF @Succ =0 -- Failure!
10830 BEGIN
10831 SET @Success = @Succ;
10832 SELECT @ErrorStatus = '-13200 Sub Pro update person Fail'+ @ErrorMsg;
10833 RAISERROR(@ErrorStatus,16,1);
10834 END
10835 END
10836
10837 --IF the source is from Food Shelf we cannot assume that we will need to call the address or phone SPs because they
10838 --are not required to take that information.
10839 --IF we have a good PersonID returned, we continue to Address
10840
10841
10842 --The record we are updating may have been originally from FoodShelf so we may not have an address. If the AddressID is 0
10843 --and the @address1 is not blank, we will insert an address. If We have an AddressID that is > 0, we will continue with
10844 --an update and not an insert.
10845 IF (@PhysicalAddressID = 0 OR @PhysicalAddressID IS NULL) AND ((LTRIM(RTRIM(@PhysicalAddress1)) <> '') AND (@PhysicalAddress1 IS NOT NULL))
10846 BEGIN
10847 EXEC DBO.pInsertAddress @PersonID, @PhysicalAddress1,@PhysicalAddress2, @PhysicalCity,@PhysicalCounty,@PhysicalState,@PhysicalPostalCode,@PhysicalAddressTypeID,@ModifiedBy, @NewPhysicalAddressID Output,@Succ Output, @ErrorMsg Output ;
10848
10849 IF @Succ =0 --Failed, Rollback!
10850 BEGIN
10851 SET @Success =0;
10852 SELECT @ErrorStatus = '-13200 Sub proc call Insert PhysAddress returned error' + @ErrorMsg;
10853 RAISERROR (@ErrorSTatus, 16,1);
10854 END
10855
10856 END
10857
10858 ELSE IF @PhysicalAddressID >0 --Slam the record in if it exists.
10859 BEGIN
10860 SELECT @CheckAddressID = AddressID
10861 FROM Person.Address
10862 WHERE
10863 AddressID = @PhysicalAddressID
10864
10865 IF @CheckAddressID = 0 OR @CheckAddressID IS NULL --Something is wrong! Bail!
10866 BEGIN
10867 SET @Success =0;
10868 SET @ErrorStatus = '-7014 Invalid PhysicalAddressID update failed';
10869 RAISERROR(@ErrorStatus,16,1);
10870 END
10871
10872
10873 EXEC DBO.pUpdateAddress @PersonId, @PhysicalAddressID, @PhysicalAddress1, @PhysicalAddress2, @PhysicalCity,@PhysicalCounty,@PhysicalState,@PhysicalPostalCode,@PhysicalAddressTypeID,@ModifiedBy,@Succ output,@ErrorMsg output;
10874
10875 IF @Succ =0
10876 BEGIN
10877 SET @Success =0;
10878 SELECT @ErrorStatus = '-13200 Sub proc call Update PhysAddress returned error' + @ErrorMsg;
10879 RAISERROR (@ErrorSTatus, 16,1);
10880 END
10881 END
10882 --One more time through this logic for mailing address
10883 IF (@MailAddressID = 0 OR @MailAddressID IS NULL) AND ((LTRIM(RTRIM(@MailAddress1)) <> '') AND (@MailAddress1 IS NOT NULL))
10884 BEGIN
10885 EXEC DBO.pInsertAddress @PersonID, @MailAddress1,@MailAddress2, @MailCity,@MailCounty,@MailState,@MailPostalCode,@MailAddressTypeID,@ModifiedBy, @NewMailAddressID Output,@Succ Output, @ErrorMsg Output ;
10886
10887 IF @Succ =0 --Failed, Rollback!
10888 BEGIN
10889 SET @Success =0;
10890 SELECT @ErrorStatus = '-13200 Sub proc call Insert Address returned error' + @ErrorMsg;
10891 RAISERROR (@ErrorSTatus, 16,1);
10892 END
10893
10894 END
10895
10896 ELSE IF @MailAddressID >0 --Slam the record in if it exists.
10897 BEGIN
10898 SELECT @CheckAddressID = AddressID
10899 FROM Person.Address
10900 WHERE
10901 AddressID = @MailAddressID
10902
10903 IF @CheckAddressID = 0 OR @CheckAddressID IS NULL --Something is wrong! Bail!
10904 BEGIN
10905 SET @Success =0;
10906 SET @ErrorStatus = '-7014 Invalid MailAddressID update failed';
10907 RAISERROR(@ErrorStatus,16,1);
10908 END
10909
10910
10911 EXEC DBO.pUpdateAddress @PersonId, @MailAddressID, @MailAddress1, @MailAddress2, @MailCity,@MailCounty,@MailState,@MailPostalCode,@MailAddressTypeID,@ModifiedBy,@Succ output,@ErrorMsg output;
10912
10913 IF @Succ =0
10914 BEGIN
10915 SET @Success =0;
10916 SELECT @ErrorStatus = '-13200 Sub proc call Update Address returned error' + @ErrorMsg;
10917 RAISERROR (@ErrorSTatus, 16,1);
10918 END
10919 END
10920
10921 --Insert or update Phone Number same rules as for Address
10922 IF @PhoneID1 = 0 OR @PhoneID1 IS NULL AND (LTRIM(RTRIM(@PhoneNumber))<>'' AND @PhoneNumber IS NOT NULL)
10923 BEGIN
10924 EXEC DBO.pInsertPhone @PersonID,@PhoneNumber, @PhoneExtension,@PhoneTypeID,@ModifiedBy,@NewPhoneID output, @Succ output, @ErrorMsg output ;
10925
10926 IF @Succ =0
10927 BEGIN
10928 SET @Success =0;
10929 SELECT @ErrorStatus = '-13200 Sub proc InsertPhone fail' + @ErrorMsg;
10930 RAISERROR(@ErrorStatus, 16,1);
10931 END
10932
10933
10934 END
10935 ELSE IF @PhoneID1 >0
10936 BEGIN
10937 SELECT @CheckPhoneID = PhoneID
10938 From Person.Phone
10939 WHERE
10940 PhoneID = @PhoneID1
10941 IF @CheckPhoneID = 0 OR @CheckPhoneID IS NULL --Something is wrong! Bail!
10942 BEGIN
10943 SET @Success =0;
10944 SET @ErrorStatus = '-8008 Invalid PhoneID update failed';
10945 RAISERROR(@ErrorStatus,16,1);
10946 END
10947
10948 BEGIN
10949 EXEC DBO.pUpdatePhone @PhoneID1,@PersonID,@PhoneNumber, @PhoneExtension,@PhoneTypeID,@ModifiedBy,@Succ output, @ErrorMsg output;
10950 END
10951
10952 IF @Succ =0
10953 BEGIN
10954 SET @Success =0;
10955 SELECT @ErrorStatus = '-13200 Sub proc updatephone fail' + @ErrorMsg;
10956 RAISERROR(@ErrorStatus, 16,1);
10957 END
10958 END
10959 --One more time for second phone
10960 SET @CheckPhoneID =0;--Reset to use again
10961 IF @PhoneID2 = 0 OR @PhoneID2 IS NULL AND (LTRIM(RTRIM(@PhoneNumber2))<>'' AND @PhoneNumber2 IS NOT NULL)
10962 BEGIN
10963 EXEC DBO.pInsertPhone @PersonID,@PhoneNumber2, @PhoneExtension2,@PhoneTypeID2,@ModifiedBy,@NewPhoneID2 output, @Succ output, @ErrorMsg output ;
10964
10965 IF @Succ =0
10966 BEGIN
10967 SET @Success =0;
10968 SELECT @ErrorStatus = '-13200 Sub proc InsertPhone fail' + @ErrorMsg;
10969 RAISERROR(@ErrorStatus, 16,1);
10970 END
10971
10972 END
10973 ELSE IF @PhoneID2 >0
10974 BEGIN
10975 SELECT @CheckPhoneID = PhoneID
10976 From Person.Phone
10977 WHERE
10978 PhoneID = @PhoneID2
10979 IF @CheckPhoneID = 0 OR @CheckPhoneID IS NULL --Something is wrong! Bail!
10980 BEGIN
10981 SET @Success =0;
10982 SET @ErrorStatus = '-8008 Invalid PhoneID update failed';
10983 RAISERROR(@ErrorStatus,16,1);
10984 END
10985
10986 BEGIN
10987 EXEC DBO.pUpdatePhone @PhoneID2,@PersonID,@PhoneNumber2, @PhoneExtension2,@PhoneTypeID2,@ModifiedBy,@Succ output, @ErrorMsg output;
10988 END
10989
10990 IF @Succ =0
10991 BEGIN
10992 SET @Success =0;
10993 SELECT @ErrorStatus = '-13200 Sub proc updatephone fail' + @ErrorMsg;
10994 RAISERROR(@ErrorStatus, 16,1);
10995 END
10996 END
10997
10998
10999 --Update Demographics... Everyone needs demographics in the basic record, so no problems here with inserts.
11000 BEGIN
11001 SELECT @CheckDemographicsID = DemographicsID
11002 FROM Person.Demographics
11003 WHERE
11004 DemographicsID = @DemographicsID
11005 IF @DemographicsID = 0 OR @DemographicsID IS NULL --Something is wrong! Bail!
11006 BEGIN
11007 SET @Success =0;
11008 SET @ErrorStatus = '-2021 Invalid DemographicsID update failed';
11009 RAISERROR(@ErrorStatus,16,1);
11010 END
11011 EXEC dbo.pUpdateDemographics @DemographicsID, @PersonID,@EducationCategoryID ,@HousingStatus,@NumberInHousehold,@Gender,@Race,@CountryOfOrigin,@Ethnicity,@Disability,@CSFP,@Veteran,@HealthInsurance,@InsuranceType,@FamilyStatusType,@FoodStamps,@HomeboundDelivery,@ModifiedBy,@Succ OUTPUT, @ErrorMsg OUTPUT;
11012
11013 IF @Succ = 0
11014 BEGIN
11015 SET @Success =0;
11016 SELECT @ErrorStatus = '-2021 sub proc Update Demographics fail' + @ErrorMsg;
11017 RAISERROR(@ErrorStatus,16,1);
11018
11019 END
11020 END
11021 --Check Income Source, If we find that this source is any value, including zero we update. This will have to be modified in the future
11022 --to cope with multiple values on input. Question, If someone has multiple income sources on one visit and then selects only 1 on the next, does that mean that the others are gone?
11023 IF @IncomeSourceID <>0
11024 BEGIN
11025 UPDATE Person.Income SET
11026 IncomeSourceID = @IncomeSourceID,
11027 ModifiedBy = @ModifiedBy,
11028 ModifiedDate = SYSDATETIME()
11029 WHERE PersonID = @PersonID
11030
11031 END
11032
11033 --This is where we check household notes input to see if it is a new note or an update to an existing one.
11034 IF @HouseholdNotesID = 0 AND @IsNewNote =0 AND LTRIM(RTRIM(@Notes)) <>''--We have a problem! No such thing as an old note with 0 ID! Bail out!
11035 BEGIN
11036 SET @Success =0;
11037 SET @ErrorStatus ='-14008 HouseoldNoteID cant be 0 for update';
11038 RAISERROR(@ErrorStatus,16,1);
11039 END
11040
11041
11042 IF (@IsNewNote =0 AND @HouseholdNotesID <> 0)--Update! We will assume that even a blank note is an update. Don't want to second guess the user!
11043 BEGIN
11044 EXEC dbo.pUpdateHouseholdNotes @HouseholdNotesID,@PersonID,@HouseHoldPersonID, @Notes,@ModifiedBy,@Success,@ErrorStatus;
11045 IF @Success =0
11046 BEGIN
11047 SET @Success =0; --redundant :)
11048 SET @ErrorStatus = @ErrorStatus + ' -1350 Update Client Record Failed';
11049 RAISERROR (@ErrorStatus,16,1);
11050 END
11051 END
11052 ELSE IF LTRIM(RTRIM(@Notes)) <> '' -- Insert New Record
11053 BEGIN
11054 EXEC dbo.pInsertHouseholdNotes @PersonID,@HouseHoldPersonID,@Notes,@ModifiedBy,@NewHouseholdNotesID,@Success,@ErrorStatus;
11055 IF @Success =0
11056 BEGIN
11057 SET @Success =0;--Redundant
11058 SET @ErrorStatus = @ErrorStatus + ' -14001 Insert HouseholdNotes Failed';
11059 RAISERROR(@ErrorStatus,16,1);
11060 END
11061 END
11062
11063
11064
11065 --This is the same as the pInsertClientRecord procedure
11066 --IF source is foodshelf, we need to capture whether they were in for bread/produce or groceries
11067
11068 IF @RecordSource ='FOOD' AND @IsUpdateBreadGroceries =1 --This is not just an update, but a foodshelf update so we make this call.
11069 BEGIN
11070 EXEC DBO.pInsertFoodTypeGiven @PersonID,@FoodReceivedDate,@FoodGiven,@ModifiedBy,@NewFoodTypeGivenID OUTPUT, @Succ OUTPUT, @ErrorMsg OUTPUT;
11071 IF @Succ =0
11072 BEGIN
11073 SET @Success =0;
11074 SELECT @ErrorStatus ='-600021 Insert FoodType fail' + @ErrorMsg;
11075 RAISERROR (@ErrorStatus,16,1);
11076 END
11077 END
11078
11079
11080
11081 --We are using nested transactions to make sure one exists in case
11082 --of a rollback in subordinate Stored Procedure
11083 IF @@TRANCOUNT > 0
11084 BEGIN
11085 SET @Success =1;
11086 SET @ErrorStatus='';
11087
11088 COMMIT TRANSACTION;
11089 END
11090
11091END TRY
11092
11093BEGIN CATCH
11094 IF @@TRANCOUNT >0
11095 BEGIN
11096 SET @Success =0
11097 SET @ErrorStatus =@ErrorStatus + ' ' +@@Error
11098 ROLLBACK TRANSACTION;
11099
11100 RAISERROR(@ErrorStatus,16,1);
11101 END
11102END CATCH
11103
11104
11105 END
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118GO
11119/****** Object: StoredProcedure [dbo].[pUpdateContactType] Script Date: 10/16/2020 7:31:03 PM ******/
11120SET ANSI_NULLS ON
11121GO
11122SET QUOTED_IDENTIFIER ON
11123GO
11124
11125
11126
11127
11128
11129/*************************************************************************************************
11130*Author: Gary Savard
11131*Date: 9 Oct 10
11132*Table Name: LUContactType
11133Description: Update data to LUContactType.
11134**************************************************************************************************/
11135
11136CREATE PROCEDURE [dbo].[pUpdateContactType](
11137 @ContactTypeID int,
11138 @Name Nvarchar(50) ,
11139 @ModifiedBy Name,
11140 @Success bit Output,
11141 @ErrorStatus NVarchar(50) Output
11142 )
11143AS
11144SET NOCOUNT ON;
11145
11146 DECLARE
11147 @TempNewContactID int
11148
11149 SET @TempNewContactID =0;
11150 SET @Success = 0;
11151 SET @ErrorStatus ='';
11152
11153
11154
11155 BEGIN
11156 BEGIN TRY
11157 BEGIN TRANSACTION;
11158
11159 IF (@ContactTypeID = 0) OR (@ContactTypeID IS NULL)
11160 BEGIN
11161 SET @ErrorStatus = ' -60022 Contact Type already exists in LUContactType';
11162 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
11163 END
11164
11165 SELECT @TempNewContactID = ContactTypeID
11166 FROM person.LUContactType
11167 WHERE ContactTypeID = @ContactTypeID
11168
11169 IF @TempNewContactID =0
11170 BEGIN
11171 SET @ErrorStatus = ' -60028 Contact Type doesnt exist in LUContactType';
11172 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
11173 END
11174
11175
11176
11177 IF @@Error <> 0
11178 BEGIN
11179 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60020';
11180 SET @Success = 0;
11181 RAISERROR(@ErrorStatus, 16,1);
11182 END
11183
11184 UPDATE Person.LUContactType
11185 SET Name = @Name,
11186 ModifiedDate = SYSDATETIME(),
11187 ModifiedBy = @ModifiedBy
11188 WHERE ContactTypeID = @ContactTypeID
11189
11190
11191 set @success =1;
11192 set @ErrorStatus =0;
11193 COMMIT TRANSACTION;
11194
11195 END TRY
11196
11197 BEGIN CATCH
11198 ROLLBACK TRANSACTION;
11199 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
11200 --We only care if the error was not raised by SSE
11201 IF @@ERROR <> 50000
11202 BEGIN
11203 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
11204 END
11205 SET @Success =0;
11206 SELECT @ErrorStatus= @ErrorStatus + '-60021 Update Failed on LUContactType';
11207 RAISERROR(@ErrorStatus, 16, 1);
11208
11209
11210 END CATCH
11211
11212 END
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224GO
11225/****** Object: StoredProcedure [dbo].[pUpdateCountryOfOrigin] Script Date: 10/16/2020 7:31:03 PM ******/
11226SET ANSI_NULLS ON
11227GO
11228SET QUOTED_IDENTIFIER ON
11229GO
11230
11231
11232
11233
11234
11235
11236/*************************************************************************************************
11237*Author: Gary Savard
11238*Date: 9 Oct 10
11239*Table Name: LUCountryOfOrigin
11240Description: Updates data to LUCountryOfOrigin.
11241**************************************************************************************************/
11242
11243CREATE PROCEDURE [dbo].[pUpdateCountryOfOrigin](
11244 @CountryID int,
11245 @CountryAbbreviation Nvarchar(30) ='',
11246 @CountryName Nvarchar(50),
11247 @FIPSCode NVarchar(2)='',
11248 @ModifiedBy Name,
11249 @Success bit Output,
11250 @ErrorStatus NVarchar(50) Output
11251 )
11252AS
11253SET NOCOUNT ON;
11254
11255 DECLARE
11256 @TempNewCountryID int
11257
11258 SET @TempNewCountryID =0;
11259 SET @Success = 0;
11260 SET @ErrorStatus ='';
11261
11262
11263/****************************************************************************/
11264
11265
11266
11267
11268 BEGIN
11269 BEGIN TRY
11270 BEGIN TRANSACTION;
11271 IF (@CountryID = 0) OR (@CountryID IS NULL)
11272 BEGIN
11273 SET @ErrorStatus = ' -60035 CountryID Cant be 0/NULL';
11274 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
11275 END
11276
11277 SELECT @TempNewCountryID = CountryID
11278 FROM person.LUCountryOfOrigin
11279 WHERE CountryID = @CountryID
11280
11281 IF @TempNewCountryID =0
11282 BEGIN
11283 SET @ErrorStatus = ' -60038 Country doesnt exists in LUCountryOfOrigin';
11284 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
11285
11286 END
11287
11288/****************************************************************************/
11289
11290 IF @@Error <> 0
11291 BEGIN
11292 SELECT @ErrorStatus = @@ERROR + '-60030';
11293 SET @Success = 0;
11294 RAISERROR(@ErrorStatus, 16,1);
11295 END
11296
11297 UPDATE Person.LUCountryOfOrigin
11298 SET CountryAbbreviation = @CountryAbbreviation,
11299 CountryName = @CountryName,
11300 FIPSCode = @FIPSCode,
11301 ModifiedDate = SYSDATETIME(),
11302 ModifiedBy = @ModifiedBy
11303 WHERE CountryID = @CountryID
11304
11305
11306 set @success =1;
11307 set @ErrorStatus =0;
11308 COMMIT TRANSACTION;
11309
11310 END TRY
11311
11312 BEGIN CATCH
11313 ROLLBACK TRANSACTION;
11314 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
11315 --We only care if the error was not raised by SSE
11316 IF @@ERROR <> 50000
11317 BEGIN
11318 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
11319 END
11320 SET @Success =0;
11321 SELECT @ErrorStatus= @ErrorStatus + '-60031 Update Failed Rollback';
11322 RAISERROR(@ErrorStatus, 16, 1);
11323
11324
11325 END CATCH
11326 END
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340GO
11341/****** Object: StoredProcedure [dbo].[pUpdateCounty] Script Date: 10/16/2020 7:31:03 PM ******/
11342SET ANSI_NULLS ON
11343GO
11344SET QUOTED_IDENTIFIER ON
11345GO
11346
11347
11348
11349
11350
11351
11352
11353/*************************************************************************************************
11354*Author: Gary Savard
11355*Date: 9 Oct 10
11356*Table Name: LUCounty
11357Description: UPdates data to LUCounty.
11358**************************************************************************************************/
11359
11360CREATE PROCEDURE [dbo].[pUpdateCounty](
11361 @CountyID int,
11362 @CountyName NVarchar(20),
11363 @StateID int,
11364 @CityID int = 0,--Default cityID to 0 just in case it comes in later.
11365 @ModifiedBy Name,
11366 @Success bit Output,
11367 @ErrorStatus NVarchar(50) Output
11368 )
11369AS
11370SET NOCOUNT ON;
11371
11372 DECLARE
11373 @TempCountyID int
11374
11375 SET @TempCountyID =0;
11376 SET @Success = 0;
11377 SET @ErrorStatus ='';
11378
11379
11380
11381
11382 BEGIN
11383 BEGIN TRY
11384 BEGIN TRANSACTION;
11385 --The county must be tied to a state so we need to have non 0's and non-nulls in both. If one
11386 --is found and not the other, it is an orphaned record. This error could be made more granular
11387 --in the future, if we are concerned with orphaned records.
11388 IF ((@CountyID = 0) or (@CountyID IS NULL)) OR ((@StateID = 0) OR (@StateID IS NULL))
11389
11390 BEGIN
11391 SELECT @ErrorStatus = '-60065 StateID/CountyID cant be NULL or 0';
11392 SET @Success = 0;
11393 RAISERROR(@ErrorStatus, 16,1);
11394 END
11395
11396/****************************************************************************/
11397 --Check to see if the number passed in is really in the table
11398 SELECT @TempCountyID = CountyID
11399 FROM person.LUCounty
11400 WHERE CountyID = @CountyID and StateID = @StateID
11401 If (@TempCountyID =0) OR (@TempCountyID IS NULL)
11402 BEGIN
11403 SET @ErrorStatus = ' -60068 County Does not exist LUCounty';
11404 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
11405
11406 END
11407
11408/****************************************************************************/
11409
11410 IF @@Error <> 0
11411 BEGIN
11412 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60060';
11413 SET @Success = 0;
11414 RAISERROR(@ErrorStatus, 16,1);
11415 END
11416
11417 UPDATE Person.LUCounty
11418 SET CityID = @CityID,
11419 CountyName = @CountyName,
11420 ModifiedDate = SYSDATETIME(),
11421 ModifiedBy = @ModifiedBy
11422
11423
11424 set @success =1;
11425 set @ErrorStatus =0;
11426 COMMIT TRANSACTION;
11427
11428 END TRY
11429
11430
11431 BEGIN CATCH
11432 ROLLBACK TRANSACTION;
11433 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
11434 --We only care if the error was not raised by SSE
11435 IF @@ERROR <> 50000
11436 BEGIN
11437 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
11438 END
11439 SET @Success =0;
11440 SELECT @ErrorStatus= @ErrorStatus +'-60061 Update Failed LUCounty ';
11441 RAISERROR(@ErrorStatus, 16, 1);
11442
11443
11444 END CATCH
11445 END
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461GO
11462/****** Object: StoredProcedure [dbo].[pUpdateDemographics] Script Date: 10/16/2020 7:31:03 PM ******/
11463SET ANSI_NULLS ON
11464GO
11465SET QUOTED_IDENTIFIER ON
11466GO
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482/*************************************************************************************************
11483
11484*Author: Gary Savard
11485*Date: 8 Oct 10
11486*Table Name: Demographics
11487Description: Updates data to Demographics table
11488Revisions: 1 Nov 10. Modified to include housing status as nvarchar(50)
11489 1 April 11. Added @InsuranceType and @FamilyStatusType
11490**************************************************************************************************/
11491CREATE PROCEDURE [dbo].[pUpdateDemographics](
11492 @DemographicsID int,
11493 @PersonID int,
11494 @EducationCategoryID int,
11495 @HousingStatus NVarchar(50) = NULL,
11496 @NumberInHousehold int,
11497 @Gender NVarchar(2) = NULL,
11498 @Race Nvarchar(20) = NULL,
11499 @CountryOfOrigin NVarchar(70) =NULL,
11500 @Ethnicity Nvarchar(20) = Null,
11501 @Disability NoYesMaybe =0,
11502 @CSFP NoYesMaybe = 0,
11503 @Veteran NoYesMaybe=0,
11504 @HealthInsurance NoYesMaybe =0 ,
11505 @InsuranceType NVarchar(50),
11506 @FamilyStatusType Nvarchar(50),
11507 @FoodStamps NoYesMaybe =0,
11508 @HomeboundDelivery NoYesMaybe =0,
11509 @ModifiedBy Name,
11510 @Success bit Output,
11511 @ErrorStatus Nvarchar(50) Output
11512 )
11513AS
11514SET NOCOUNT ON;
11515
11516 DECLARE
11517 @TempDemographicsID int,
11518 @TempPersonID int
11519
11520 SET @TempPersonID =0;
11521 SET @Success = 0;
11522 SET @ErrorStatus ='';
11523 SET @TempDemographicsID =0;
11524
11525
11526
11527
11528 BEGIN
11529 BEGIN TRY
11530 BEGIN TRANSACTION;
11531 IF ((@DemographicsID = 0) OR (@DemographicsID IS NULL)) OR ((@PersonID = 0) OR (@PersonID IS NULL))
11532 BEGIN
11533 SELECT @ErrorStatus = '2005 DemographicsID/PersonID cant be 0/NULL';
11534 SET @Success = 0;
11535 RAISERROR(@ErrorStatus, 16,1);
11536 END
11537
11538 --Check to see that the IDs match.. paranoid? NO! Have had worse things happen....Data integrity can fail!
11539 --Could use count but that has some optimization and indexing problems....
11540 SELECT @TempPersonID = PersonID, @TempDemographicsID = DemographicsID
11541 FROM person.Demographics
11542 WHERE PersonID = @PersonID AND DemographicsID = @DemographicsID
11543
11544
11545 IF ((@TempDemographicsID=0) OR (@TempDemographicsID IS NULL)) OR ((@TempPersonID =0) OR (@TempPersonID IS NULL))
11546 BEGIN
11547 SELECT @ErrorStatus = ' -2008 DemographicsID/PersonID combo does not exist';
11548 SET @Success =0;
11549 RAISERROR(@ErrorStatus,16,1);
11550 END
11551
11552 IF @@Error <> 0
11553 BEGIN
11554 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -2000';
11555 SET @Success = 0;
11556 RAISERROR(@ErrorStatus, 16, 1);
11557 END
11558
11559 UPDATE Person.Demographics
11560 SET EducationCategoryID = @EducationCategoryID,
11561 NumberInHousehold = @NumberInHousehold,
11562 Gender = @Gender,
11563 Race = @Race,
11564 CountryOfOrigin = @CountryOfOrigin,
11565 HousingStatus = @HousingStatus,
11566 Ethnicity = @Ethnicity,
11567 Disability = @Disability,
11568 CSFP = @CSFP,
11569 Veteran = @Veteran,
11570 HealthInsurance = @HealthInsurance,
11571 FamilyStatusType = @FamilyStatusType,
11572 InsuranceType = @InsuranceType,
11573 FoodStamps = @FoodStamps,
11574 HomeboundDelivery = @HomeboundDelivery,
11575 ModifiedDate = SYSDATETIME(),
11576 ModifiedBy = @ModifiedBy
11577 WHERE DemographicsID = @DemographicsID AND PersonID = @PersonID
11578
11579 set @success =1;
11580 set @ErrorStatus =0;
11581 COMMIT TRANSACTION;
11582
11583 END TRY
11584
11585 BEGIN CATCH
11586 ROLLBACK TRANSACTION;
11587 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
11588 --We only care if the error was not raised by SSE
11589 IF @@ERROR <> 50000
11590 BEGIN
11591 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
11592 END
11593 SET @Success =0;
11594 SELECT @ErrorStatus= @ErrorStatus +'-2001 Update Fail Demographics';
11595 RAISERROR(@ErrorStatus, 15, 1);
11596
11597
11598 END CATCH
11599
11600 END
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618GO
11619/****** Object: StoredProcedure [dbo].[pUpdateEthnicity] Script Date: 10/16/2020 7:31:03 PM ******/
11620SET ANSI_NULLS ON
11621GO
11622SET QUOTED_IDENTIFIER ON
11623GO
11624
11625
11626
11627
11628
11629
11630/*************************************************************************************************
11631*Author: Gary Savard
11632*Date: 9 Oct 10
11633*Table Name: LUEthnicity
11634Description: Update data to LUEthnicity.
11635**************************************************************************************************/
11636CREATE PROCEDURE [dbo].[pUpdateEthnicity](
11637 @EthnicityID int,
11638 @EthnicityAbbreviation NVarchar(10),
11639 @EthnicityDescription NVarchar(50),
11640 @ModifiedBy Name,
11641 @Success bit Output,
11642 @ErrorStatus NVarchar(50) Output
11643 )
11644AS
11645SET NOCOUNT ON;
11646
11647 DECLARE
11648 @TempEthnicityID int
11649
11650 SET @TempEthnicityID =0;
11651 SET @Success = 0;
11652 SET @ErrorStatus ='';
11653
11654/****************************************************************************/
11655
11656
11657
11658
11659 BEGIN
11660 BEGIN TRY
11661 BEGIN TRANSACTION;
11662 IF (@EthnicityID = 0) OR (@EthnicityID IS NULL)
11663 BEGIN
11664 SET @ErrorStatus = ' -60065 EthnicityID Cant be 0/NULL';
11665 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
11666 END
11667
11668 SELECT @TempEthnicityID = EthnicityID
11669 FROM person.LUEthnicity
11670 WHERE EthnicityID =@EthnicityID
11671
11672 If @TempEthnicityID =0 --Double check to see if ID exists in db.
11673 BEGIN
11674 SET @ErrorStatus = ' -60082 Ethnicity already exists'; --Failed in lookup table
11675 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
11676
11677 END
11678
11679/****************************************************************************/
11680
11681 IF @@Error <> 0
11682 BEGIN
11683 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60080';
11684 SET @Success = 0;
11685 RAISERROR(@ErrorStatus, 16,1);
11686 END
11687
11688 UPDATE Person.LUEthnicity
11689 SET EthnicityAbbreviation = @EthnicityAbbreviation,
11690 EthnicityDescription = @EthnicityDescription,
11691 ModifiedDate = SYSDATETIME(),
11692 ModifiedBy = @ModifiedBy
11693 WHERE
11694 EthnicityID= @EthnicityID
11695
11696 set @success =1;
11697 set @ErrorStatus =0;
11698 COMMIT TRANSACTION;
11699
11700 END TRY
11701
11702 BEGIN CATCH
11703 ROLLBACK TRANSACTION;
11704 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
11705 --We only care if the error was not raised by SSE
11706 IF @@ERROR <> 50000
11707 BEGIN
11708 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
11709 END
11710 SET @Success =0;
11711 SELECT @ErrorStatus= @ErrorStatus +'-60081 Update Failed Ethnicity';
11712 RAISERROR(@ErrorStatus, 16, 1);
11713
11714
11715 END CATCH
11716
11717 END
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730GO
11731/****** Object: StoredProcedure [dbo].[pUpdateFamilyRelationship] Script Date: 10/16/2020 7:31:03 PM ******/
11732SET ANSI_NULLS ON
11733GO
11734SET QUOTED_IDENTIFIER ON
11735GO
11736
11737
11738
11739
11740
11741
11742
11743/*************************************************************************************************
11744*Author: Gary Savard
11745*Date: 9 Oct 10
11746*Table Name: FamilyRelationships
11747Description: Updates data to FamilyRelationships. Do not confuse with the sp that inserts to the
11748family relationship LU table! This stored procedure is not called directly and its superior sps do the validation, so it is left out
11749**************************************************************************************************/
11750
11751CREATE PROCEDURE [dbo].[pUpdateFamilyRelationship](
11752 @FamilyRelationshipID int,
11753 @PersonID int,
11754 @ClientPersonID int ,
11755 @RelationshipID int,
11756 @RelationshipDescription nVarchar(50)='',
11757 @ModifiedBy Name,
11758 @Success bit Output,
11759 @ErrorStatus NVarchar(50) Output
11760 )
11761AS
11762SET NOCOUNT ON;
11763BEGIN
11764 DECLARE
11765 @TempFamilyRelationshipID int
11766
11767 SET @TempFamilyRelationshipID =0;
11768 SET @Success = 0;
11769 SET @ErrorStatus ='';
11770
11771
11772/****************************************************************************/
11773--This stored procedure is not called directly and its superior sps do the validation, so it is left out
11774
11775 BEGIN TRY
11776 BEGIN TRANSACTION;
11777
11778 IF @FamilyRelationshipID = 0 OR @FamilyRelationshipID IS NULL
11779 BEGIN
11780 SELECT @ErrorStatus = '-17501 FamilyRelationshipID cant be 0/NULL';
11781 SET @Success = 0;
11782 RAISERROR(@ErrorStatus, 16,1);
11783 END
11784
11785 IF @PersonID =0 OR @PersonID IS NULL
11786 BEGIN
11787 SELECT @ErrorStatus = '-17503 PersonID cant be 0/NULL';
11788 SET @Success = 0;
11789 RAISERROR(@ErrorStatus, 16,1);
11790 END
11791
11792 IF @ClientPersonID =0 OR @ClientPersonID IS NULL
11793 BEGIN
11794 SELECT @ErrorStatus = '-17500 PersonID cant be 0/NULL';
11795 SET @Success = 0;
11796 RAISERROR(@ErrorStatus, 16,1);
11797 END
11798
11799 IF @@Error <> 0
11800 BEGIN
11801 SELECT @ErrorStatus = Convert(nVarchar(50),@@ERROR) + '-17540 Update Failed';
11802 SET @Success = 0;
11803 RAISERROR(@ErrorStatus, 16,1);
11804 END
11805
11806
11807
11808 BEGIN
11809
11810 UPDATE Person.FamilyRelationships
11811 SET RelationshipID = @RelationshipID,
11812 RelationDescription =@RelationshipDescription,
11813 ModifiedDate = SYSDATETIME(),
11814 ModifiedBy = @ModifiedBy
11815 WHERE FamilyRelationshipID = @FamilyRelationshipID;
11816
11817 IF @@Error <> 0
11818 BEGIN
11819 SELECT @ErrorStatus = Convert(nVarchar(50),@@ERROR) + '-17540 Update Failed';
11820 SET @Success = 0;
11821 RAISERROR(@ErrorStatus, 16,1);
11822 END
11823
11824
11825 SET @Success =1;
11826 SET @ErrorStatus =0;
11827 COMMIT TRANSACTION;
11828 END
11829
11830 END TRY
11831
11832 BEGIN CATCH
11833 ROLLBACK TRANSACTION;
11834 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
11835 --We only care if the error was not raised by SSE
11836 IF @@ERROR <> 50000
11837 BEGIN
11838 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
11839 END
11840 SET @Success =0;
11841 SELECT @ErrorStatus= @ErrorStatus +'-18001 Update Failed on FamilyRelationships';
11842 RAISERROR(@ErrorStatus, 16, 1);
11843
11844
11845 END CATCH
11846
11847 END
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861GO
11862/****** Object: StoredProcedure [dbo].[pUpdateFamilyStatusType] Script Date: 10/16/2020 7:31:03 PM ******/
11863SET ANSI_NULLS ON
11864GO
11865SET QUOTED_IDENTIFIER ON
11866GO
11867
11868
11869
11870
11871
11872
11873/*************************************************************************************************
11874*Author: Gary Savard
11875*Date: 15 March 11
11876*Table Name: LUFamilySTatusType
11877Description: Update data to LUFamilySTatusType.
11878**************************************************************************************************/
11879
11880CREATE PROCEDURE [dbo].[pUpdateFamilyStatusType](
11881 @FamilyStatusTypeID int,
11882 @FamilySTatusType Nvarchar(50) ,
11883 @ModifiedBy Name,
11884 @Success bit Output,
11885 @ErrorStatus NVarchar(50) Output
11886 )
11887AS
11888SET NOCOUNT ON;
11889
11890 DECLARE
11891 @TempNewFamilyStatusTypeID int
11892
11893 SET @TempNewFamilyStatusTypeID =0;
11894 SET @Success = 0;
11895 SET @ErrorStatus ='';
11896
11897
11898
11899 BEGIN
11900 BEGIN TRY
11901 BEGIN TRANSACTION;
11902
11903 IF (@FamilyStatusTypeID = 0) OR (@FamilyStatusTypeID IS NULL)
11904 BEGIN
11905 SET @ErrorStatus = ' -60022 FamilyStatusType already exists in LUFamilyStatusType';
11906 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
11907 END
11908
11909 SELECT @TempNewFamilyStatusTypeID = FamilyStatusTypeID
11910 FROM person.LUFamilyStatusType
11911 WHERE FamilyStatusTypeID = FamilyStatusTypeID
11912
11913 IF @TempNewFamilyStatusTypeID =0
11914 BEGIN
11915 SET @ErrorStatus = ' -60028 FamilyStatusType doesnt exist in LUFamilyStatusType';
11916 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
11917 END
11918
11919
11920
11921 IF @@Error <> 0
11922 BEGIN
11923 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60020';
11924 SET @Success = 0;
11925 RAISERROR(@ErrorStatus, 16,1);
11926 END
11927
11928 UPDATE Person.LUFamilyStatusType
11929 SET FamilyStatusType = @FamilyStatusType,
11930 ModifiedDate = SYSDATETIME(),
11931 ModifiedBy = @ModifiedBy
11932 WHERE FamilyStatusTypeID = @FamilyStatusTypeID
11933
11934
11935 set @success =1;
11936 set @ErrorStatus =0;
11937 COMMIT TRANSACTION;
11938
11939 END TRY
11940
11941 BEGIN CATCH
11942 ROLLBACK TRANSACTION;
11943 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
11944 --We only care if the error was not raised by SSE
11945 IF @@ERROR <> 50000
11946 BEGIN
11947 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
11948 END
11949 SET @Success =0;
11950 SELECT @ErrorStatus= @ErrorStatus + '-60021 Update Failed on LUFamilyStatusType';
11951 RAISERROR(@ErrorStatus, 16, 1);
11952
11953
11954 END CATCH
11955
11956 END
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969GO
11970/****** Object: StoredProcedure [dbo].[pUpdateFoodTypeGiven] Script Date: 10/16/2020 7:31:03 PM ******/
11971SET ANSI_NULLS ON
11972GO
11973SET QUOTED_IDENTIFIER ON
11974GO
11975
11976/*************************************************************************************************
11977*Author: Gary Savard
11978*Date: 9 Oct 10
11979*Table Name: FoodTypeGiven
11980Description: Update data to FoodTypeGiven. This SP requires PersonID, to be valid on input
11981in order to capture the appropriate information. ReceivedDate should also be a valid date/time since we need to be able
11982to return up to 90 days history for each client in reports. This date is not tested since we have to assume
11983that the record may have been input on paper for some reason, so we cannot use system date to test validity.
11984**************************************************************************************************/
11985
11986CREATE PROCEDURE [dbo].[pUpdateFoodTypeGiven](
11987 @FoodTypeGivenID int,
11988 @PersonID int ,
11989 @ReceivedDate DateTime,
11990 @FoodGiven FoodShelf.GroceryOrBreadProduce,
11991 @ModifiedBy Name,
11992 @NewFoodTypeGivenID int Output,
11993 @Success bit Output,
11994 @ErrorStatus NVarchar(50) Output
11995 )
11996AS
11997SET NOCOUNT ON;
11998BEGIN
11999 DECLARE
12000 @TempFoodTypeGivenID int
12001
12002
12003 SET @TempFoodTypeGivenID =0;
12004
12005 SET @Success = 0;
12006 SET @ErrorStatus ='';
12007/****************************************************************************/
12008
12009 BEGIN
12010 BEGIN TRY
12011 BEGIN TRANSACTION;
12012 --Make sure that we do not have bad data
12013 IF ((@FoodTypeGivenID=0) OR (@FoodTypeGivenID IS NULL)) OR((@PersonID = 0) OR (@PersonID IS NULL))
12014 BEGIN
12015 SELECT @ErrorStatus = ' -600011 @FoodTypeGivenID/PersonID/ProgramID/ServiceId not valid';
12016 SET @Success = 0;
12017 RAISERROR(@ErrorStatus,16,1);
12018 END
12019
12020 --We now have a valid range for each ID, but need to be sure that they exist in the database before trying the Update.
12021 SELECT @TempFoodTypeGivenID = FoodTypeGivenID
12022 FROM Foodshelf.FoodTypeGiven
12023 WHERE FoodTypeGivenID = @FoodTypeGivenID AND PersonID = @PersonID
12024 --The above could use just @FoodTypeGiven in the WHERE clause, but this is just more validation.
12025 IF @TempFoodTypeGivenID =0
12026 BEGIN
12027 SET @ErrorStatus = ' -600008 Record does not exist';
12028 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
12029
12030 END
12031
12032/****************************************************************************/
12033
12034 IF @@Error <> 0
12035 BEGIN
12036 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-600010';
12037 SET @Success = 0;
12038 RAISERROR(@ErrorStatus, 16,1);
12039 END
12040
12041 UPDATE Foodshelf.FoodTypeGiven
12042 SET PersonID = @PersonID,
12043 ReceivedDate = @ReceivedDate,
12044 FoodGiven = @FoodGiven,
12045 ModifiedDate = SYSDATETIME(),
12046 ModifiedBy = @ModifiedBy
12047 WHERE FoodTypeGivenID = @FoodTypeGivenID
12048
12049
12050 SET @success =1;
12051 SET @ErrorStatus =0;
12052 COMMIT TRANSACTION;
12053
12054 END TRY
12055
12056 BEGIN CATCH
12057 ROLLBACK TRANSACTION;
12058 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
12059 --We only care if the error was not raised by SSE
12060 IF @@ERROR <> 50000
12061 BEGIN
12062 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
12063 END
12064 SET @Success =0;
12065 SELECT @ErrorStatus= @ErrorStatus + '-600011 Insert Failed on FoodTypeGiven';
12066 RAISERROR(@ErrorStatus, 16, 1);
12067
12068 END CATCH
12069 END
12070END
12071
12072
12073
12074GO
12075/****** Object: StoredProcedure [dbo].[pUpdateHouseholdNotes] Script Date: 10/16/2020 7:31:03 PM ******/
12076SET ANSI_NULLS ON
12077GO
12078SET QUOTED_IDENTIFIER ON
12079GO
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093/*************************************************************************************************
12094*Author: Gary Savard
12095*Date: 2 NOV 10
12096*Table Name: FoodShelf.Household Notes
12097Description: Updates data to FoodShelf.HouseHoldNotes table.This table is for the notes associated with the
12098food shelf intake screens. There are 3 ID fields, the HouseholdNotesID is the identity. ClientPersonID
12099is the PersonID of the individual on which the note was written. The HouseholdMemberPersonID is optional, and
12100If this person is not the client, but a household member, this value will be the Client's personID. We
12101may not need this field, but it is added for potential future functionality
12102Revisions:
12103**************************************************************************************************/
12104
12105CREATE PROCEDURE [dbo].[pUpdateHouseholdNotes](
12106 @HouseholdNotesID int,
12107 @ClientPersonID int,
12108 @HouseholdMemberPersonID int,
12109 @Notes Nvarchar(MAX),
12110 @ModifiedBy Name,
12111 @Success bit Output,
12112 @ErrorStatus Nvarchar(50) Output
12113 )
12114AS
12115SET NOCOUNT ON;
12116BEGIN
12117 DECLARE
12118 @TempHouseholdNotesID int,
12119 @TempClientPersonID int,
12120 @TempHouseholdMemberPersonID int
12121
12122 SET @TempHouseholdNotesID =0;
12123 SET @TempClientPersonID = 0;
12124 SET @Success = 0;
12125 SET @ErrorStatus ='';
12126
12127
12128
12129
12130 BEGIN TRY
12131 BEGIN TRANSACTION;
12132 /****************************************************************************/
12133 --Validate IDs coming in. Only the HouseholdNotesID and ClientPersonID are mandatory,
12134
12135 SELECT @TempHouseholdNotesID = @HouseholdNotesID
12136 FROM Foodshelf.HouseholdNotes
12137 WHERE HouseholdNotesID = @HouseholdNotesID
12138
12139 IF @TempHouseholdNotesID = 0 OR @TempHouseholdNotesID IS NULL
12140 BEGIN
12141 SET @ErrorStatus ='-14008 Record does not exist';
12142 SET @Success =0;
12143 RAISERROR(@ErrorStatus,16,1);
12144 END
12145
12146 SELECT @TempClientPersonID = PersonID
12147 FROM person.Person
12148 WHERE PersonID = @ClientPersonID
12149
12150 If @TempClientPersonID = 0 or @TempClientPersonID IS NULL
12151 BEGIN
12152 SET @ErrorStatus = ' -14008 ClientPersonID does not exist in Person'; --Failed in person table
12153 SET @Success =0;
12154 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
12155
12156 END
12157
12158 --Since this is an optional field, we only check it if it has a value other than 0 or NULL
12159 IF @HouseholdMemberPersonID <> 0 AND @HouseholdMemberPersonID IS NOT NULL
12160 BEGIN
12161 SELECT @TempHouseholdMemberPersonID = @HouseholdMemberPersonID
12162 FROM Person.Person
12163 WHERE PersonID = @HouseholdMemberPersonID
12164
12165 IF @TempHouseholdMemberPersonID = 0 OR @TempHouseholdMemberPersonID IS NULL
12166 BEGIN
12167 SET @ErrorStatus =' -14016 HouseholdMemberPersonID does not exist, though not NULL/0';
12168 SET @Success =0;
12169 RAISERROR(@ErrorStatus,16,1);
12170 END
12171 END
12172 /****************************************************************************/
12173
12174
12175 IF @@Error <> 0
12176 BEGIN
12177 SELECT @ErrorStatus = Convert(nVarchar(50),@@ERROR) + '-14000';
12178 SET @Success = 0;
12179 RAISERROR (@ErrorStatus,16,1);
12180 END
12181
12182 UPDATE Foodshelf.HouseholdNotes
12183 SET ClientPersonID = @ClientPersonID,
12184 HouseholdMemberPersonID = @HouseholdMemberPersonID,
12185 Notes = @Notes,
12186 ModifiedBy = @ModifiedBy,
12187 ModifiedDate = SYSDATETIME()
12188 WHERE HouseholdNotesID = @HouseholdNotesID --Don't bother with other Ids here since this is the identity for the row.
12189
12190
12191 SET @success =1;
12192 SET @ErrorStatus =0;
12193 COMMIT TRANSACTION;
12194
12195 END TRY
12196
12197 BEGIN CATCH
12198 ROLLBACK TRANSACTION;
12199 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
12200 --We only care if the error was not raised by SSE
12201 IF @@ERROR <> 50000
12202 BEGIN
12203 SET @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
12204 END
12205
12206
12207 SELECT @ErrorStatus =@ErrorStatus + ' -14000' +' Update Failed HouseholdNotes';
12208 SET @Success =0;
12209
12210 RAISERROR(@ErrorStatus, 16, 1);
12211
12212
12213 END CATCH
12214
12215
12216END
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231GO
12232/****** Object: StoredProcedure [dbo].[pUpdateHousingStatus] Script Date: 10/16/2020 7:31:03 PM ******/
12233SET ANSI_NULLS ON
12234GO
12235SET QUOTED_IDENTIFIER ON
12236GO
12237
12238
12239
12240
12241
12242/*************************************************************************************************
12243*Author: Gary Savard
12244*Date: 9 Oct 10
12245*Table Name: LUHousingStatus
12246Description: Updates data to LUHousingStatus.
12247**************************************************************************************************/
12248
12249CREATE PROCEDURE [dbo].[pUpdateHousingStatus](
12250 @HousingStatusID int,
12251 @HousingStatus NVarchar(20),
12252 @ModifiedBy Name,
12253 @Success bit Output,
12254 @ErrorStatus NVarchar(50) Output
12255 )
12256AS
12257SET NOCOUNT ON;
12258BEGIN
12259 DECLARE
12260 @TempHousingStatusID int
12261
12262 SET @TempHousingStatusID =0;
12263 SET @Success = 0;
12264 SET @ErrorStatus ='';
12265
12266
12267
12268 BEGIN TRY
12269 BEGIN TRANSACTION;
12270 /****************************************************************************/
12271
12272 SELECT @TempHousingStatusID = HousingStatusID
12273 FROM person.LUHousingStatus
12274 WHERE HousingStatusID = @HousingStatusID
12275
12276 If (@TempHousingStatusID =0) OR (@TempHousingStatusID IS NULL)
12277 BEGIN
12278 SET @ErrorStatus = ' -60098 Does not exist in LUHousingStatus'; --Failed in lookup table
12279 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
12280
12281 END
12282
12283 /****************************************************************************/
12284
12285 IF @@Error <> 0
12286 BEGIN
12287 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60020';
12288 SET @Success = 0;
12289 RAISERROR(@ErrorStatus, 16,1);
12290 END
12291
12292 BEGIN
12293
12294 UPDATE Person.LUHousingStatus
12295 SET HousingStatus = @HousingStatus,
12296 ModifiedDate = SYSDATETIME(),
12297 ModifiedBy = @ModifiedBy
12298 WHERE
12299 HousingStatusID = @HousingStatusID
12300
12301
12302 set @success =1;
12303 set @ErrorStatus =0;
12304 COMMIT TRANSACTION;
12305 END
12306
12307
12308
12309 END TRY
12310
12311 BEGIN CATCH
12312 ROLLBACK TRANSACTION;
12313 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
12314 --We only care if the error was not raised by SSE
12315 IF @@ERROR <> 50000
12316 BEGIN
12317 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
12318 END
12319 SET @Success =0;
12320 SELECT @ErrorStatus= @ErrorStatus + +'-60021 Insert Failed Housing Status';
12321 RAISERROR(@ErrorStatus, 16, 1);
12322
12323
12324 END CATCH
12325
12326END
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337GO
12338/****** Object: StoredProcedure [dbo].[pUpdateIncomeSource] Script Date: 10/16/2020 7:31:03 PM ******/
12339SET ANSI_NULLS ON
12340GO
12341SET QUOTED_IDENTIFIER ON
12342GO
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354/*************************************************************************************************
12355
12356*Author: Gary Savard
12357*Date: 8 Oct 10
12358*Table Name: Address
12359Description: Update data to LUIncomeSource table.
12360Revisions:
12361**************************************************************************************************/
12362
12363CREATE PROCEDURE [dbo].[pUpdateIncomeSource](
12364 @IncomeSourceID int,
12365 @IncomeSourceAbbreviation NVarchar(10),
12366 @IncomeSourceDescription Nvarchar(50),
12367 @ModifiedBy Name,
12368 @Success bit Output,
12369 @ErrorStatus Nvarchar(50) Output
12370 )
12371AS
12372SET NOCOUNT ON;
12373BEGIN
12374 DECLARE
12375 @TempIncomeSourceID int
12376
12377 SET @TempIncomeSourceID =0;
12378 SET @Success = 0;
12379 SET @ErrorStatus ='';
12380
12381
12382
12383
12384 BEGIN TRY
12385 BEGIN TRANSACTION;
12386 /****************************************************************************/
12387
12388 --the address, so we need to be sure that the data matches an address type before continuing.
12389 SELECT @TempIncomeSourceID = IncomeSourceID
12390 FROM person.LUIncomeSource
12391 WHERE IncomeSourceID = @IncomeSourceID
12392
12393 IF (@IncomeSourceID = 0) OR (@IncomeSourceID IS NULL)
12394 BEGIN
12395 SET @ErrorStatus = ' -6095 Income Source exists in LUIncomeSource'; --Failed in lookup table
12396 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
12397 END
12398
12399 IF @TempIncomeSourceID = 0
12400 BEGIN
12401 SET @ErrorStatus = ' -6098 Income Source doesnt exist LUIncomeSource'; --Failed in lookup table
12402 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
12403
12404 END
12405/****************************************************************************/
12406
12407 IF @@Error <> 0
12408 BEGIN
12409 SELECT @ErrorStatus = @@ERROR + '-6090';
12410 SET @Success = 0;
12411 RAISERROR (@ErrorStatus,16,1);
12412 END
12413
12414
12415
12416 UPDATE Person.LUIncomeSource
12417 SET IncomeSourceAbbreviation = @IncomeSourceAbbreviation,
12418 IncomeSourceDescription = @IncomeSourceDescription,
12419 ModifiedDate = SYSDATETIME(),
12420 ModifiedBy = @ModifiedBy
12421
12422
12423 set @success =1;
12424 set @ErrorStatus =0;
12425 COMMIT TRANSACTION;
12426
12427 END TRY
12428
12429 BEGIN CATCH
12430 ROLLBACK TRANSACTION;
12431 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
12432 --We only care if the error was not raised by SSE
12433 IF @@ERROR <> 50000
12434 BEGIN
12435 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
12436 END
12437 SELECT @ErrorStatus =@ErrorStatus + ' -6091' +' Update Failed LUIncomeSource';
12438 SET @Success =0;
12439
12440 RAISERROR(@ErrorStatus, 16, 1);
12441
12442
12443 END CATCH
12444
12445
12446END
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459GO
12460/****** Object: StoredProcedure [dbo].[pUpdateInsuranceType] Script Date: 10/16/2020 7:31:03 PM ******/
12461SET ANSI_NULLS ON
12462GO
12463SET QUOTED_IDENTIFIER ON
12464GO
12465
12466
12467
12468
12469
12470
12471/*************************************************************************************************
12472*Author: Gary Savard
12473*Date: 15 March 11
12474*Table Name: LUInsuranceType
12475Description: Update data to LUInsuranceType.
12476**************************************************************************************************/
12477
12478CREATE PROCEDURE [dbo].[pUpdateInsuranceType](
12479 @InsuranceTypeID int,
12480 @InsuranceType Nvarchar(50) ,
12481 @ModifiedBy Name,
12482 @Success bit Output,
12483 @ErrorStatus NVarchar(50) Output
12484 )
12485AS
12486SET NOCOUNT ON;
12487
12488 DECLARE
12489 @TempNewInsuranceTypeID int
12490
12491 SET @TempNewInsuranceTypeID =0;
12492 SET @Success = 0;
12493 SET @ErrorStatus ='';
12494
12495
12496
12497 BEGIN
12498 BEGIN TRY
12499 BEGIN TRANSACTION;
12500
12501 IF (@InsuranceTypeID = 0) OR (@InsuranceTypeID IS NULL)
12502 BEGIN
12503 SET @ErrorStatus = ' -60022 Insurance Type already exists in LUInsuranceType';
12504 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
12505 END
12506
12507 SELECT @TempNewInsuranceTypeID = InsuranceTypeID
12508 FROM person.LUInsuranceType
12509 WHERE InsuranceTypeID = @InsuranceTypeID
12510
12511 IF @TempNewInsuranceTypeID =0
12512 BEGIN
12513 SET @ErrorStatus = ' -60028 Insurance Type doesnt exist in LUInsuranceType';
12514 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
12515 END
12516
12517
12518
12519 IF @@Error <> 0
12520 BEGIN
12521 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-60020';
12522 SET @Success = 0;
12523 RAISERROR(@ErrorStatus, 16,1);
12524 END
12525
12526 UPDATE Person.LUInsuranceType
12527 SET InsuranceType = @InsuranceType,
12528 ModifiedDate = SYSDATETIME(),
12529 ModifiedBy = @ModifiedBy
12530 WHERE InsuranceTypeID = @InsuranceTypeID
12531
12532
12533 set @success =1;
12534 set @ErrorStatus =0;
12535 COMMIT TRANSACTION;
12536
12537 END TRY
12538
12539 BEGIN CATCH
12540 ROLLBACK TRANSACTION;
12541 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
12542 --We only care if the error was not raised by SSE
12543 IF @@ERROR <> 50000
12544 BEGIN
12545 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
12546 END
12547 SET @Success =0;
12548 SELECT @ErrorStatus= @ErrorStatus + '-60021 Update Failed on LUInsuranceType';
12549 RAISERROR(@ErrorStatus, 16, 1);
12550
12551
12552 END CATCH
12553
12554 END
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567GO
12568/****** Object: StoredProcedure [dbo].[pUpdateLanguage] Script Date: 10/16/2020 7:31:03 PM ******/
12569SET ANSI_NULLS ON
12570GO
12571SET QUOTED_IDENTIFIER ON
12572GO
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583/*************************************************************************************************
12584*Author: Gary Savard
12585*Date: 15 Oct 10
12586*Table Name: LULanguage
12587Description: Updates data to LULangage. This table Contains the most common languages and dialects in the world.Dialects
12588are comma demlmited. Example: Chinese, Mandarin.
12589Revisions:
12590**************************************************************************************************/
12591
12592CREATE PROCEDURE [dbo].[pUpdateLanguage](
12593 @LanguageID int,
12594 @LanguageName Nvarchar(50),
12595 @ModifiedBy Name,
12596 @Success bit Output,
12597 @ErrorStatus Nvarchar(50) Output
12598 )
12599AS
12600SET NOCOUNT ON;
12601BEGIN
12602 DECLARE
12603 @TempLanguageID int
12604
12605 SET @TempLanguageID =0;
12606 SET @Success = 0;
12607 SET @ErrorStatus ='';
12608
12609
12610 BEGIN TRY
12611 BEGIN TRANSACTION;
12612 /****************************************************************************/
12613 --Double check to see that we do have a correct languageID before trying to update
12614 SELECT @TempLanguageID = LanguageID
12615 FROM person.LULanguage
12616 WHERE LanguageID = @LanguageID
12617
12618 /****************************************************************************/
12619 IF @@Error <> 0
12620 BEGIN
12621 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6060';
12622 SET @Success = 0;
12623 RAISERROR(@ErrorStatus,16,1);
12624 END
12625 IF (@TempLanguageID = 0) or (@TempLanguageID IS NULL)
12626 BEGIN
12627 SELECT @ErrorStatus = '-6068 Language does not exist in db';
12628 SET @Success =0;
12629 RAISERROR(@ErrorStatus, 16,1);
12630 END
12631
12632 IF @TempLanguageID <> 0 --Don't really need this, but... it exists in the database then
12633 BEGIN
12634
12635 UPDATE Person.LULanguage
12636 SET LanguageName = @LanguageName,
12637 ModifiedDate = SYSDATETIME(),
12638 ModifiedBy = @ModifiedBy
12639 WHERE
12640 LanguageID = @LanguageID
12641
12642
12643 set @success =1;
12644 set @ErrorStatus =0;
12645 COMMIT TRANSACTION;
12646 END
12647
12648 END TRY
12649
12650 BEGIN CATCH
12651 ROLLBACK TRANSACTION;
12652 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
12653 --We only care if the error was not raised by SSE
12654 IF @@ERROR <> 50000
12655 BEGIN
12656 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
12657 END
12658 SET @Success =0;
12659 SELECT @ErrorStatus= @ErrorStatus + 'LULanguage-6061';
12660 RAISERROR(@ErrorStatus, 16, 1);
12661
12662
12663 END CATCH
12664
12665 END
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678GO
12679/****** Object: StoredProcedure [dbo].[pUpdateLUFamilyRelationships] Script Date: 10/16/2020 7:31:03 PM ******/
12680SET ANSI_NULLS ON
12681GO
12682SET QUOTED_IDENTIFIER ON
12683GO
12684
12685
12686
12687
12688
12689/*************************************************************************************************
12690*Author: Gary Savard
12691*Date: 9 Oct 10
12692*Table Name: LUFamilyRelationships
12693Description: Updates data to LUFamilyRelationships.
12694**************************************************************************************************/
12695
12696CREATE PROCEDURE [dbo].[pUpdateLUFamilyRelationships](
12697 @FamilyRelationshipID int,
12698 @RelationshipCode Nvarchar(30),
12699 @RelationshipDescription Nvarchar(50) ='',
12700 @ModifiedBy Name,
12701 @Success bit Output,
12702 @ErrorStatus NVarchar(50) Output
12703 )
12704AS
12705SET NOCOUNT ON;
12706BEGIN
12707 DECLARE
12708 @TempFamilyRelationshipID int
12709
12710 SET @TempFamilyRelationshipID =0;
12711 SET @Success = 0;
12712 SET @ErrorStatus ='';
12713
12714
12715/****************************************************************************/
12716
12717
12718 BEGIN TRY
12719 BEGIN TRANSACTION;
12720 IF (@FamilyRelationshipID =0) OR (@FamilyRelationshipID IS NULL)
12721 BEGIN
12722 SELECT @ErrorStatus = ' -60045 FamilyRelationshipID cant be 0/NULL';
12723 SET @Success =0;
12724 RAISERROR(@ErrorStatus, 16,1);
12725 END
12726
12727
12728 SELECT @TempFamilyRelationshipID = FamilyRelationshipID
12729 FROM person.LUFamilyRelationship
12730 WHERE FamilyRelationshipID = @FamilyRelationshipID
12731
12732 If @TempFamilyRelationshipID =0
12733 BEGIN
12734 SET @ErrorStatus = ' -60048 RelationshipID doesnt exist LUFamilyRelationship';
12735 RAISERROR(@ErrorStatus,16,1);--Could use WITH LOG for event log
12736
12737 END
12738
12739 IF @@Error <> 0
12740 BEGIN
12741 SELECT @ErrorStatus = Convert(nVarchar(50),@@ERROR) + '-60040';
12742 SET @Success = 0;
12743 RAISERROR(@ErrorStatus, 16,1);
12744 END
12745
12746
12747
12748 BEGIN
12749
12750 UPDATE Person.LUFamilyRelationship
12751 SET RelationshipCode = @RelationshipCode,
12752 RelationshipDescription = @RelationshipDescription,
12753 ModifiedDate = SYSDATETIME(),
12754 ModifiedBy = @ModifiedBy
12755 WHERE FamilyRelationshipID = @FamilyRelationshipID
12756
12757
12758
12759 set @success =1;
12760 set @ErrorStatus =0;
12761 COMMIT TRANSACTION;
12762 END
12763
12764 END TRY
12765
12766 BEGIN CATCH
12767 ROLLBACK TRANSACTION;
12768 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
12769 --We only care if the error was not raised by SSE
12770 IF @@ERROR <> 50000
12771 BEGIN
12772 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
12773 END
12774 SET @Success =0;
12775 SELECT @ErrorStatus= @ErrorStatus +'-60041 Update Failed LUFamilyRelationship';
12776 RAISERROR(@ErrorStatus, 16, 1);
12777
12778
12779 END CATCH
12780
12781 END
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793GO
12794/****** Object: StoredProcedure [dbo].[pUpdatePerson] Script Date: 10/16/2020 7:31:03 PM ******/
12795SET ANSI_NULLS ON
12796GO
12797SET QUOTED_IDENTIFIER ON
12798GO
12799
12800
12801/*************************************************************************************************
12802
12803*Author: Gary Savard
12804*Date: 8 Oct 10
12805*Table Name: Person
12806Description: Update data to Person table
12807Revisions:
12808**************************************************************************************************/
12809CREATE PROCEDURE [dbo].[pUpdatePerson](
12810 @PersonID int,
12811 @Title NVarchar(8) =NULL,
12812 @FirstName Name,
12813 @MiddleName Name = Null,
12814 @LastName Name,
12815 @Suffix NVarchar(10) = Null,
12816 @DateOfBirth DateTime,
12817 @EmailAddress Nvarchar(50) = Null,
12818 @EmailContactPreference NoYes =0,
12819 @ModifiedBy Name,
12820 @Success bit Output,
12821 @ErrorStatus Nvarchar(50) Output
12822 )
12823AS
12824SET NOCOUNT ON;
12825BEGIN
12826 DECLARE
12827 @TempPersonID int
12828
12829
12830 SET @TempPersonID =0;
12831 SET @Success = 0;
12832 SET @ErrorStatus ='';
12833 SET @TempPersonID =0;
12834
12835
12836
12837BEGIN TRY
12838 BEGIN TRANSACTION;
12839
12840 IF ((@PersonID = 0) OR (@PersonID IS NULL))
12841 BEGIN
12842 SELECT @ErrorStatus = 'Person ID cant be 0 or NULL -1005';
12843 SET @Success = 0;
12844 RAISERROR (@ErrorStatus,16,1);
12845 END
12846 BEGIN
12847 SELECT @TempPersonID = PersonID from Person.Person
12848 WHERE
12849 PersonID = @PersonID
12850 IF @TempPersonID =0 OR @TempPersonID IS NULL
12851 BEGIN
12852 SET @Success =0;
12853 SELECT @ErrorStatus = '-1008 Person does not exist';
12854 RAISERROR(@ErrorStatus,16,1);
12855 END
12856 END
12857
12858 IF @@Error <> 0
12859 BEGIN
12860 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-1000';
12861 SET @Success = 0;
12862 END
12863
12864
12865 UPDATE Person.Person
12866 SET Title = @Title,
12867 FirstName = @FirstName,
12868 MiddleName = @MiddleName,
12869 LastName = @LastName,
12870 Suffix = @Suffix,
12871 DateOfBirth = @DateOfBirth,
12872 EmailAddress = @EmailAddress,
12873 EmailContactPreference = @EmailContactPreference,
12874 ModifiedDate = SYSDATETIME(),
12875 ModifiedBy = @ModifiedBy
12876 WHERE PersonID = @PersonID
12877
12878
12879
12880 SET @success =1;
12881 SET @ErrorStatus =0;
12882 COMMIT TRANSACTION;
12883
12884 END TRY
12885
12886 BEGIN CATCH
12887 ROLLBACK TRANSACTION;
12888 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
12889 --We only care if the error was not raised by SSE
12890 IF @@ERROR <> 50000
12891 BEGIN
12892 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
12893 END
12894 SET @Success =0;
12895 SET @ErrorStatus= @ErrorStatus + 'Update Person Failed -1001';
12896 RAISERROR(@ErrorStatus, 15, 1);
12897
12898
12899 END CATCH
12900
12901 END
12902
12903
12904
12905
12906
12907
12908
12909
12910GO
12911/****** Object: StoredProcedure [dbo].[pUpdatePersonType] Script Date: 10/16/2020 7:31:03 PM ******/
12912SET ANSI_NULLS ON
12913GO
12914SET QUOTED_IDENTIFIER ON
12915GO
12916
12917
12918
12919
12920
12921
12922/*************************************************************************************************
12923*Author: Gary Savard
12924*Date: 9 Oct 10
12925*Table Name: LUPersonType
12926Description: Updates data to LUPersonType.
12927Revisions:
12928**************************************************************************************************/
12929
12930CREATE PROCEDURE [dbo].[pUpdatePersonType](
12931 @PersonTypeID int,
12932 @PersonType NVarchar(20),
12933 @ModifiedBy Name,
12934 @Success bit Output,
12935 @ErrorStatus NVarchar(50) Output
12936 )
12937AS
12938SET NOCOUNT ON;
12939BEGIN
12940 DECLARE
12941 @TempPersonTypeID int
12942
12943 SET @TempPersonTypeID =0;
12944 SET @Success = 0;
12945 SET @ErrorStatus ='';
12946
12947
12948BEGIN TRY
12949 BEGIN TRANSACTION;
12950 /****************************************************************************/
12951 --Does it already exist? If not, then do not try to update!
12952 SELECT @TempPersonTypeID = PersonTypeID
12953 FROM person.LUPersonType
12954 WHERE PersonTypeID = @PersonType
12955
12956/****************************************************************************/
12957 IF (@TempPersonTypeID = 0) OR (@TempPersonTypeID IS NULL)
12958 BEGIN
12959 SELECT @ErrorStatus = @@ERROR + '-600008 PersonType does not exists';
12960 SET @Success = 0;
12961 RAISERROR(@ErrorStatus, 16,1);
12962 END
12963
12964 IF @@Error <> 0
12965 BEGIN
12966 SELECT @ErrorStatus = @@ERROR + '-600000';
12967 SET @Success = 0;
12968 RAISERROR(@ErrorStatus, 16,1);
12969 END
12970
12971
12972
12973 BEGIN
12974
12975 UPDATE Person.LUPersonType
12976 SET PersonType = @PersonType,
12977 ModifiedDate = SYSDATETIME(),
12978 ModifiedBy = @ModifiedBy
12979 WHERE PersonTypeID = @PersonTypeID
12980
12981
12982 set @success =1;
12983 set @ErrorStatus =0;
12984 COMMIT TRANSACTION;
12985 END
12986END TRY
12987
12988 BEGIN CATCH
12989 ROLLBACK TRANSACTION;
12990 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
12991 --We only care if the error was not raised by SSE
12992 IF @@ERROR <> 50000
12993 BEGIN
12994 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
12995 END
12996 SET @Success =0;
12997 SELECT @ErrorStatus= @ErrorStatus +'-600001 Update Failed Person Type';
12998 RAISERROR(@ErrorStatus, 16, 1);
12999
13000
13001 END CATCH
13002
13003 END
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015GO
13016/****** Object: StoredProcedure [dbo].[pUpdatePhone] Script Date: 10/16/2020 7:31:03 PM ******/
13017SET ANSI_NULLS ON
13018GO
13019SET QUOTED_IDENTIFIER ON
13020GO
13021
13022
13023/*************************************************************************************************
13024*Author: Gary Savard
13025*Date: 8 Oct 10
13026*Table Name: Phone
13027Description: Update data to phone table. The row is tied to the person.personid. This Stored proc/table does not directly
13028access the LUPhoneType table. The type is selected by the user from a dropdown and we just store the ID from the dropdown behind the scenes
13029 for simplicity
13030**************************************************************************************************/
13031
13032CREATE PROCEDURE [dbo].[pUpdatePhone](
13033 @PhoneID int,
13034 @PersonID int,
13035 @PhoneNumber Phone,
13036 @PhoneExtension NVarchar(8),
13037 @PhoneType int,
13038 @ModifiedBy Name,
13039 @Success bit Output,
13040 @ErrorStatus Nvarchar(50) Output
13041 )
13042AS
13043SET NOCOUNT ON;
13044
13045 DECLARE
13046 @TempPhoneID int,
13047 @TempPersonID int
13048
13049 SET @TempPhoneID =0;
13050 SET @TempPersonID =0;
13051 SET @Success = 0;
13052 SET @ErrorStatus ='';
13053
13054
13055 BEGIN TRY
13056 BEGIN TRANSACTION;
13057 IF ((@PersonID = 0) OR (@PersonID IS NULL) OR (@PhoneID = 0) OR (@PhoneID IS NULL)) -- This has to be valid or we bail out!
13058 BEGIN
13059 SET @Success =0;
13060 SET @ErrorStatus = '-8005: PersonID/PhoneID must be valid';
13061
13062 RAISERROR(@ErrorStatus,16,1);
13063 END
13064
13065 BEGIN
13066 SELECT @TempPersonID = PersonID, @TempPhoneID = @PhoneID
13067 FROM Person.Phone
13068 WHERE
13069 PersonID =@PersonID AND @PhoneID = @PhoneID
13070
13071 IF ((@TempPersonID = 0) OR (@TempPersonID IS NULL)) OR ((@TempPhoneID = 0) OR (@TempPhoneID IS NULL))
13072 BEGIN
13073 SET @ErrorStatus ='-8008 PersonID or PhoneID not valid';
13074 SET @Success =0;
13075 RAISERROR (@ErrorStatus, 16, 1);
13076 END
13077
13078 IF @@Error <> 0
13079 BEGIN
13080 SELECT @ErrorStatus = @@ERROR + '-8030';
13081 SET @Success = 0;
13082 RAISERROR(@ErrorStatus, 16, 1);
13083 END
13084 END
13085
13086 UPDATE Person.Phone
13087 SET PersonID = @PersonID,
13088 PhoneNumber = @PhoneNumber,
13089 PhoneExtension = @PhoneExtension,
13090 PhoneType = @PhoneType,
13091 ModifiedDate = SYSDATETIME(),
13092 ModifiedBy = @ModifiedBy
13093 WHERE PhoneID = @PhoneID
13094
13095
13096 SET @success =1;
13097 SET @ErrorStatus =0;
13098
13099 COMMIT TRANSACTION;
13100
13101 END TRY
13102
13103 BEGIN CATCH
13104 ROLLBACK TRANSACTION;
13105 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
13106 --We only care if the error was not raised by SSE
13107 IF @@ERROR <> 50000
13108 BEGIN
13109 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
13110 END
13111
13112 SELECT @ErrorStatus= @ErrorStatus + '8001 Update Failed';
13113 RAISERROR(@ErrorStatus, 16, 1);
13114 SET @Success =0;
13115
13116
13117 END CATCH
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135GO
13136/****** Object: StoredProcedure [dbo].[pUpdatePhoneType] Script Date: 10/16/2020 7:31:03 PM ******/
13137SET ANSI_NULLS ON
13138GO
13139SET QUOTED_IDENTIFIER ON
13140GO
13141
13142
13143
13144
13145/*************************************************************************************************
13146
13147*Author: Gary Savard
13148*Date: 12 Oct 10
13149*Table Name: LUPhoneType
13150Description: Updage Phone Type to the LUPhoneType table.The data in this table could easily become
13151poor if the user does not take care when inserting phone types. A mis-spelling can cause unintential duplicate
13152records.
13153Revisions:
13154**************************************************************************************************/
13155
13156CREATE PROCEDURE [dbo].[pUpdatePhoneType](
13157 @PhoneTypeID int,
13158 @PhoneType int,
13159 @ModifiedBy Name,
13160 @Success bit Output,
13161 @ErrorStatus Nvarchar(50) Output
13162 )
13163AS
13164SET NOCOUNT ON;
13165BEGIN
13166 DECLARE
13167 @TempPhoneTypeID int
13168
13169 SET @TempPhoneTypeID =0;
13170 SET @Success = 0;
13171 SET @ErrorStatus ='';
13172
13173
13174
13175
13176
13177BEGIN TRY
13178 BEGIN TRANSACTION;
13179 IF (@PhoneTypeID = 0) OR (@PhoneTypeID IS NULL)
13180 BEGIN
13181 SET @ErrorStatus = '-6085' + ' PhoneTypeID Cant be 0/NULL' ;
13182 RAISERROR(@ErrorStatus,15,1);--Could use WITH LOG for event log
13183 END
13184
13185 SELECT @TempPhoneTypeID = PhoneTypeID
13186 FROM person.LUPhoneType
13187 WHERE PhoneTypeID = @PhoneTypeID
13188
13189
13190 IF @TempPhoneTypeID = 0
13191 BEGIN
13192 SET @ErrorStatus = '-6088' + ' PhoneType doesnt exists LUPhoneType' ; --Failed in lookup table
13193 RAISERROR(@ErrorStatus,15,1);--Could use WITH LOG for event log
13194
13195 END
13196
13197
13198 IF @@Error <> 0
13199 BEGIN
13200 SET @ErrorStatus = '-6080';
13201 SET @Success = 0;
13202 RAISERROR (@ErrorStatus,16,1);
13203 END
13204
13205 UPDATE Person.LUPhoneType
13206 SET PhoneType = @PhoneType,
13207 ModifiedDate= SYSDATETIME(),
13208 ModifiedBy = @ModifiedBy
13209 WHERE PhoneTypeID = @PhoneTypeID
13210
13211 set @success =1;
13212 set @ErrorStatus ='';
13213 COMMIT TRANSACTION;
13214
13215 END TRY
13216
13217 BEGIN CATCH
13218 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
13219 --We only care if the error was not raised by SSE
13220 IF @@ERROR <> 50000
13221 BEGIN
13222 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
13223 END
13224 SET @Success =0;
13225
13226 SET @ErrorStatus= @Errorstatus + ' -6081' +'Insert Failed on Phone Type';
13227 RAISERROR(@ErrorStatus, 16, 1);
13228
13229 ROLLBACK TRANSACTION;
13230 END CATCH
13231
13232
13233END
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243GO
13244/****** Object: StoredProcedure [dbo].[pUpdatepHouseholdTransferOptions] Script Date: 10/16/2020 7:31:03 PM ******/
13245SET ANSI_NULLS ON
13246GO
13247SET QUOTED_IDENTIFIER ON
13248GO
13249
13250
13251
13252
13253/*************************************************************************************************
13254*Author: Gary Savard
13255*Date: 22 April 11
13256*Table Name: LUHouseholdTransferOptions
13257Description: Update data to LUHouseholdTransferOptions.
13258Revisions:
13259
13260**************************************************************************************************/
13261CREATE PROCEDURE [dbo].[pUpdatepHouseholdTransferOptions](
13262 @ActionToTakeID int,
13263 @ActionToTake Nvarchar(50),
13264 @ActionToTakeDescription NVarchar(MAX),
13265 @ModifiedBy Name,
13266 @Success bit Output,
13267 @ErrorStatus Nvarchar(50) Output
13268 )
13269AS
13270SET NOCOUNT ON;
13271
13272BEGIN
13273 DECLARE
13274 @TempActionToTakeID int
13275
13276 SET @TempActionToTakeID =0;
13277 SET @Success = 0;
13278 SET @ErrorStatus ='';
13279
13280
13281
13282
13283
13284 BEGIN TRY
13285 BEGIN TRANSACTION;
13286
13287 /****************************************************************************/
13288
13289
13290 SELECT @TempActionToTakeID = HouseholdTransferActionID
13291 FROM dbo.LUHouseholdTransferOptions
13292 WHERE HouseholdTransferActionID = @ActionToTakeID
13293
13294 If @TempActionToTakeID = 0 --Cant Update if it doesnt exist
13295 BEGIN
13296 SELECT @ErrorStatus = '-6015 Action Type Does Not Exists';
13297 SET @Success =0;
13298 RAISERROR(@ErrorStatus, 16, 1);
13299 END
13300
13301 /****************************************************************************/
13302
13303 IF @@Error <> 0
13304 BEGIN
13305 SELECT @ErrorStatus = Convert (nVarchar(50),@@ERROR) + ' -6010';
13306 SET @Success = 0;
13307 RAISERROR(@ErrorStatus, 16, 1);
13308 END
13309
13310
13311 UPDATE dbo.LUHouseholdTransferOptions
13312 SET ActionToTake = @ActionToTake,
13313 ActionToTakeDescription = @ActionToTakeDescription,
13314 ModifiedBy = @ModifiedBy,
13315 ModifiedDate = SYSDATETIME()
13316 WHERE
13317 HouseholdTransferActionID =@ActionToTakeID;
13318
13319
13320
13321 set @success =1;
13322 set @ErrorStatus ='';
13323 COMMIT TRANSACTION;
13324
13325 END TRY
13326
13327 BEGIN CATCH
13328
13329 ROLLBACK TRANSACTION;
13330 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
13331 --We only care if the error was not raised by SSE
13332 IF @@ERROR <> 50000
13333 BEGIN
13334 SET @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
13335 END
13336
13337
13338 SET @Success =0;
13339 SELECT @ErrorStatus = @ErrorStatus + 'Update Failed Rollback -6011';
13340 RAISERROR(@ErrorStatus, 16, 1);
13341
13342
13343 END CATCH
13344
13345
13346END
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357GO
13358/****** Object: StoredProcedure [dbo].[pUpdatePostalCode] Script Date: 10/16/2020 7:31:03 PM ******/
13359SET ANSI_NULLS ON
13360GO
13361SET QUOTED_IDENTIFIER ON
13362GO
13363
13364
13365
13366
13367
13368
13369
13370
13371/*************************************************************************************************
13372
13373*Author: Gary Savard
13374*Date: 12 Oct 10
13375*Table Name: LUPostalCode
13376Description: Inserts Postal Code to the Postal Code table.This requires that the CityID be passed in as a
13377paramter. It is unlikely that a new city will be build, requiring a new postal code, but it is very likely
13378that a new postal code will be needed in a city.
13379Revisions:
13380**************************************************************************************************/
13381
13382CREATE PROCEDURE [dbo].[pUpdatePostalCode](
13383 @PostalCodeID int,
13384 @CityID int,
13385 @PostalCode Nvarchar(10),
13386 @ModifiedBy Name,
13387 @Success bit Output,
13388 @ErrorStatus Nvarchar(50) Output
13389 )
13390AS
13391SET NOCOUNT ON;
13392BEGIN
13393 DECLARE
13394 @TempCityID int,
13395 @TempPostalCodeID int
13396
13397 SET @TempPostalCodeID = 0;
13398 SET @TempCityID =0;
13399 SET @Success = 0;
13400 SET @ErrorStatus ='';
13401
13402
13403
13404
13405
13406BEGIN TRY
13407 BEGIN TRANSACTION;
13408
13409 IF ((@TempPostalCodeID = 0)OR (@TempPostalCodeID IS NULL)) AND ((@TempCityID =0) OR (@TempCityID IS NULL))
13410 BEGIN
13411 SET @ErrorStatus = '-6075' + ' PostalCodeId/CityID cant be 0/NULL' ;
13412 RAISERROR(@ErrorStatus,15,1);--Could use WITH LOG for event log
13413 END
13414
13415 /****************************************************************************/
13416 --Check to be sure that the city ID and PostalCode ID does exist in the city table before we go on. We could
13417 --just use postal code ,but adding CityID allows for updates to mistakes in city when entered.
13418
13419
13420 SELECT @TempCityID = CityID
13421 FROM person.LUCity
13422 WHERE CityID = @CityID
13423
13424 SELECT @TempPostalCodeID = PostalCodeID
13425 FROM Person.LUPostalCode
13426 WHERE PostalCodeID = @PostalCodeID
13427
13428 If @TempCityID = 0 OR @TempPostalCodeID = 0
13429 BEGIN
13430 SET @ErrorStatus = '-6072' + ' CityID or PostalCodeID doesnt exist in LUtables, cant Update PostalCode' ; --Failed in lookup table
13431 RAISERROR(@ErrorStatus,15,1);--Could use WITH LOG for event log
13432
13433 END
13434/****************************************************************************/
13435
13436 IF @@Error <> 0
13437 BEGIN
13438 SET @ErrorStatus = '-6070';
13439 SET @Success = 0;
13440 RAISERROR (@ErrorStatus,16,1);
13441 END
13442
13443
13444 UPDATE Person.LUPostalCode
13445 SET CityID =@CityID,--Do this in case there was a mistake in original insert
13446 PostalCode = @PostalCode,
13447 ModifiedDate = SYSDATETIME(),
13448 ModifiedBy = @ModifiedBy
13449 WHERE PostalCodeID = @PostalCodeID
13450
13451
13452 set @success =1;
13453 set @ErrorStatus ='';
13454 COMMIT TRANSACTION;
13455
13456END TRY
13457
13458 BEGIN CATCH
13459 ROLLBACK TRANSACTION;
13460 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
13461 --We only care if the error was not raised by SSE
13462 IF @@ERROR <> 50000
13463 BEGIN
13464 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
13465 END
13466 SET @Success =0;
13467 SET @ErrorStatus='-6071' +'Update Failed on PostalCode';
13468 RAISERROR(@ErrorStatus, 16, 1);
13469
13470
13471 END CATCH
13472
13473
13474END
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484GO
13485/****** Object: StoredProcedure [dbo].[pUpdateProgramServiceType] Script Date: 10/16/2020 7:31:03 PM ******/
13486SET ANSI_NULLS ON
13487GO
13488SET QUOTED_IDENTIFIER ON
13489GO
13490
13491
13492
13493
13494
13495/*************************************************************************************************
13496*Author: Gary Savard
13497*Date: 8 Oct 10
13498*Table Name: LUprogramServiceType
13499Description: Update data to LUProgramServiceType. This table matches the Program with the service being
13500used by the client.
13501Revisions:
13502**************************************************************************************************/
13503
13504CREATE PROCEDURE [dbo].[pUpdateProgramServiceType](
13505 @ProgramServiceTypeID int,
13506 @ServiceCode Nvarchar(20),
13507 @ServiceDescription NVarchar(50),
13508 @ModifiedBy Name,
13509 @Success bit Output,
13510 @ErrorStatus Nvarchar(50) Output
13511 )
13512AS
13513SET NOCOUNT ON;
13514
13515 DECLARE
13516 @TempProgramServiceTypeID int
13517
13518 SET @TempProgramServiceTypeID =0;
13519 SET @Success = 0;
13520 SET @ErrorStatus ='';
13521
13522BEGIN
13523 BEGIN TRY
13524 BEGIN TRANSACTION;
13525 IF ((@ProgramServiceTypeID = 0) OR (@ProgramServiceTypeID IS NULL))
13526 BEGIN
13527 SELECT @ErrorStatus = '-6055 ProgramServiceTypeID cant be 0 or NULL';
13528 SET @Success = 0;
13529 RAISERROR(@ErrorStatus, 16,1);
13530 END
13531
13532 SELECT @TempProgramServiceTypeID = ProgramServiceTypeID
13533 FROM Person.LUProgramServiceType
13534 WHERE ProgramServiceTypeID = @ProgramServiceTypeID
13535
13536 IF (@TempProgramServiceTypeID = 0) OR (@TempProgramServiceTypeID IS NULL)
13537 BEGIN
13538 SELECT @ErrorStatus = '-6058 ProgramServiceTypeID cant be 0 or NULL';
13539 SET @Success = 0;
13540 RAISERROR(@ErrorStatus, 16,1);
13541 END
13542
13543 IF @@Error <> 0
13544 BEGIN
13545 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6040';
13546 SET @Success = 0;
13547 RAISERROR(@ErrorStatus, 16,1);
13548 END
13549
13550
13551
13552 BEGIN
13553
13554 UPDATE Person.LUProgramServiceType
13555 SET ServiceCode = @ServiceCode,
13556 ServiceDescription = @ServiceDescription,
13557 ModifiedDate = SYSDATETIME(),
13558 ModifiedBy = @ModifiedBy
13559 WHERE ProgramServiceTypeID = @ProgramServiceTypeID
13560
13561 set @success =1;
13562 set @ErrorStatus =0;
13563 COMMIT TRANSACTION;
13564 END
13565
13566 END TRY
13567
13568 BEGIN CATCH
13569 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
13570 --We only care if the error was not raised by SSE
13571 IF @@ERROR <> 50000
13572 BEGIN
13573 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
13574 END
13575 ROLLBACK TRANSACTION;
13576 SET @Success =0;
13577 SET @ErrorStatus=@ErrorStatus+ 'Update failed Rollback -6051';
13578 RAISERROR(@ErrorStatus, 16, 1);
13579
13580
13581 END CATCH
13582
13583 END
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595GO
13596/****** Object: StoredProcedure [dbo].[pUpdateProgramType] Script Date: 10/16/2020 7:31:03 PM ******/
13597SET ANSI_NULLS ON
13598GO
13599SET QUOTED_IDENTIFIER ON
13600GO
13601
13602
13603
13604
13605
13606
13607/*************************************************************************************************
13608*Author: Gary Savard
13609*Date: 8 Oct 10
13610*Table Name: LUProgramType
13611Description: Update data to LUProgramType. This table matches the Program with the user.
13612Revisions:
13613**************************************************************************************************/
13614
13615CREATE PROCEDURE [dbo].[pUpdateProgramType](
13616 @ProgramTypeID int,
13617 @ProgramName Nvarchar(20),
13618 @ProgramDescription NVarchar(50),
13619 @ModifiedBy Name,
13620 @Success bit Output,
13621 @ErrorStatus Nvarchar(50) Output
13622 )
13623AS
13624SET NOCOUNT ON;
13625BEGIN
13626 DECLARE
13627 @TempProgramTypeID int
13628
13629 SET @TempProgramTypeID =0;
13630 SET @Success = 0;
13631 SET @ErrorStatus ='';
13632
13633
13634BEGIN TRY
13635 BEGIN TRANSACTION;
13636 IF(@ProgramTypeID = 0) OR (@ProgramTypeID IS NULL)
13637 BEGIN
13638 SELECT @ErrorStatus = '-6045 ProgramTypeID cant be 0/null';
13639 SET @Success =0;
13640 RAISERROR(@ErrorStatus,16,1);
13641 END
13642 BEGIN
13643 SELECT ProgramTypeID = @ProgramTypeID
13644 FROM Person.LUProgramType
13645 WHERE ProgramTypeID = @ProgramTypeID
13646
13647 IF(@ProgramTypeID = 0) OR (@ProgramTypeID IS NULL)
13648 BEGIN
13649 SELECT @ErrorStatus = '-6048 ProgramType does not exist';
13650 SET @Success =0;
13651 RAISERROR(@ErrorStatus,16,1);
13652 END
13653
13654 END
13655
13656 IF @@Error <> 0
13657 BEGIN
13658 SELECT @ErrorStatus = @@ERROR + ' -6040';
13659 SET @Success = 0;
13660 END
13661
13662
13663
13664 BEGIN
13665
13666 UPDATE Person.LUProgramType
13667 SET ProgramName = @ProgramName,
13668 ProgramDescription = @ProgramDescription,
13669 ModifiedDate = SYSDATETIME(),
13670 ModifiedBy = @ModifiedBy
13671 WHERE
13672 ProgramTypeID = @ProgramTypeID
13673
13674 SET @success =1;
13675 SET @ErrorStatus =0;
13676 COMMIT TRANSACTION;
13677 END
13678
13679
13680 END TRY
13681
13682 BEGIN CATCH
13683 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
13684 --We only care if the error was not raised by SSE
13685 IF @@ERROR <> 50000
13686 BEGIN
13687 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
13688 END
13689 ROLLBACK TRANSACTION;
13690 SET @Success =0;
13691 SET @ErrorStatus= @ErrorStatus +' -6041 Update Failed on Program Type';
13692 RAISERROR(@ErrorStatus, 16, 1);
13693
13694
13695 END CATCH
13696
13697 END
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709GO
13710/****** Object: StoredProcedure [dbo].[pUpdateRace] Script Date: 10/16/2020 7:31:03 PM ******/
13711SET ANSI_NULLS ON
13712GO
13713SET QUOTED_IDENTIFIER ON
13714GO
13715
13716
13717
13718
13719
13720
13721/*************************************************************************************************
13722*Author: Gary Savard
13723*Date: 9 Oct 10
13724*Table Name: LURace
13725Description: Update data to LURace. This table matches the Race with a U.S Census race category
13726Revisions:
13727**************************************************************************************************/
13728
13729CREATE PROCEDURE [dbo].[pUpdateRace](
13730 @RaceID int,
13731 @RaceAbbreviation NVarchar(10),
13732 @RaceDescription NVarchar(50),
13733 @ModifiedBy Name,
13734 @Success bit Output,
13735 @ErrorStatus NVarchar(50) Output
13736 )
13737AS
13738SET NOCOUNT ON;
13739BEGIN
13740 DECLARE
13741 @TempRaceID int
13742
13743 SET @TempRaceID =0;
13744 SET @Success = 0;
13745 SET @ErrorStatus ='';
13746
13747
13748BEGIN TRY
13749 BEGIN TRANSACTION;
13750 /****************************************************************************/
13751 --Check to see if the RaceID Exists in the DB. Validates the Race ID Input
13752 --White, Black(AA or Negro).American Indian or Alaskan native.,Asian Indian,Chinese,Filipino, Other Asian, Japanese,
13753 --Korean, Vietnamese, Native Hawaiian, Guanamanian or Chamorro, Samoan, Other pacific Islander.
13754 SELECT @TempRaceID = RaceID
13755 FROM person.LURace
13756 WHERE RaceID = @RaceID --Be a bit paranoid and trim the input for white spaces
13757
13758
13759/****************************************************************************/
13760 IF @@Error <> 0
13761 BEGIN
13762 SELECT @ErrorStatus = @@ERROR + '-6020';
13763 SET @Success = 0;
13764 RAISERROR(@ErrorStatus, 16,1);
13765
13766 END
13767 IF (@TempRaceID = NULL) or (@TempRaceID =0) -- can't update if doesnt exist
13768 SELECT @ErrorStatus ='-6028 Does not exist in DB';
13769 SET @Success = 0;
13770 RAISERROR (@ErrorStatus,16,1);
13771
13772
13773
13774 IF @TempRaceID <> 0 --If they exist in the database then
13775 BEGIN
13776
13777 UPDATE Person.LURace
13778 SET RaceAbbreviation = @RaceAbbreviation,
13779 RaceDescription = @RaceDescription,
13780 ModifiedDate = SYSDATETIME(),
13781 ModifiedBy =@ModifiedBy
13782 WHERE
13783 RaceID = @RaceID;
13784
13785 set @success =1;
13786 set @ErrorStatus =0;
13787 COMMIT TRANSACTION;
13788 END
13789END TRY
13790
13791 BEGIN CATCH
13792 ROLLBACK TRANSACTION;
13793 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
13794 --We only care if the error was not raised by SSE
13795 IF @@ERROR <> 50000
13796 BEGIN
13797 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
13798 END
13799 SET @Success =0;
13800 SELECT @ErrorStatus= @ErrorStatus +'-6021 Update Failed Race Type';
13801 RAISERROR(@ErrorStatus, 16, 1);
13802
13803
13804 END CATCH
13805
13806 END
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818GO
13819/****** Object: StoredProcedure [dbo].[pUpdateSSN] Script Date: 10/16/2020 7:31:03 PM ******/
13820SET ANSI_NULLS ON
13821GO
13822SET QUOTED_IDENTIFIER ON
13823GO
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834/*************************************************************************************************
13835*Author: Gary Savard
13836*Date: 15 Oct 10
13837*Table Name: SSN.SSN
13838Description: Updates data to SSN. Only Certain federal programs require that SSN be captured, so we only want to
13839use this sparingly.
13840Revisions:
13841**************************************************************************************************/
13842
13843CREATE PROCEDURE [dbo].[pUpdateSSN](
13844 @SSNID int,
13845 @PersonID int,
13846 @SSN NVarchar(9),
13847 @ModifiedBy Name,
13848 @Success bit Output,
13849 @ErrorStatus Nvarchar(50) Output
13850 )
13851AS
13852SET NOCOUNT ON;
13853BEGIN
13854 DECLARE
13855 @TempPersonID int,
13856 @TempSSNID int
13857
13858 SET @TempPersonID =0;
13859 SET @TempSSNID =0;
13860 SET @Success = 0;
13861 SET @ErrorStatus ='';
13862
13863
13864 BEGIN TRY
13865 BEGIN TRANSACTION;
13866 SELECT @SSN = ltrim(rtrim(@SSN)); --Get rid of spaces before we begin!
13867 /****************************************************************************/
13868 IF ((@PersonID = 0) OR (@PersonID IS NULL))
13869 BEGIN
13870 SELECT @ErrorStatus = '-12005 PersonID cant be 0/NULL';
13871 SET @Success =0;
13872 RAISERROR(@ErrorStatus,16,1);
13873
13874 END
13875 IF ((LEN(@SSN)<9) OR (@SSN IS NULL))
13876 BEGIN
13877 SELECT @ErrorStatus = '-11006 Invalid SSN Null or <9 Characters';
13878 SET @Success =0;
13879 RAISERROR(@ErrorStatus,16,1);
13880
13881 END
13882
13883 IF (@SSNID = 0 OR @SSNID IS NULL)
13884 BEGIN
13885 SELECT @ErrorStatus ='-12006 SSNID Cant be 0/NULL';
13886 SET @Success =0;
13887 RAISERROR (@ErrorStatus,16,1);
13888 END
13889
13890
13891 --Final check to be sure this is not a duplicate
13892
13893 SELECT @TempSSNID = SSNID
13894 FROM SSN.SSN
13895 WHERE PersonID = @PersonID AND SSNID =@SSNID
13896
13897 IF @TempSSNID = 0
13898 --No Record, Cant update!
13899 BEGIN
13900 SELECT @ErrorStatus = '-12008 Record Does not Exist';
13901 SET @Success =0;
13902 RAISERROR(@ErrorStatus,16,1);
13903 END
13904
13905
13906
13907 /****************************************************************************/
13908 IF @@Error <> 0
13909 BEGIN
13910 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -12001';
13911 SET @Success = 0;
13912 RAISERROR(@ErrorStatus,16,1);
13913 END
13914
13915
13916
13917
13918
13919 UPDATE SSN.SSN
13920 SET PersonID = @PersonID,
13921 SSN = @SSN,
13922 ModifiedDate = SYSDATETIME(),
13923 ModifiedBy = @ModifiedBy
13924
13925 WHERE SSNID = @SSNID
13926
13927
13928 SET @success =1;
13929 SET @ErrorStatus =0;
13930
13931 COMMIT TRANSACTION;
13932
13933
13934 END TRY
13935
13936 BEGIN CATCH
13937 ROLLBACK TRANSACTION;
13938 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
13939 --We only care if the error was not raised by SSE
13940 IF @@ERROR <> 50000
13941 BEGIN
13942 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
13943 END
13944 SET @Success =0;
13945 SELECT @ErrorStatus= @ErrorStatus + 'SSN -12001';
13946 RAISERROR(@ErrorStatus, 16, 1);
13947
13948
13949 END CATCH
13950
13951 END
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964GO
13965/****** Object: StoredProcedure [dbo].[pUpdateState] Script Date: 10/16/2020 7:31:03 PM ******/
13966SET ANSI_NULLS ON
13967GO
13968SET QUOTED_IDENTIFIER ON
13969GO
13970
13971
13972
13973
13974
13975/*************************************************************************************************
13976*Author: Gary Savard
13977*Date: 8 Oct 10
13978*Table Name: LUState
13979Description: Update data to LUState. This table matches the State with a State ID for ties to County, City and Zip Code.
13980Revisions:
13981**************************************************************************************************/
13982
13983CREATE PROCEDURE [dbo].[pUpdateState](
13984 @StateID int,
13985 @StateCode Nvarchar(2),
13986 @Name Nvarchar(50),
13987 @ModifiedBy Name,
13988 @Success bit Output,
13989 @ErrorStatus Nvarchar(50) Output
13990 )
13991AS
13992SET NOCOUNT ON;
13993BEGIN
13994 DECLARE
13995 @TempStateID int
13996
13997 SET @TempStateID =0;
13998 SET @Success = 0;
13999 SET @ErrorStatus ='';
14000
14001
14002BEGIN TRY
14003 BEGIN TRANSACTION;
14004 /****************************************************************************/
14005--This could go after the test for @StateId =0 but will leave here
14006 SELECT @TempStateID = StateID
14007 FROM person.LUState
14008 WHERE StateID = @StateID
14009
14010/****************************************************************************/
14011 IF (@TempStateId = NULL) OR (@TempStateID = 0)
14012 BEGIN
14013 SELECT @ErrorStatus = 'State does not exist -6038';
14014 SET @Success =0;
14015 RAISERROR(@ErrorStatus, 16,1);
14016 END
14017
14018 IF @@Error <> 0
14019 BEGIN
14020 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + '-6030';
14021 SET @Success = 0;
14022 RAISERROR(@ErrorStatus, 16, 1);
14023 END
14024
14025
14026 IF @StateID = 0
14027 BEGIN
14028 SELECT @ErrorStatus = '@StateID cant be 0 -6035';
14029 SET @Success =0;
14030 RAISERROR(@ErrorStatus, 16,1);
14031 END
14032
14033
14034 UPDATE Person.LUState
14035 SET StateCode = @StateCode,
14036 Name = @Name,
14037 ModifiedBy = @ModifiedBy,
14038 ModifiedDate = SYSDATETIME()
14039 WHERE
14040 StateID = @StateID;
14041
14042
14043 set @success =1;
14044 set @ErrorStatus =0;
14045 COMMIT TRANSACTION;
14046
14047
14048 END TRY
14049
14050 BEGIN CATCH
14051 ROLLBACK TRANSACTION;
14052 SET @Success =0;
14053 SET @ErrorStatus= @ErrorStatus + @@ERROR + '-6031 Update Failed on State';--6030-6039 is for this table
14054 RAISERROR(@ErrorStatus, 16, 1);
14055
14056
14057 END CATCH
14058
14059 END
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072GO
14073/****** Object: StoredProcedure [dbo].[spInsertJournalClientFamilyChanges] Script Date: 10/16/2020 7:31:03 PM ******/
14074SET ANSI_NULLS ON
14075GO
14076SET QUOTED_IDENTIFIER ON
14077GO
14078
14079
14080
14081-- =============================================
14082-- Author: Gary Savard
14083-- Create date: 6 JUNE 11
14084-- Description: This sp inserts a row in the journaling table for recordkeeping of admin functions.
14085--
14086-- =============================================
14087CREATE PROCEDURE [dbo].[spInsertJournalClientFamilyChanges]
14088(
14089 @HouseholdMembersID int,
14090 @PreviousClientsID int,
14091 @NewClientsID int,
14092 @ActionTaken NVarchar(50),
14093 @Notes NVarchar(MAX),
14094 @ModifiedBy Name
14095
14096)
14097
14098AS
14099BEGIN
14100BEGIN TRANSACTION
14101--No Error handling used because we do not want to affect the main sp with problems here.
14102
14103 INSERT dbo.JournalClientFamilyChanges
14104 (HouseholdMembersID,
14105 PreviousClientsID,
14106 NewClientsID,
14107 ActionTaken,
14108 Notes,
14109 ModifiedBy,
14110 ModifiedDate)
14111 VALUES
14112 (@HouseholdMembersID,
14113 @PreviousClientsID,
14114 @NewClientsID,
14115 @ActionTaken,
14116 @Notes,
14117 @ModifiedBy,
14118 SYSDATETIME())
14119
14120
14121IF @@ROWCOUNT >0
14122 COMMIT TRANSACTION
14123ELSE
14124 ROLLBACK TRANSACTION
14125END
14126
14127
14128
14129
14130GO
14131/****** Object: StoredProcedure [Maintenance].[CreateRoleScript] Script Date: 10/16/2020 7:31:03 PM ******/
14132SET ANSI_NULLS ON
14133GO
14134SET QUOTED_IDENTIFIER ON
14135GO
14136--Written By Bradley Morris
14137--In Query Analyzer be sure to go to
14138--Query -> Current Connection Options -> Advanced (Tab)
14139--and set Maximum characters per column
14140--to a high number, such as 10000, so
14141--that all the code will be displayed.
14142
14143Create Procedure [Maintenance].[CreateRoleScript](@RoleName [SYSNAME])
14144As
14145
14146--Written By Bradley Morris
14147--In Query Analyzer be sure to go to
14148--Query -> Current Connection Options -> Advanced (Tab)
14149--and set Maximum characters per column
14150--to a high number, such as 10000, so
14151--that all the code will be displayed.
14152
14153DECLARE @DatabaseRoleName [SYSNAME]
14154--SET @DatabaseRoleName = '{Database Role Name}'
14155
14156--SET @DatabaseRoleName = 'role_name_goes_here'
14157SET @DatabaseRoleName =@RoleName
14158
14159SET NoCount ON
14160
14161DECLARE @errStatement [VARCHAR](8000),
14162 @msgStatement [VARCHAR](8000),
14163 @DatabaseRoleID [SMALLINT],
14164 @IsApplicationRole [BIT],
14165 @ObjectID [INT],
14166 @ObjectName [SYSNAME]
14167
14168SELECT @DatabaseRoleID = [uId],
14169 @IsApplicationRole = CAST([IsapProle] AS BIT)
14170FROM [dbo].[sysUsers]
14171WHERE [Name] = @DatabaseRoleName
14172 AND ([IssqlRole] = 1
14173 OR [IsapProle] = 1)
14174 AND [Name] NOT IN ('public',
14175 'INFORMATION_SCHEMA',
14176 'db_owner',
14177 'db_accessadmin',
14178 'db_securityadmin',
14179 'db_ddladmin',
14180 'db_backupoperator',
14181 'db_datareader',
14182 'db_datawriter',
14183 'db_denydatareader',
14184 'db_denydatawriter')
14185
14186IF @DatabaseRoleID IS NULL
14187 BEGIN
14188 IF @DatabaseRoleName IN ('public',
14189 'INFORMATION_SCHEMA',
14190 'db_owner',
14191 'db_accessadmin',
14192 'db_securityadmin',
14193 'db_ddladmin',
14194 'db_backupoperator',
14195 'db_datareader',
14196 'db_datawriter',
14197 'db_denydatareader',
14198 'db_denydatawriter')
14199 SET @errStatement = 'Role ' + @DatabaseRoleName + ' is a fixed database role and cannot be scripted.'
14200 ELSE
14201 SET @errStatement = 'Role ' + @DatabaseRoleName + ' does not exist in ' + Db_name() + '.' + CHAR(13) + 'Please provide the name of a current role in ' + Db_name() + ' you wish to script.'
14202 RAISERROR (@errStatement,16,1)
14203 END
14204ELSE
14205 BEGIN
14206 SET @msgStatement = '--Security creation script for role ' + @DatabaseRoleName + CHAR(13) + '--Created At: ' + CONVERT(VARCHAR,Getdate(),112) + REPLACE(CONVERT(VARCHAR,Getdate(),108),':','') + CHAR(13) + '--Created By: ' + Suser_name() + CHAR(13) + '--Add Role To Database' + CHAR(13)
14207 IF @IsApplicationRole = 1
14208 SET @msgStatement = @msgStatement + 'EXEC sp_addapprole' + CHAR(13) + CHAR(9) + '@rolename = ''' + @DatabaseRoleName + '''' + CHAR(13) + CHAR(9) + '@password = ''{Please provide the password here}''' + CHAR(13)
14209 ELSE
14210 BEGIN
14211 SET @msgStatement = @msgStatement + 'EXEC sp_addrole' + CHAR(13) + CHAR(9) + '@rolename ''' + @DatabaseRoleName + '''' + CHAR(13)
14212 PRINT 'GO'
14213 END
14214 SET @msgStatement = @msgStatement + '--Set Object Specific Permissions For Role'
14215 PRINT @msgStatement
14216 DECLARE _sySobjects CURSOR LOCAL FORWARD_ONLY READ_ONLY FOR
14217 SELECT DISTINCT ([sySobjects].[Id]),
14218 '[' + User_name([sySobjects].[uId]) + '].[' + [sySobjects].[Name] + ']'
14219 FROM [dbo].[sysProtects]
14220 INNER JOIN [dbo].[sySobjects]
14221 ON [sysProtects].[Id] = [sySobjects].[Id]
14222 WHERE [sysProtects].[uId] = @DatabaseRoleID
14223 OPEN _sySobjects
14224 FETCH NEXT FROM _sySobjects
14225 INTO @ObjectID,
14226 @ObjectName
14227 WHILE @@FETCH_STATUS = 0
14228 BEGIN
14229 SET @msgStatement = ''
14230 IF EXISTS (SELECT *
14231 FROM [dbo].[sysProtects]
14232 WHERE [Id] = @ObjectID
14233 AND [uId] = @DatabaseRoleID
14234 AND [Action] = 193
14235 AND [ProtectType] = 205)
14236 SET @msgStatement = @msgStatement + 'SELECT,'
14237 IF EXISTS (SELECT *
14238 FROM [dbo].[sysProtects]
14239 WHERE [Id] = @ObjectID
14240 AND [uId] = @DatabaseRoleID
14241 AND [Action] = 195
14242 AND [ProtectType] = 205)
14243 SET @msgStatement = @msgStatement + 'INSERT,'
14244 IF EXISTS (SELECT *
14245 FROM [dbo].[sysProtects]
14246 WHERE [Id] = @ObjectID
14247 AND [uId] = @DatabaseRoleID
14248 AND [Action] = 197
14249 AND [ProtectType] = 205)
14250 SET @msgStatement = @msgStatement + 'UPDATE,'
14251 IF EXISTS (SELECT *
14252 FROM [dbo].[sysProtects]
14253 WHERE [Id] = @ObjectID
14254 AND [uId] = @DatabaseRoleID
14255 AND [Action] = 196
14256 AND [ProtectType] = 205)
14257 SET @msgStatement = @msgStatement + 'DELETE,'
14258 IF EXISTS (SELECT *
14259 FROM [dbo].[sysProtects]
14260 WHERE [Id] = @ObjectID
14261 AND [uId] = @DatabaseRoleID
14262 AND [Action] = 224
14263 AND [ProtectType] = 205)
14264 SET @msgStatement = @msgStatement + 'EXECUTE,'
14265 IF EXISTS (SELECT *
14266 FROM [dbo].[sysProtects]
14267 WHERE [Id] = @ObjectID
14268 AND [uId] = @DatabaseRoleID
14269 AND [Action] = 26
14270 AND [ProtectType] = 205)
14271 SET @msgStatement = @msgStatement + 'REFERENCES,'
14272 IF len(@msgStatement) > 0
14273 BEGIN
14274 IF RIGHT(@msgStatement,1) = ','
14275 SET @msgStatement = LEFT(@msgStatement,Len(@msgStatement) - 1)
14276 SET @msgStatement = 'GRANT' + CHAR(13) + CHAR(9) + @msgStatement + CHAR(13) + CHAR(9) + 'ON ' + @ObjectName + CHAR(13) + CHAR(9) + 'TO ' + @DatabaseRoleName
14277 PRINT @msgStatement
14278 END
14279 SET @msgStatement = ''
14280 IF EXISTS (SELECT *
14281 FROM [dbo].[sysProtects]
14282 WHERE [Id] = @ObjectID
14283 AND [uId] = @DatabaseRoleID
14284 AND [Action] = 193
14285 AND [ProtectType] = 206)
14286 SET @msgStatement = @msgStatement + 'SELECT,'
14287 IF EXISTS (SELECT *
14288 FROM [dbo].[sysProtects]
14289 WHERE [Id] = @ObjectID
14290 AND [uId] = @DatabaseRoleID
14291 AND [Action] = 195
14292 AND [ProtectType] = 206)
14293 SET @msgStatement = @msgStatement + 'INSERT,'
14294 IF EXISTS (SELECT *
14295 FROM [dbo].[sysProtects]
14296 WHERE [Id] = @ObjectID
14297 AND [uId] = @DatabaseRoleID
14298 AND [Action] = 197
14299 AND [ProtectType] = 206)
14300 SET @msgStatement = @msgStatement + 'UPDATE,'
14301 IF EXISTS (SELECT *
14302 FROM [dbo].[sysProtects]
14303 WHERE [Id] = @ObjectID
14304 AND [uId] = @DatabaseRoleID
14305 AND [Action] = 196
14306 AND [ProtectType] = 206)
14307 SET @msgStatement = @msgStatement + 'DELETE,'
14308 IF EXISTS (SELECT *
14309 FROM [dbo].[sysProtects]
14310 WHERE [Id] = @ObjectID
14311 AND [uId] = @DatabaseRoleID
14312 AND [Action] = 224
14313 AND [ProtectType] = 206)
14314 SET @msgStatement = @msgStatement + 'EXECUTE,'
14315 IF EXISTS (SELECT *
14316 FROM [dbo].[sysProtects]
14317 WHERE [Id] = @ObjectID
14318 AND [uId] = @DatabaseRoleID
14319 AND [Action] = 26
14320 AND [ProtectType] = 206)
14321 SET @msgStatement = @msgStatement + 'REFERENCES,'
14322 IF len(@msgStatement) > 0
14323 BEGIN
14324 IF RIGHT(@msgStatement,1) = ','
14325 SET @msgStatement = LEFT(@msgStatement,Len(@msgStatement) - 1)
14326 SET @msgStatement = 'DENY' + CHAR(13) + CHAR(9) + @msgStatement + CHAR(13) + CHAR(9) + 'ON ' + @ObjectName + CHAR(13) + CHAR(9) + 'TO ' + @DatabaseRoleName
14327 PRINT @msgStatement
14328 END
14329 FETCH NEXT FROM _sySobjects
14330 INTO @ObjectID,
14331 @ObjectName
14332 END
14333 CLOSE _sySobjects
14334 DEALLOCATE _sySobjects
14335 PRINT 'GO'
14336 END
14337
14338GO
14339/****** Object: StoredProcedure [Maintenance].[pFamilyMemberStartsNewHousehold] Script Date: 10/16/2020 7:31:03 PM ******/
14340SET ANSI_NULLS ON
14341GO
14342SET QUOTED_IDENTIFIER ON
14343GO
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354/*************************************************************************************************
14355*
14356*Author: Gary Savard
14357*Date: 15 April 2011
14358*
14359Description: This SP covers the instances where a family member starts a new household. This is really only removing
14360them from their current household since the record type is the same for client and family members.
14361Revisions:
14362**************************************************************************************************/
14363CREATE PROCEDURE [Maintenance].[pFamilyMemberStartsNewHousehold](
14364 @ClientPersonID int, -- The old client that the person moving is associated with.
14365 @FamilyToClientPersonID int,--The person who is creating a new household.
14366 @ModifiedBy name,
14367 @Success bit Output,
14368 @ErrorStatus Nvarchar(50) Output
14369 )
14370AS
14371SET NOCOUNT ON;
14372BEGIN
14373 DECLARE
14374 @TempPersonID int,
14375 @PersonID int,
14376 @Notes NVarchar(100),
14377 @ErrNo int
14378
14379 SET @TempPersonID =0;
14380 SET @Success = 0;
14381 SET @ErrorStatus ='';
14382 SET @TempPersonID =0;
14383 SET @ErrNo =0;
14384
14385
14386
14387BEGIN TRY
14388 BEGIN TRANSACTION;
14389 --We first check to be sure that the @FamilyToClientPersonID is in the db
14390 --Check to see that the old @ClientToPersonID is in the db
14391 --if either fails, then bail!
14392 --Place a record in the Journal Table with the appropriate information before making the change.
14393 --Remove the new client from the FamilyRelationship table
14394 --Make update to Family relationships table table for new family status. This will probably be blank since we will
14395 --want the family to be created on the new query.
14396
14397
14398
14399
14400 --We need them BOTH to be in the FamilyRelationship table in the same record, else the system does not know that they are related!
14401 IF EXISTS(SELECT * from person.FamilyRelationships where PersonID =@FamilyToClientPersonID AND ClientPersonID=@ClientPersonID)
14402 BEGIN
14403 --Create a string to pass into notes in journal
14404 SET @Notes = 'Create new household for Person = ' + @FamilyToClientPersonID + 'Previous Household''s Head = ' + @ClientPersonID + 'old household tie removed from FamilyRelationships table'
14405
14406 --Time to remove the person. We need to only remove them from the FamilyRelationships table. They will have to Certify when they come in.
14407
14408 DELETE FROM Person.FamilyRelationships WHERE PersonID = @FamilyToClientPersonID AND ClientPersonID = @ClientPersonID
14409
14410 SELECT @ErrNo=@@ERROR
14411
14412 IF @ErrNo<>0
14413 BEGIN
14414 SET @ErrorStatus ='Failed on Delete Family Member PersonID: ' + CONVERT(NVarchar(50),@FamilyToClientPersonID)
14415 RAISERROR(@ErrorStatus,16,0)
14416
14417 END--IF@ErrNO
14418
14419 --Make Journal Entry. We are ignoring potential errors from journal for the time being.
14420 EXEC pInsertJournalClientFamilyChanges @FamilyToClientPersonID,@ClientPersonID,0,'New Household Created','',@ModifiedBY,@Success OUTPUT,@ErrorStatus OUTPUT
14421
14422
14423
14424 END
14425 ELSE
14426 BEGIN
14427 SET @ErrorStatus ='Client/House member not matched FamRel tab : ' + CONVERT(NVarchar(50),@FamilyToClientPersonID) + ' ' + CONVERT(NVarchar(50),@ClientPersonID)
14428 RAISERROR(@ErrorStatus,16,0)
14429
14430 END
14431
14432
14433 /******************************************************************************************************
14434
14435
14436
14437 *******************************************************************************************************/
14438 COMMIT TRANSACTION;
14439
14440 END TRY
14441
14442 BEGIN CATCH
14443 ROLLBACK TRANSACTION;
14444 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
14445 --We only care if the error was not raised by SSE
14446 IF @@ERROR <> 50000
14447 BEGIN
14448 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
14449 END
14450 SET @Success =0;
14451 SET @ErrorStatus= @ErrorStatus + '-1001';
14452 RAISERROR(@ErrorStatus, 15, 1);
14453
14454
14455 END CATCH
14456
14457 END
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470GO
14471/****** Object: StoredProcedure [Maintenance].[pGrantViewDefinitionsforUDTs] Script Date: 10/16/2020 7:31:03 PM ******/
14472SET ANSI_NULLS ON
14473GO
14474SET QUOTED_IDENTIFIER ON
14475GO
14476
14477
14478CREATE PROCEDURE [Maintenance].[pGrantViewDefinitionsforUDTs]
14479
14480AS
14481BEGIN
14482
14483DECLARE
14484
14485@UDTName NVarchar(30),
14486@SchemaID int,
14487@SchemaName NVarchar(30),
14488@Cnt int,
14489@NumRec int,
14490@ExecString NVarchar(200)
14491
14492
14493
14494CREATE TABLE #TempTable (counts INT identity,name Varchar(50),SchemaID int)
14495INSERT INTO #TempTable SELECT name,schema_id FROM sys.Types
14496WHERE is_user_defined = 1
14497
14498SELECT @NumRec = MAX(Counts) from #TempTable
14499
14500SET @Cnt =1
14501
14502While @Cnt <= @NumRec
14503 BEGIN
14504 SELECT @UDTName =name, @SchemaID =SCHEMAID from #TempTable where counts =@Cnt
14505
14506 SELECT @SchemaName =name from sys.schemas where schema_id =@SchemaID
14507
14508 SET @ExecString = 'GRANT VIEW DEFINITION ON TYPE::[' + @SchemaName + '].' + @UDTNAME + ' TO db_CrystalReports'
14509
14510 EXEC (@ExecString)
14511
14512 SET @Cnt = @Cnt +1
14513
14514 END
14515Drop Table #TempTable
14516
14517END
14518
14519
14520GO
14521/****** Object: StoredProcedure [Maintenance].[pHideAddressType] Script Date: 10/16/2020 7:31:03 PM ******/
14522SET ANSI_NULLS ON
14523GO
14524SET QUOTED_IDENTIFIER ON
14525GO
14526
14527
14528/*************************************************************************************************
14529
14530*Author: Gary Savard
14531*Date: 21 July 2011
14532*Table Name: LUAddressType
14533Description: Suppresses from LUAddressType
14534Revisions:
14535**************************************************************************************************/
14536CREATE PROCEDURE [Maintenance].[pHideAddressType](
14537 @AddressTypeID int,
14538 @Success bit Output,
14539 @ErrorStatus Nvarchar(50) Output
14540 )
14541AS
14542SET NOCOUNT ON;
14543
14544 DECLARE
14545 @TempAddressTypeID int
14546
14547 SET @TempAddressTypeID =0;
14548 SET @Success = 0;
14549 SET @ErrorStatus ='';
14550
14551
14552
14553 BEGIN
14554 BEGIN TRY
14555 BEGIN TRANSACTION;
14556 IF ((@AddressTypeID = 0) OR (@AddressTypeID IS NULL))
14557 BEGIN
14558 SELECT @ErrorStatus = '6015 AddressTypeID cannot be 0/NULL';
14559 SET @Success = 0;
14560 RAISERROR(@ErrorStatus, 16,1);
14561 END
14562
14563
14564 SELECT @TempAddressTypeID =@AddressTypeID
14565 FROM person.LUAddressType
14566 WHERE AddressTypeID= @AddressTypeID
14567
14568
14569 IF ((@TempAddressTypeID=0) OR (@TempAddressTypeID IS NULL))
14570 BEGIN
14571 SELECT @ErrorStatus = ' -6018 AddressTypeID does not exist';
14572 SET @Success =0;
14573 RAISERROR(@ErrorStatus,16,1);
14574 END
14575
14576 IF @@Error <> 0
14577 BEGIN
14578 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6010';
14579 SET @Success = 0;
14580 RAISERROR(@ErrorStatus, 16, 1);
14581 END
14582
14583 UPDATE Person.LUAddressType
14584 SET IsDeleted =1
14585 WHERE AddressTypeID = @AddressTypeID
14586
14587 set @success =1;
14588 set @ErrorStatus =0;
14589 COMMIT TRANSACTION;
14590
14591 END TRY
14592
14593 BEGIN CATCH
14594 ROLLBACK TRANSACTION;
14595 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
14596 --We only care if the error was not raised by SSE
14597 IF @@ERROR <> 50000
14598 BEGIN
14599 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
14600 END
14601 SET @Success =0;
14602 SELECT @ErrorStatus= @ErrorStatus +'-6013 DELETE Fail AddressType';
14603 RAISERROR(@ErrorStatus, 15, 1);
14604
14605
14606 END CATCH
14607
14608 END
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622GO
14623/****** Object: StoredProcedure [Maintenance].[pHideCity] Script Date: 10/16/2020 7:31:03 PM ******/
14624SET ANSI_NULLS ON
14625GO
14626SET QUOTED_IDENTIFIER ON
14627GO
14628
14629
14630/*************************************************************************************************
14631
14632*Author: Gary Savard
14633*Date:21 July 2011
14634*Table Name: LUCity
14635Description: Hides row in LUCity
14636Revisions:
14637**************************************************************************************************/
14638CREATE PROCEDURE [Maintenance].[pHideCity](
14639 @CityID int,
14640 @Success bit Output,
14641 @ErrorStatus Nvarchar(50) Output
14642 )
14643AS
14644SET NOCOUNT ON;
14645
14646 DECLARE
14647 @TempCityID int
14648
14649 SET @TempCityID =0;
14650 SET @Success = 0;
14651 SET @ErrorStatus ='';
14652
14653
14654
14655 BEGIN
14656 BEGIN TRY
14657 BEGIN TRANSACTION;
14658 IF ((@CityID = 0) OR (@CityID IS NULL))
14659 BEGIN
14660 SELECT @ErrorStatus = '60055 CityID cant be 0/NULL';
14661 SET @Success = 0;
14662 RAISERROR(@ErrorStatus, 16,1);
14663 END
14664
14665
14666 SELECT @TempCityID =@CityID
14667 FROM person.LUCity
14668 WHERE CityID= @CityID
14669
14670
14671 IF ((@TempCityID=0) OR (@TempCityID IS NULL))
14672 BEGIN
14673 SELECT @ErrorStatus = ' -60058 CityID does not exist';
14674 SET @Success =0;
14675 RAISERROR(@ErrorStatus,16,1);
14676 END
14677
14678 IF @@Error <> 0
14679 BEGIN
14680 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -60050';
14681 SET @Success = 0;
14682 RAISERROR(@ErrorStatus, 16, 1);
14683 END
14684
14685 UPDATE Person.LUCity SET IsDeleted =1
14686 WHERE CityID = @CityID
14687
14688 set @success =1;
14689 set @ErrorStatus =0;
14690 COMMIT TRANSACTION;
14691
14692 END TRY
14693
14694 BEGIN CATCH
14695 ROLLBACK TRANSACTION;
14696 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
14697 --We only care if the error was not raised by SSE
14698 IF @@ERROR <> 50000
14699 BEGIN
14700 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
14701 END
14702 SET @Success =0;
14703 SELECT @ErrorStatus= @ErrorStatus +'-60053 DELETE Fail City';
14704 RAISERROR(@ErrorStatus, 15, 1);
14705
14706
14707 END CATCH
14708
14709 END
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723GO
14724/****** Object: StoredProcedure [Maintenance].[pHideContactType] Script Date: 10/16/2020 7:31:03 PM ******/
14725SET ANSI_NULLS ON
14726GO
14727SET QUOTED_IDENTIFIER ON
14728GO
14729
14730
14731/*************************************************************************************************
14732
14733*Author: Gary Savard
14734*Date: 21 July 2011
14735*Table Name: LUContactType
14736Description: Hides LUContactType
14737Revisions:
14738**************************************************************************************************/
14739CREATE PROCEDURE [Maintenance].[pHideContactType](
14740 @ContactTypeID int,
14741 @Success bit Output,
14742 @ErrorStatus Nvarchar(50) Output
14743 )
14744AS
14745SET NOCOUNT ON;
14746
14747 DECLARE
14748 @TempContactTypeID int
14749
14750 SET @TempContactTypeID =0;
14751 SET @Success = 0;
14752 SET @ErrorStatus ='';
14753
14754
14755
14756 BEGIN
14757 BEGIN TRY
14758 BEGIN TRANSACTION;
14759 IF ((@ContactTypeID = 0) OR (@ContactTypeID IS NULL))
14760 BEGIN
14761 SELECT @ErrorStatus = '60025 ContactTypeID cant be 0/NULL';
14762 SET @Success = 0;
14763 RAISERROR(@ErrorStatus, 16,1);
14764 END
14765
14766
14767 SELECT @TempContactTypeID =ContactTypeID
14768 FROM person.LUContactType
14769 WHERE ContactTypeID= @ContactTypeID
14770
14771
14772 IF ((@TempContactTypeID=0) OR (@TempContactTypeID IS NULL))
14773 BEGIN
14774 SELECT @ErrorStatus = ' -60028 ContactTypeID does not exist';
14775 SET @Success =0;
14776 RAISERROR(@ErrorStatus,16,1);
14777 END
14778
14779 IF @@Error <> 0
14780 BEGIN
14781 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -60020';
14782 SET @Success = 0;
14783 RAISERROR(@ErrorStatus, 16, 1);
14784 END
14785
14786 UPDATE Person.LUContactType
14787 SET IsDeleted =1
14788 WHERE ContactTypeID = @ContactTypeID
14789
14790 set @success =1;
14791 set @ErrorStatus =0;
14792 COMMIT TRANSACTION;
14793
14794 END TRY
14795
14796 BEGIN CATCH
14797 ROLLBACK TRANSACTION;
14798 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
14799 --We only care if the error was not raised by SSE
14800 IF @@ERROR <> 50000
14801 BEGIN
14802 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
14803 END
14804 SET @Success =0;
14805 SELECT @ErrorStatus= @ErrorStatus +'-60023 DELETE Fail ContactType';
14806 RAISERROR(@ErrorStatus, 15, 1);
14807
14808
14809 END CATCH
14810
14811 END
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825GO
14826/****** Object: StoredProcedure [Maintenance].[pHideEducationCategory] Script Date: 10/16/2020 7:31:03 PM ******/
14827SET ANSI_NULLS ON
14828GO
14829SET QUOTED_IDENTIFIER ON
14830GO
14831
14832
14833
14834
14835
14836/*************************************************************************************************
14837
14838*Author: Gary Savard
14839*Date: 21 July 2011
14840*Table Name: LUEducationCategory
14841Description: Hides LUEducationCategory
14842Revisions:
14843**************************************************************************************************/
14844CREATE PROCEDURE [Maintenance].[pHideEducationCategory](
14845 @EducationCategoryID int,
14846 @Success bit Output,
14847 @ErrorStatus Nvarchar(50) Output
14848 )
14849AS
14850SET NOCOUNT ON;
14851
14852 DECLARE
14853 @TempEducationCategoryID int
14854
14855
14856 SET @TempEducationCategoryID =0;
14857 SET @Success = 0;
14858 SET @ErrorStatus ='';
14859
14860
14861
14862 BEGIN
14863 BEGIN TRY
14864 BEGIN TRANSACTION;
14865 IF ((@EducationCategoryID = 0) OR (@EducationCategoryID IS NULL))
14866 BEGIN
14867 SELECT @ErrorStatus = '60065 EducationCategoryID cant be 0/NULL';
14868 SET @Success = 0;
14869 RAISERROR(@ErrorStatus, 16,1);
14870 END
14871
14872
14873 SELECT @TempEducationCategoryID = EducationCategoryID
14874 FROM person.LUEducationCategory
14875 WHERE EducationCategoryID = @TempEducationCategoryID
14876
14877
14878 IF ((@TempEducationCategoryID=0) OR (@TempEducationCategoryID IS NULL))
14879 BEGIN
14880 SELECT @ErrorStatus = ' -60078 EducationCategoryID does not exist';
14881 SET @Success =0;
14882 RAISERROR(@ErrorStatus,16,1);
14883 END
14884
14885 IF @@Error <> 0
14886 BEGIN
14887 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -2000';
14888 SET @Success = 0;
14889 RAISERROR(@ErrorStatus, 16, 1);
14890 END
14891
14892 UPDATE Person.LUEducationCategory
14893 SET IsDeleted =1
14894 WHERE EducationCategoryID = @EducationCategoryID
14895
14896 set @success =1;
14897 set @ErrorStatus =0;
14898 COMMIT TRANSACTION;
14899
14900 END TRY
14901
14902 BEGIN CATCH
14903 ROLLBACK TRANSACTION;
14904 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
14905 --We only care if the error was not raised by SSE
14906 IF @@ERROR <> 50000
14907 BEGIN
14908 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
14909 END
14910 SET @Success =0;
14911 SELECT @ErrorStatus= @ErrorStatus +'-60073 DELETE Fail EducationCategory';
14912 RAISERROR(@ErrorStatus, 15, 1);
14913
14914
14915 END CATCH
14916
14917 END
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931GO
14932/****** Object: StoredProcedure [Maintenance].[pHideEthnicity] Script Date: 10/16/2020 7:31:03 PM ******/
14933SET ANSI_NULLS ON
14934GO
14935SET QUOTED_IDENTIFIER ON
14936GO
14937
14938
14939
14940
14941
14942/*************************************************************************************************
14943
14944*Author: Gary Savard
14945*Date: 21 July 11
14946*Table Name: LUEthnicity
14947Description: Hides LUEthicity
14948Revisions:
14949**************************************************************************************************/
14950CREATE PROCEDURE [Maintenance].[pHideEthnicity](
14951 @EthnicityID int,
14952 @Success bit Output,
14953 @ErrorStatus Nvarchar(50) Output
14954 )
14955AS
14956SET NOCOUNT ON;
14957
14958 DECLARE
14959 @TempEthnicityID int
14960
14961 SET @TempEthnicityID =0;
14962 SET @Success = 0;
14963 SET @ErrorStatus ='';
14964
14965
14966
14967 BEGIN
14968 BEGIN TRY
14969 BEGIN TRANSACTION;
14970 IF ((@EthnicityID = 0) OR (@EthnicityID IS NULL))
14971 BEGIN
14972 SELECT @ErrorStatus = '60085 EthnicityID cant be 0/NULL';
14973 SET @Success = 0;
14974 RAISERROR(@ErrorStatus, 16,1);
14975 END
14976
14977
14978 SELECT @TempEthnicityID =EthnicityID
14979 FROM person.LUEthnicity
14980 WHERE EthnicityID = @TempEthnicityID
14981
14982
14983 IF ((@TempEthnicityID=0) OR (@TempEthnicityID IS NULL))
14984 BEGIN
14985 SELECT @ErrorStatus = ' -60088 EthnicityID does not exist';
14986 SET @Success =0;
14987 RAISERROR(@ErrorStatus,16,1);
14988 END
14989
14990 IF @@Error <> 0
14991 BEGIN
14992 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -2000';
14993 SET @Success = 0;
14994 RAISERROR(@ErrorStatus, 16, 1);
14995 END
14996
14997 UPDATE Person.LUEthnicity
14998 SET IsDeleted =1
14999 WHERE EthnicityID = @EthnicityID
15000
15001 set @success =1;
15002 set @ErrorStatus =0;
15003 COMMIT TRANSACTION;
15004
15005 END TRY
15006
15007 BEGIN CATCH
15008 ROLLBACK TRANSACTION;
15009 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
15010 --We only care if the error was not raised by SSE
15011 IF @@ERROR <> 50000
15012 BEGIN
15013 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
15014 END
15015 SET @Success =0;
15016 SELECT @ErrorStatus= @ErrorStatus +'-60083 DELETE Fail Ethnicity';
15017 RAISERROR(@ErrorStatus, 15, 1);
15018
15019
15020 END CATCH
15021
15022 END
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036GO
15037/****** Object: StoredProcedure [Maintenance].[pHideFamilyStatusType] Script Date: 10/16/2020 7:31:03 PM ******/
15038SET ANSI_NULLS ON
15039GO
15040SET QUOTED_IDENTIFIER ON
15041GO
15042
15043
15044
15045
15046/*************************************************************************************************
15047
15048*Author: Gary Savard
15049*Date: 14 March 11
15050*Table Name: LUFamilyStatusType
15051Description: Hides LUFamilyStatusType
15052Revisions:
15053**************************************************************************************************/
15054CREATE PROCEDURE [Maintenance].[pHideFamilyStatusType](
15055 @FamilyStatusTypeID int,
15056 @Success bit Output,
15057 @ErrorStatus Nvarchar(50) Output
15058 )
15059AS
15060SET NOCOUNT ON;
15061
15062 DECLARE
15063 @TempFamilyStatusTypeID int
15064
15065 SET @FamilyStatusTypeID =0;
15066 SET @Success = 0;
15067 SET @ErrorStatus ='';
15068
15069
15070
15071 BEGIN
15072 BEGIN TRY
15073 BEGIN TRANSACTION;
15074 IF ((@FamilyStatusTypeID = 0) OR (@FamilyStatusTypeID IS NULL))
15075 BEGIN
15076 SELECT @ErrorStatus = '600015 FamilyStatusTypeID cant be 0/NULL';
15077 SET @Success = 0;
15078 RAISERROR(@ErrorStatus, 16,1);
15079 END
15080
15081
15082 SELECT @FamilyStatusTypeID =FamilySTatusTypeID
15083 FROM person.LUFamilyStatusType
15084 WHERE FamilyStatusTypeID = @FamilyStatusTypeID
15085
15086
15087 IF ((@TempFamilyStatusTypeID=0) OR (@TempFamilyStatusTypeID IS NULL))
15088 BEGIN
15089 SELECT @ErrorStatus = ' -600018 FamilySTatusTypeID does not exist';
15090 SET @Success =0;
15091 RAISERROR(@ErrorStatus,16,1);
15092 END
15093
15094 IF @@Error <> 0
15095 BEGIN
15096 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -600010';
15097 SET @Success = 0;
15098 RAISERROR(@ErrorStatus, 16, 1);
15099 END
15100
15101 UPDATE Person.LUFamilyStatusType
15102 SET IsDeleted =1
15103 WHERE FamilyStatusTypeID = @FamilyStatusTypeID
15104
15105 set @success =1;
15106 set @ErrorStatus =0;
15107 COMMIT TRANSACTION;
15108
15109 END TRY
15110
15111 BEGIN CATCH
15112 ROLLBACK TRANSACTION;
15113 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
15114 --We only care if the error was not raised by SSE
15115 IF @@ERROR <> 50000
15116 BEGIN
15117 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
15118 END
15119 SET @Success =0;
15120 SELECT @ErrorStatus= @ErrorStatus +'-600013 DELETE Fail LuFamilyStatusType';
15121 RAISERROR(@ErrorStatus, 15, 1);
15122
15123
15124 END CATCH
15125
15126 END
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142GO
15143/****** Object: StoredProcedure [Maintenance].[pHideHouseholdTransferOptions] Script Date: 10/16/2020 7:31:03 PM ******/
15144SET ANSI_NULLS ON
15145GO
15146SET QUOTED_IDENTIFIER ON
15147GO
15148
15149
15150
15151/*************************************************************************************************
15152
15153*Author: Gary Savard
15154*Date: 21 July 11
15155*Table Name: HouseholdTransferOptions
15156Description: Hides from HouseholdTransferOptions.
15157Revisions:
15158**************************************************************************************************/
15159CREATE PROCEDURE [Maintenance].[pHideHouseholdTransferOptions](
15160 @ActionToTakeID int,
15161 @Success bit Output,
15162 @ErrorStatus Nvarchar(50) Output
15163 )
15164AS
15165SET NOCOUNT ON;
15166
15167 DECLARE
15168 @TempActionToTakeID int
15169
15170 SET @TempActionToTakeID =0;
15171 SET @Success = 0;
15172 SET @ErrorStatus ='';
15173
15174
15175
15176 BEGIN
15177 BEGIN TRY
15178 BEGIN TRANSACTION;
15179 IF ((@ActionToTakeID = 0) OR (@ActionToTakeID IS NULL))
15180 BEGIN
15181 SELECT @ErrorStatus = '6015 ActionToTakeID cant be 0/NULL';
15182 SET @Success = 0;
15183 RAISERROR(@ErrorStatus, 16,1);
15184 END
15185
15186
15187 SELECT @TempActionToTakeID =@ActionToTakeID
15188 FROM dbo.LUHouseholdTransferOptions
15189 WHERE HouseholdTransferActionID= @ActionToTakeID
15190
15191
15192 IF ((@TempActionToTakeID=0) OR (@TempActionToTakeID IS NULL))
15193 BEGIN
15194 SELECT @ErrorStatus = ' -6018 ActionToTakeID does not exist';
15195 SET @Success =0;
15196 RAISERROR(@ErrorStatus,16,1);
15197 END
15198
15199 IF @@Error <> 0
15200 BEGIN
15201 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6010';
15202 SET @Success = 0;
15203 RAISERROR(@ErrorStatus, 16, 1);
15204 END
15205
15206 UPDATE dbo.LUHouseholdTransferOptions
15207 SET IsDeleted =1
15208 WHERE HouseholdTransferActionID = @TempActionToTakeID
15209
15210 set @success =1;
15211 set @ErrorStatus =0;
15212 COMMIT TRANSACTION;
15213
15214 END TRY
15215
15216 BEGIN CATCH
15217 ROLLBACK TRANSACTION;
15218 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
15219 --We only care if the error was not raised by SSE
15220 IF @@ERROR <> 50000
15221 BEGIN
15222 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
15223 END
15224 SET @Success =0;
15225 SELECT @ErrorStatus= @ErrorStatus +'-6013 DELETE Fail LUHouseholdTransferOptions';
15226 RAISERROR(@ErrorStatus, 15, 1);
15227
15228
15229 END CATCH
15230
15231 END
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246GO
15247/****** Object: StoredProcedure [Maintenance].[pHideHousingStatus] Script Date: 10/16/2020 7:31:03 PM ******/
15248SET ANSI_NULLS ON
15249GO
15250SET QUOTED_IDENTIFIER ON
15251GO
15252
15253
15254/*************************************************************************************************
15255
15256*Author: Gary Savard
15257*Date: 21 July
15258*Table Name: LUHousingStatus
15259Description: Hides LUHousingStatus
15260Revisions:
15261**************************************************************************************************/
15262CREATE PROCEDURE [Maintenance].[pHideHousingStatus](
15263 @HousingStatusID int,
15264 @Success bit Output,
15265 @ErrorStatus Nvarchar(50) Output
15266 )
15267AS
15268SET NOCOUNT ON;
15269
15270 DECLARE
15271 @TempHousingStatusID int
15272
15273 SET @TempHousingStatusID =0;
15274 SET @Success = 0;
15275 SET @ErrorStatus ='';
15276
15277
15278
15279 BEGIN
15280 BEGIN TRY
15281 BEGIN TRANSACTION;
15282 IF ((@HousingStatusID = 0) OR (@HousingStatusID IS NULL))
15283 BEGIN
15284 SELECT @ErrorStatus = '60085 HousingStatusID cant be 0/NULL';
15285 SET @Success = 0;
15286 RAISERROR(@ErrorStatus, 16,1);
15287 END
15288
15289
15290 SELECT @TempHousingStatusID =HousingStatusID
15291 FROM person.LUHousingStatus
15292 WHERE HousingStatusID= @HousingStatusID
15293
15294
15295 IF ((@TempHousingStatusID=0) OR (@TempHousingStatusID IS NULL))
15296 BEGIN
15297 SELECT @ErrorStatus = ' -60088 HousingStatusID does not exist';
15298 SET @Success =0;
15299 RAISERROR(@ErrorStatus,16,1);
15300 END
15301
15302 IF @@Error <> 0
15303 BEGIN
15304 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -60080';
15305 SET @Success = 0;
15306 RAISERROR(@ErrorStatus, 16, 1);
15307 END
15308
15309 UPDATE Person.LUHousingStatus
15310 SET IsDeleted =1
15311 WHERE HousingStatusID = @HousingStatusID
15312
15313 set @success =1;
15314 set @ErrorStatus =0;
15315 COMMIT TRANSACTION;
15316
15317 END TRY
15318
15319 BEGIN CATCH
15320 ROLLBACK TRANSACTION;
15321 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
15322 --We only care if the error was not raised by SSE
15323 IF @@ERROR <> 50000
15324 BEGIN
15325 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
15326 END
15327 SET @Success =0;
15328 SELECT @ErrorStatus= @ErrorStatus +'-60083 DELETE Fail HousingStatus';
15329 RAISERROR(@ErrorStatus, 15, 1);
15330
15331
15332 END CATCH
15333
15334 END
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348GO
15349/****** Object: StoredProcedure [Maintenance].[pHideIncomeSource] Script Date: 10/16/2020 7:31:03 PM ******/
15350SET ANSI_NULLS ON
15351GO
15352SET QUOTED_IDENTIFIER ON
15353GO
15354
15355
15356
15357
15358
15359/*************************************************************************************************
15360
15361*Author: Gary Savard
15362*Date: 21 July 11
15363*Table Name: LUIncomeSource
15364Description: Hides LUIncomeSource
15365Revisions:
15366**************************************************************************************************/
15367CREATE PROCEDURE [Maintenance].[pHideIncomeSource](
15368 @IncomeSourceID int,
15369 @Success bit Output,
15370 @ErrorStatus Nvarchar(50) Output
15371 )
15372AS
15373SET NOCOUNT ON;
15374
15375 DECLARE
15376 @TempIncomeSourceID int
15377
15378 SET @TempIncomeSourceID =0;
15379 SET @Success = 0;
15380 SET @ErrorStatus ='';
15381
15382
15383
15384 BEGIN
15385 BEGIN TRY
15386 BEGIN TRANSACTION;
15387 IF ((@IncomeSourceID = 0) OR (@IncomeSourceID IS NULL))
15388 BEGIN
15389 SELECT @ErrorStatus = '60095 IncomeSourceID cant be 0/NULL';
15390 SET @Success = 0;
15391 RAISERROR(@ErrorStatus, 16,1);
15392 END
15393
15394
15395 SELECT @TempIncomeSourceID = IncomeSourceID
15396 FROM person.LUIncomeSource
15397 WHERE IncomeSourceID = @IncomeSourceID
15398
15399
15400 IF ((@TempIncomeSourceID=0) OR (@TempIncomeSourceID IS NULL))
15401 BEGIN
15402 SELECT @ErrorStatus = ' -60098 IncomeSourceID does not exist';
15403 SET @Success =0;
15404 RAISERROR(@ErrorStatus,16,1);
15405 END
15406
15407 IF @@Error <> 0
15408 BEGIN
15409 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -2000';
15410 SET @Success = 0;
15411 RAISERROR(@ErrorStatus, 16, 1);
15412 END
15413
15414 UPDATE Person.LUIncomeSource
15415 SET IsDeleted =1
15416 WHERE IncomeSourceID = @IncomeSourceID
15417
15418 set @success =1;
15419 set @ErrorStatus =0;
15420 COMMIT TRANSACTION;
15421
15422 END TRY
15423
15424 BEGIN CATCH
15425 ROLLBACK TRANSACTION;
15426 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
15427 --We only care if the error was not raised by SSE
15428 IF @@ERROR <> 50000
15429 BEGIN
15430 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
15431 END
15432 SET @Success =0;
15433 SELECT @ErrorStatus= @ErrorStatus +'-60093 DELETE Fail IncomeSource';
15434 RAISERROR(@ErrorStatus, 15, 1);
15435
15436
15437 END CATCH
15438
15439 END
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453GO
15454/****** Object: StoredProcedure [Maintenance].[pHideInsuranceType] Script Date: 10/16/2020 7:31:03 PM ******/
15455SET ANSI_NULLS ON
15456GO
15457SET QUOTED_IDENTIFIER ON
15458GO
15459
15460
15461
15462/*************************************************************************************************
15463
15464*Author: Gary Savard
15465*Date: 21 July 11
15466*Table Name: LUInsuranceType
15467Description: Hides LUInsuranceType
15468Revisions:
15469**************************************************************************************************/
15470CREATE PROCEDURE [Maintenance].[pHideInsuranceType](
15471 @InsuranceTypeID int,
15472 @Success bit Output,
15473 @ErrorStatus Nvarchar(50) Output
15474 )
15475AS
15476SET NOCOUNT ON;
15477
15478 DECLARE
15479 @TempInsuranceTypeID int
15480
15481 SET @InsuranceTypeID =0;
15482 SET @Success = 0;
15483 SET @ErrorStatus ='';
15484
15485
15486
15487 BEGIN
15488 BEGIN TRY
15489 BEGIN TRANSACTION;
15490 IF ((@InsuranceTypeID = 0) OR (@InsuranceTypeID IS NULL))
15491 BEGIN
15492 SELECT @ErrorStatus = '600015 InsuranceTypeID cant be 0/NULL';
15493 SET @Success = 0;
15494 RAISERROR(@ErrorStatus, 16,1);
15495 END
15496
15497
15498 SELECT @InsuranceTypeID =InsuranceTypeID
15499 FROM person.LUInsuranceType
15500 WHERE InsuranceTypeID = @InsuranceTypeID
15501
15502
15503 IF ((@TempInsuranceTypeID=0) OR (@TempInsuranceTypeID IS NULL))
15504 BEGIN
15505 SELECT @ErrorStatus = ' -600018 InsuranceTypeID does not exist';
15506 SET @Success =0;
15507 RAISERROR(@ErrorStatus,16,1);
15508 END
15509
15510 IF @@Error <> 0
15511 BEGIN
15512 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -600010';
15513 SET @Success = 0;
15514 RAISERROR(@ErrorStatus, 16, 1);
15515 END
15516
15517 UPDATE Person.LUInsuranceType
15518 SET IsDeleted =1
15519 WHERE InsuranceTypeID = @InsuranceTypeID
15520
15521 set @success =1;
15522 set @ErrorStatus =0;
15523 COMMIT TRANSACTION;
15524
15525 END TRY
15526
15527 BEGIN CATCH
15528 ROLLBACK TRANSACTION;
15529 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
15530 --We only care if the error was not raised by SSE
15531 IF @@ERROR <> 50000
15532 BEGIN
15533 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
15534 END
15535 SET @Success =0;
15536 SELECT @ErrorStatus= @ErrorStatus +'-600013 DELETE Fail LuInsuranceType';
15537 RAISERROR(@ErrorStatus, 15, 1);
15538
15539
15540 END CATCH
15541
15542 END
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557GO
15558/****** Object: StoredProcedure [Maintenance].[pHideLanguage] Script Date: 10/16/2020 7:31:03 PM ******/
15559SET ANSI_NULLS ON
15560GO
15561SET QUOTED_IDENTIFIER ON
15562GO
15563
15564
15565/*************************************************************************************************
15566
15567*Author: Gary Savard
15568*Date:21 July 11
15569*Table Name: LULanguage
15570Description: Deletes from LULanguage
15571Revisions:
15572**************************************************************************************************/
15573CREATE PROCEDURE [Maintenance].[pHideLanguage](
15574 @LanguageID int,
15575 @Success bit Output,
15576 @ErrorStatus Nvarchar(50) Output
15577 )
15578AS
15579SET NOCOUNT ON;
15580
15581 DECLARE
15582 @TempLanguageID int
15583
15584 SET @TempLanguageID =0;
15585 SET @Success = 0;
15586 SET @ErrorStatus ='';
15587
15588
15589
15590 BEGIN
15591 BEGIN TRY
15592 BEGIN TRANSACTION;
15593 IF ((@LanguageID = 0) OR (@LanguageID IS NULL))
15594 BEGIN
15595 SELECT @ErrorStatus = '60065 LanguageID cant be 0/NULL';
15596 SET @Success = 0;
15597 RAISERROR(@ErrorStatus, 16,1);
15598 END
15599
15600
15601 SELECT @TempLanguageID = LanguageID
15602 FROM person.LULanguage
15603 WHERE LanguageID = @LanguageID
15604
15605
15606 IF ((@TempLanguageID=0) OR (@TempLanguageID IS NULL))
15607 BEGIN
15608 SELECT @ErrorStatus = ' -60068 LanguageID does not exist';
15609 SET @Success =0;
15610 RAISERROR(@ErrorStatus,16,1);
15611 END
15612
15613 IF @@Error <> 0
15614 BEGIN
15615 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -60000';
15616 SET @Success = 0;
15617 RAISERROR(@ErrorStatus, 16, 1);
15618 END
15619
15620 UPDATE Person.LULanguage
15621 SET IsDeleted =1
15622 WHERE LanguageID = @LanguageID
15623
15624 set @success =1;
15625 set @ErrorStatus =0;
15626 COMMIT TRANSACTION;
15627
15628 END TRY
15629
15630 BEGIN CATCH
15631 ROLLBACK TRANSACTION;
15632 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
15633 --We only care if the error was not raised by SSE
15634 IF @@ERROR <> 50000
15635 BEGIN
15636 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
15637 END
15638 SET @Success =0;
15639 SELECT @ErrorStatus= @ErrorStatus +'-60063 DELETE Fail Language';
15640 RAISERROR(@ErrorStatus, 15, 1);
15641
15642
15643 END CATCH
15644
15645 END
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659GO
15660/****** Object: StoredProcedure [Maintenance].[pHideLUFamilyRelationship] Script Date: 10/16/2020 7:31:03 PM ******/
15661SET ANSI_NULLS ON
15662GO
15663SET QUOTED_IDENTIFIER ON
15664GO
15665
15666
15667/*************************************************************************************************
15668
15669*Author: Gary Savard
15670*Date: 21 July 11
15671*Table Name: LUFamilyRelationship
15672Description: Hide LUFamilyRelationship
15673Revisions:
15674**************************************************************************************************/
15675CREATE PROCEDURE [Maintenance].[pHideLUFamilyRelationship](
15676 @FamilyRelationshipID int,
15677 @Success bit Output,
15678 @ErrorStatus Nvarchar(50) Output
15679 )
15680AS
15681SET NOCOUNT ON;
15682
15683 DECLARE
15684 @TempFamilyRelationshipID int
15685
15686 SET @TempFamilyRelationshipID =0;
15687 SET @Success = 0;
15688 SET @ErrorStatus ='';
15689
15690
15691
15692 BEGIN
15693 BEGIN TRY
15694 BEGIN TRANSACTION;
15695 IF ((@FamilyRelationshipID = 0) OR (@FamilyRelationshipID IS NULL))
15696 BEGIN
15697 SELECT @ErrorStatus = '60045 FamilyRelationshipID cant be 0/NULL';
15698 SET @Success = 0;
15699 RAISERROR(@ErrorStatus, 16,1);
15700 END
15701
15702
15703 SELECT @TempFamilyRelationshipID =FamilyRelationshipID
15704 FROM person.LUFamilyRelationship
15705 WHERE FamilyRelationshipID= @FamilyRelationshipID
15706
15707
15708 IF ((@TempFamilyRelationshipID=0) OR (@TempFamilyRelationshipID IS NULL))
15709 BEGIN
15710 SELECT @ErrorStatus = ' -60048 FamilyRelationshipID does not exist';
15711 SET @Success =0;
15712 RAISERROR(@ErrorStatus,16,1);
15713 END
15714
15715 IF @@Error <> 0
15716 BEGIN
15717 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -60040';
15718 SET @Success = 0;
15719 RAISERROR(@ErrorStatus, 16, 1);
15720 END
15721
15722 UPDATE Person.LUFamilyRelationship
15723 SET IsDeleted =1
15724 WHERE FamilyRelationshipID = @FamilyRelationshipID
15725
15726 set @success =1;
15727 set @ErrorStatus =0;
15728 COMMIT TRANSACTION;
15729
15730 END TRY
15731
15732 BEGIN CATCH
15733 ROLLBACK TRANSACTION;
15734 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
15735 --We only care if the error was not raised by SSE
15736 IF @@ERROR <> 50000
15737 BEGIN
15738 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
15739 END
15740 SET @Success =0;
15741 SELECT @ErrorStatus= @ErrorStatus +'-60043 DELETE Fail FamilyRelationship';
15742 RAISERROR(@ErrorStatus, 15, 1);
15743
15744
15745 END CATCH
15746
15747 END
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761GO
15762/****** Object: StoredProcedure [Maintenance].[pHidePersonType] Script Date: 10/16/2020 7:31:03 PM ******/
15763SET ANSI_NULLS ON
15764GO
15765SET QUOTED_IDENTIFIER ON
15766GO
15767
15768
15769/*************************************************************************************************
15770
15771*Author: Gary Savard
15772*Date: 8 Oct 10
15773*Table Name: LUPersonType
15774Description: Hides LUPersonType
15775Revisions:
15776**************************************************************************************************/
15777CREATE PROCEDURE [Maintenance].[pHidePersonType](
15778 @PersonTypeID int,
15779 @Success bit Output,
15780 @ErrorStatus Nvarchar(50) Output
15781 )
15782AS
15783SET NOCOUNT ON;
15784
15785 DECLARE
15786 @TempPersonTypeID int
15787
15788 SET @TempPersonTypeID =0;
15789 SET @Success = 0;
15790 SET @ErrorStatus ='';
15791
15792
15793
15794 BEGIN
15795 BEGIN TRY
15796 BEGIN TRANSACTION;
15797 IF ((@PersonTypeID = 0) OR (@PersonTypeID IS NULL))
15798 BEGIN
15799 SELECT @ErrorStatus = '600015 PersonTypeID cant be 0/NULL';
15800 SET @Success = 0;
15801 RAISERROR(@ErrorStatus, 16,1);
15802 END
15803
15804
15805 SELECT @TempPersonTypeID =PersonTypeID
15806 FROM person.LUPersonType
15807 WHERE PersonTypeID = @PersonTypeID
15808
15809
15810 IF ((@TempPersonTypeID=0) OR (@TempPersonTypeID IS NULL))
15811 BEGIN
15812 SELECT @ErrorStatus = ' -600018 PersonTypeID does not exist';
15813 SET @Success =0;
15814 RAISERROR(@ErrorStatus,16,1);
15815 END
15816
15817 IF @@Error <> 0
15818 BEGIN
15819 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -600010';
15820 SET @Success = 0;
15821 RAISERROR(@ErrorStatus, 16, 1);
15822 END
15823
15824 UPDATE Person.LUPersonType
15825 SET IsDeleted =1
15826 WHERE PersonTypeID = @PersonTypeID
15827
15828 set @success =1;
15829 set @ErrorStatus =0;
15830 COMMIT TRANSACTION;
15831
15832 END TRY
15833
15834 BEGIN CATCH
15835 ROLLBACK TRANSACTION;
15836 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
15837 --We only care if the error was not raised by SSE
15838 IF @@ERROR <> 50000
15839 BEGIN
15840 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
15841 END
15842 SET @Success =0;
15843 SELECT @ErrorStatus= @ErrorStatus +'-600013 DELETE Fail PersonType';
15844 RAISERROR(@ErrorStatus, 15, 1);
15845
15846
15847 END CATCH
15848
15849 END
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863GO
15864/****** Object: StoredProcedure [Maintenance].[pHidePhoneType] Script Date: 10/16/2020 7:31:03 PM ******/
15865SET ANSI_NULLS ON
15866GO
15867SET QUOTED_IDENTIFIER ON
15868GO
15869
15870
15871
15872/*************************************************************************************************
15873
15874*Author: Gary Savard
15875*Date: 8 Oct 10
15876*Table Name: LUPhoneType
15877Description: HideLUPhoneType
15878Revisions:
15879**************************************************************************************************/
15880CREATE PROCEDURE [Maintenance].[pHidePhoneType](
15881 @PhoneTypeID int,
15882 @Success bit Output,
15883 @ErrorStatus Nvarchar(50) Output
15884 )
15885AS
15886SET NOCOUNT ON;
15887
15888 DECLARE
15889 @TempPhoneTypeID int
15890
15891 SET @TempPhoneTypeID =0;
15892 SET @Success = 0;
15893 SET @ErrorStatus ='';
15894
15895
15896
15897 BEGIN
15898 BEGIN TRY
15899 BEGIN TRANSACTION;
15900 IF ((@PhoneTypeID = 0) OR (@PhoneTypeID IS NULL))
15901 BEGIN
15902 SELECT @ErrorStatus = '600085 PhoneTypeID cant be 0/NULL';
15903 SET @Success = 0;
15904 RAISERROR(@ErrorStatus, 16,1);
15905 END
15906
15907
15908 SELECT @TempPhoneTypeID =PhoneTypeID
15909 FROM person.LUPhoneType
15910 WHERE PhoneTypeID = @PhoneTypeID
15911
15912
15913 IF ((@TempPhoneTypeID=0) OR (@TempPhoneTypeID IS NULL))
15914 BEGIN
15915 SELECT @ErrorStatus = ' -600088 PhoneTypeID does not exist';
15916 SET @Success =0;
15917 RAISERROR(@ErrorStatus,16,1);
15918 END
15919
15920 IF @@Error <> 0
15921 BEGIN
15922 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -600080';
15923 SET @Success = 0;
15924 RAISERROR(@ErrorStatus, 16, 1);
15925 END
15926
15927 UPDATE Person.LUPhoneType
15928 SET IsDeleted =1
15929 WHERE PhoneTypeID = @PhoneTypeID
15930
15931 set @success =1;
15932 set @ErrorStatus =0;
15933 COMMIT TRANSACTION;
15934
15935 END TRY
15936
15937 BEGIN CATCH
15938 ROLLBACK TRANSACTION;
15939 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
15940 --We only care if the error was not raised by SSE
15941 IF @@ERROR <> 50000
15942 BEGIN
15943 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
15944 END
15945 SET @Success =0;
15946 SELECT @ErrorStatus= @ErrorStatus +'-600083 DELETE Fail PhoneType';
15947 RAISERROR(@ErrorStatus, 15, 1);
15948
15949
15950 END CATCH
15951
15952 END
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967GO
15968/****** Object: StoredProcedure [Maintenance].[pHidePostalCode] Script Date: 10/16/2020 7:31:03 PM ******/
15969SET ANSI_NULLS ON
15970GO
15971SET QUOTED_IDENTIFIER ON
15972GO
15973
15974
15975/*************************************************************************************************
15976
15977*Author: Gary Savard
15978*Date: 21 July 11
15979*Table Name: LUPostalCode
15980Description: Hides LUPostalCode
15981Revisions:
15982**************************************************************************************************/
15983CREATE PROCEDURE [Maintenance].[pHidePostalCode](
15984 @PostalCodeID int,
15985 @Success bit Output,
15986 @ErrorStatus Nvarchar(50) Output
15987 )
15988AS
15989SET NOCOUNT ON;
15990
15991 DECLARE
15992 @TempPostalCodeID int
15993
15994 SET @TempPostalCodeID =0;
15995 SET @Success = 0;
15996 SET @ErrorStatus ='';
15997
15998
15999
16000 BEGIN
16001 BEGIN TRY
16002 BEGIN TRANSACTION;
16003 IF ((@PostalCodeID = 0) OR (@PostalCodeID IS NULL))
16004 BEGIN
16005 SELECT @ErrorStatus = '6075 PostalCodeID cant be 0/NULL';
16006 SET @Success = 0;
16007 RAISERROR(@ErrorStatus, 16,1);
16008 END
16009
16010
16011 SELECT @TempPostalCodeID =PostalCodeID
16012 FROM person.LUPostalCode
16013 WHERE PostalCodeID= @PostalCodeID
16014
16015
16016 IF ((@TempPostalCodeID=0) OR (@TempPostalCodeID IS NULL))
16017 BEGIN
16018 SELECT @ErrorStatus = ' -6078 PostalCodeID does not exist';
16019 SET @Success =0;
16020 RAISERROR(@ErrorStatus,16,1);
16021 END
16022
16023 IF @@Error <> 0
16024 BEGIN
16025 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6070';
16026 SET @Success = 0;
16027 RAISERROR(@ErrorStatus, 16, 1);
16028 END
16029
16030 UPDATE Person.LUPostalCode
16031 SET IsDeleted =1
16032 WHERE PostalCodeID = @PostalCodeID
16033
16034 set @success =1;
16035 set @ErrorStatus =0;
16036 COMMIT TRANSACTION;
16037
16038 END TRY
16039
16040 BEGIN CATCH
16041 ROLLBACK TRANSACTION;
16042 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
16043 --We only care if the error was not raised by SSE
16044 IF @@ERROR <> 50000
16045 BEGIN
16046 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
16047 END
16048 SET @Success =0;
16049 SELECT @ErrorStatus= @ErrorStatus +'-6073 DELETE Fail PostalCode';
16050 RAISERROR(@ErrorStatus, 15, 1);
16051
16052
16053 END CATCH
16054
16055 END
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069GO
16070/****** Object: StoredProcedure [Maintenance].[pHideProgramServiceType] Script Date: 10/16/2020 7:31:03 PM ******/
16071SET ANSI_NULLS ON
16072GO
16073SET QUOTED_IDENTIFIER ON
16074GO
16075
16076
16077/*************************************************************************************************
16078
16079*Author: Gary Savard
16080*Date: 8 Oct 10
16081*Table Name: LUProgramServiceType
16082Description: Hides LUProgramServiceType
16083Revisions:
16084**************************************************************************************************/
16085CREATE PROCEDURE [Maintenance].[pHideProgramServiceType](
16086 @ProgramServiceTypeID int,
16087 @Success bit Output,
16088 @ErrorStatus Nvarchar(50) Output
16089 )
16090AS
16091SET NOCOUNT ON;
16092
16093 DECLARE
16094 @TempProgramServiceTypeID int
16095
16096 SET @TempProgramServiceTypeID =0;
16097 SET @Success = 0;
16098 SET @ErrorStatus ='';
16099
16100
16101
16102 BEGIN
16103 BEGIN TRY
16104 BEGIN TRANSACTION;
16105 IF ((@ProgramServiceTypeID = 0) OR (@ProgramServiceTypeID IS NULL))
16106 BEGIN
16107 SELECT @ErrorStatus = '6055 ProgramServiceTypeID cant be 0/NULL';
16108 SET @Success = 0;
16109 RAISERROR(@ErrorStatus, 16,1);
16110 END
16111
16112
16113 SELECT @TempProgramServiceTypeID =ProgramServiceTypeID
16114 FROM person.LUProgramServiceType
16115 WHERE ProgramServiceTypeID= @ProgramServiceTypeID
16116
16117
16118 IF ((@TempProgramServiceTypeID=0) OR (@TempProgramServiceTypeID IS NULL))
16119 BEGIN
16120 SELECT @ErrorStatus = ' -6058 ProgramServiceTypeID does not exist';
16121 SET @Success =0;
16122 RAISERROR(@ErrorStatus,16,1);
16123 END
16124
16125 IF @@Error <> 0
16126 BEGIN
16127 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6050';
16128 SET @Success = 0;
16129 RAISERROR(@ErrorStatus, 16, 1);
16130 END
16131
16132 UPDATE Person.LUProgramServiceType
16133 SET IsDeleted =1
16134 WHERE ProgramServiceTypeID = @ProgramServiceTypeID
16135
16136 set @success =1;
16137 set @ErrorStatus =0;
16138 COMMIT TRANSACTION;
16139
16140 END TRY
16141
16142 BEGIN CATCH
16143 ROLLBACK TRANSACTION;
16144 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
16145 --We only care if the error was not raised by SSE
16146 IF @@ERROR <> 50000
16147 BEGIN
16148 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
16149 END
16150 SET @Success =0;
16151 SELECT @ErrorStatus= @ErrorStatus +'-6053 DELETE Fail ProgramServiceType';
16152 RAISERROR(@ErrorStatus, 15, 1);
16153
16154
16155 END CATCH
16156
16157 END
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171GO
16172/****** Object: StoredProcedure [Maintenance].[pHideProgramType] Script Date: 10/16/2020 7:31:03 PM ******/
16173SET ANSI_NULLS ON
16174GO
16175SET QUOTED_IDENTIFIER ON
16176GO
16177
16178
16179/*************************************************************************************************
16180
16181*Author: Gary Savard
16182*Date: 21 July 11
16183*Table Name: LUProgramType
16184Description: Hides LUProgramType
16185Revisions:
16186**************************************************************************************************/
16187CREATE PROCEDURE [Maintenance].[pHideProgramType](
16188 @ProgramTypeID int,
16189 @Success bit Output,
16190 @ErrorStatus Nvarchar(50) Output
16191 )
16192AS
16193SET NOCOUNT ON;
16194
16195 DECLARE
16196 @TempProgramTypeID int
16197
16198 SET @TempProgramTypeID =0;
16199 SET @Success = 0;
16200 SET @ErrorStatus ='';
16201
16202
16203
16204 BEGIN
16205 BEGIN TRY
16206 BEGIN TRANSACTION;
16207 IF ((@ProgramTypeID = 0) OR (@ProgramTypeID IS NULL))
16208 BEGIN
16209 SELECT @ErrorStatus = '6045 ProgramTypeID cant be 0/NULL';
16210 SET @Success = 0;
16211 RAISERROR(@ErrorStatus, 16,1);
16212 END
16213
16214
16215 SELECT @TempProgramTypeID =ProgramTypeID
16216 FROM person.LUProgramType
16217 WHERE ProgramTypeID= @ProgramTypeID
16218
16219
16220 IF ((@TempProgramTypeID=0) OR (@TempProgramTypeID IS NULL))
16221 BEGIN
16222 SELECT @ErrorStatus = ' -6048 ProgramTypeID does not exist';
16223 SET @Success =0;
16224 RAISERROR(@ErrorStatus,16,1);
16225 END
16226
16227 IF @@Error <> 0
16228 BEGIN
16229 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6040';
16230 SET @Success = 0;
16231 RAISERROR(@ErrorStatus, 16, 1);
16232 END
16233
16234 UPDATE Person.LUProgramType
16235 SET IsDeleted =1
16236 WHERE ProgramTypeID = @ProgramTypeID
16237
16238 set @success =1;
16239 set @ErrorStatus =0;
16240 COMMIT TRANSACTION;
16241
16242 END TRY
16243
16244 BEGIN CATCH
16245 ROLLBACK TRANSACTION;
16246 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
16247 --We only care if the error was not raised by SSE
16248 IF @@ERROR <> 50000
16249 BEGIN
16250 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
16251 END
16252 SET @Success =0;
16253 SELECT @ErrorStatus= @ErrorStatus +'-6043 DELETE Fail PostalCode';
16254 RAISERROR(@ErrorStatus, 15, 1);
16255
16256
16257 END CATCH
16258
16259 END
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273GO
16274/****** Object: StoredProcedure [Maintenance].[pHideRace] Script Date: 10/16/2020 7:31:03 PM ******/
16275SET ANSI_NULLS ON
16276GO
16277SET QUOTED_IDENTIFIER ON
16278GO
16279
16280
16281/*************************************************************************************************
16282
16283*Author: Gary Savard
16284*Date: 8 Oct 10
16285*Table Name: LURace
16286Description: Hides LURace
16287Revisions:
16288**************************************************************************************************/
16289CREATE PROCEDURE [Maintenance].[pHideRace](
16290 @RaceID int,
16291 @Success bit Output,
16292 @ErrorStatus Nvarchar(50) Output
16293 )
16294AS
16295SET NOCOUNT ON;
16296
16297 DECLARE
16298 @TempRaceID int
16299
16300 SET @TempRaceID =0;
16301 SET @Success = 0;
16302 SET @ErrorStatus ='';
16303
16304
16305
16306 BEGIN
16307 BEGIN TRY
16308 BEGIN TRANSACTION;
16309 IF ((@RaceID = 0) OR (@RaceID IS NULL))
16310 BEGIN
16311 SELECT @ErrorStatus = '6025 RaceID cant be 0/NULL';
16312 SET @Success = 0;
16313 RAISERROR(@ErrorStatus, 16,1);
16314 END
16315
16316
16317 SELECT @TempRaceID =RaceID
16318 FROM person.LURace
16319 WHERE RaceID= @RaceID
16320
16321
16322 IF ((@TempRaceID=0) OR (@TempRaceID IS NULL))
16323 BEGIN
16324 SELECT @ErrorStatus = ' -6028 RaceID does not exist';
16325 SET @Success =0;
16326 RAISERROR(@ErrorStatus,16,1);
16327 END
16328
16329 IF @@Error <> 0
16330 BEGIN
16331 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6020';
16332 SET @Success = 0;
16333 RAISERROR(@ErrorStatus, 16, 1);
16334 END
16335
16336 UPDATE Person.LURace
16337 SET IsDeleted =1
16338 WHERE RaceID = @RaceID
16339
16340 set @success =1;
16341 set @ErrorStatus =0;
16342 COMMIT TRANSACTION;
16343
16344 END TRY
16345
16346 BEGIN CATCH
16347 ROLLBACK TRANSACTION;
16348 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
16349 --We only care if the error was not raised by SSE
16350 IF @@ERROR <> 50000
16351 BEGIN
16352 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
16353 END
16354 SET @Success =0;
16355 SELECT @ErrorStatus= @ErrorStatus +'-6023 DELETE Fail Race';
16356 RAISERROR(@ErrorStatus, 15, 1);
16357
16358
16359 END CATCH
16360
16361 END
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375GO
16376/****** Object: StoredProcedure [Maintenance].[pHideState] Script Date: 10/16/2020 7:31:03 PM ******/
16377SET ANSI_NULLS ON
16378GO
16379SET QUOTED_IDENTIFIER ON
16380GO
16381
16382
16383/*************************************************************************************************
16384
16385*Author: Gary Savard
16386*Date: 8 Oct 10
16387*Table Name: LUState
16388Description: Hides LUState
16389Revisions:
16390**************************************************************************************************/
16391CREATE PROCEDURE [Maintenance].[pHideState](
16392 @StateID int,
16393 @Success bit Output,
16394 @ErrorStatus Nvarchar(50) Output
16395 )
16396AS
16397SET NOCOUNT ON;
16398
16399 DECLARE
16400 @TempStateID int
16401
16402 SET @TempStateID =0;
16403 SET @Success = 0;
16404 SET @ErrorStatus ='';
16405
16406
16407
16408 BEGIN
16409 BEGIN TRY
16410 BEGIN TRANSACTION;
16411 IF ((@StateID = 0) OR (@StateID IS NULL))
16412 BEGIN
16413 SELECT @ErrorStatus = '6035 StateID cant be 0/NULL';
16414 SET @Success = 0;
16415 RAISERROR(@ErrorStatus, 16,1);
16416 END
16417
16418
16419 SELECT @TempStateID =StateID
16420 FROM person.LUState
16421 WHERE StateID= @StateID
16422
16423
16424 IF ((@TempStateID=0) OR (@TempStateID IS NULL))
16425 BEGIN
16426 SELECT @ErrorStatus = ' -6038 StateID does not exist';
16427 SET @Success =0;
16428 RAISERROR(@ErrorStatus,16,1);
16429 END
16430
16431 IF @@Error <> 0
16432 BEGIN
16433 SELECT @ErrorStatus = CONVERT(nVarchar(50),@@ERROR) + ' -6030';
16434 SET @Success = 0;
16435 RAISERROR(@ErrorStatus, 16, 1);
16436 END
16437
16438 UPDATE Person.LUState
16439 SET IsDeleted =1
16440 WHERE StateID = @StateID
16441
16442 set @success =1;
16443 set @ErrorStatus =0;
16444 COMMIT TRANSACTION;
16445
16446 END TRY
16447
16448 BEGIN CATCH
16449 ROLLBACK TRANSACTION;
16450 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
16451 --We only care if the error was not raised by SSE
16452 IF @@ERROR <> 50000
16453 BEGIN
16454 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
16455 END
16456 SET @Success =0;
16457 SELECT @ErrorStatus= @ErrorStatus +'-6033 DELETE Fail State';
16458 RAISERROR(@ErrorStatus, 15, 1);
16459
16460
16461 END CATCH
16462
16463 END
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477GO
16478/****** Object: StoredProcedure [Maintenance].[pMakeFamilyMemberClientinSameHousehold] Script Date: 10/16/2020 7:31:03 PM ******/
16479SET ANSI_NULLS ON
16480GO
16481SET QUOTED_IDENTIFIER ON
16482GO
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492/*************************************************************************************************
16493*
16494*Author: Gary Savard
16495*Date: 15 April 2011
16496*
16497Description: This SP covers the instances where a family member replaces the current client and becomes the client.
16498*We handle the client by either deleting (supressing) from the system, moving the client to another household, creating
16499*another household or by 'demoting' the client to family member.
16500Revisions:
16501**************************************************************************************************/
16502CREATE PROCEDURE [Maintenance].[pMakeFamilyMemberClientinSameHousehold](
16503 @ClientPersonID int,
16504 @PromoteToClientPersonID int,
16505 @ActionToTake nVarchar(10),
16506 @NewPersonID int Output,
16507 @Success bit Output,
16508 @ErrorStatus Nvarchar(50) Output
16509 )
16510AS
16511SET NOCOUNT ON;
16512BEGIN
16513 DECLARE
16514 @TempPersonID int,
16515 @PersonID int;
16516
16517 SET @TempPersonID =0;
16518 SET @Success = 0;
16519 SET @ErrorStatus ='';
16520 SET @TempPersonID =0;
16521
16522
16523
16524BEGIN TRY
16525 BEGIN TRANSACTION;
16526 --Make sure that the @ActionToTake value is valid. If not, bail!
16527
16528 -- Check the @PromoteToClientPersonID to ensure that the person to be promoted is associated with the current client.
16529 --If Not Valid, Bail
16530 --Else
16531 --all of the household member IDs from the FamilyRelationship table so that we can update the ClientPersonID to that of the new client.
16532 --Change the Family status of the new client to reflect that they are no longer child, spouse, etc, of the client
16533
16534
16535 --If this works, then we will deal with the old client.
16536
16537 --"DEMOTE" If the old client is to become a member of the same household
16538 --We add them to the FamilyRelationship table and give them a FamilyMember entry
16539
16540 --If they are part of a new household, then we update any records in the familyRelationship table that has their ID and
16541 --Remove any from the FamilyRelationship status as appropriate
16542
16543 --"DELETE" We remove the client by setting the IsDeleted bit in the person table. We keep them in the system,but
16544 --they are no longer visible from a query.
16545
16546 --"NEWHOUSEHOLD" -- We create a new household and return the new household ID. May not even need to do that because we are
16547 --really just removing their association with the current client. When the move is finished. The person inputting data will have
16548 --to query on the new record and create the appropriate household members.
16549
16550
16551 /******************************************************************************************************
16552
16553
16554
16555 *******************************************************************************************************/
16556 COMMIT TRANSACTION;
16557
16558 END TRY
16559
16560 BEGIN CATCH
16561 ROLLBACK TRANSACTION;
16562 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
16563 --We only care if the error was not raised by SSE
16564 IF @@ERROR <> 50000
16565 BEGIN
16566 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
16567 END
16568 SET @Success =0;
16569 SET @ErrorStatus= @ErrorStatus + '-1001';
16570 RAISERROR(@ErrorStatus, 15, 1);
16571
16572
16573 END CATCH
16574
16575 END
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587GO
16588/****** Object: StoredProcedure [Maintenance].[pMoveFamilyMemberToAnotherHousehold] Script Date: 10/16/2020 7:31:03 PM ******/
16589SET ANSI_NULLS ON
16590GO
16591SET QUOTED_IDENTIFIER ON
16592GO
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603/*************************************************************************************************
16604*
16605*Author: Gary Savard
16606*Date: 15 April 2011
16607*
16608Description: This SP covers the instances where a family member moves to a new household. It assumes that if the
16609person is the head of the old household, that another person has been promoted to head of that household already
16610**************************************************************************************************/
16611CREATE PROCEDURE [Maintenance].[pMoveFamilyMemberToAnotherHousehold](
16612 @OldHouseholdClientPersonID int, -- The old client that the person moving is associated with.
16613 @NewHouseholdClientPersonID int,--Person moving to new household
16614 @ToNewHouseholdPersonID int,--The person who going to new household
16615 @NewFamilyStatusType NVarchar(50) = NULL,--This may or may not be used.
16616 @NewFamilyRelationshipID int =0, --May or may not be used.
16617 @NewFamilyRelationshipDescription NVarchar(50)=NULL, --This may or may not be used
16618 @ModifiedBy Name,
16619 @Success bit Output,
16620 @ErrorStatus Nvarchar(50) Output
16621 )
16622AS
16623SET NOCOUNT ON;
16624BEGIN
16625 DECLARE
16626 @ErrNo int
16627
16628
16629 SET @Success = 0;
16630 SET @ErrorStatus ='';
16631 SET @ErrNo =0;
16632
16633
16634
16635BEGIN TRY
16636 BEGIN TRANSACTION;
16637 --Place a record in the Journal Table with the appropriate information before making the change.
16638 --Update the Relationship table with the new household's client ID and the new relationship
16639 --Make update to demographics table for new family status.
16640
16641 EXEC dbo.pInsertJournalClientFamilyChanges @ToNewHouseholdPersonID,
16642 @OldHouseholdClientPersonID,
16643 @NewHouseholdClientPersonId,
16644 'Moved to new household',
16645 @NewFamilyRelationshipDescription,
16646 @ModifiedBy
16647
16648
16649 --Move to new household
16650 INSERT Person.FamilyRelationships(PersonID,ClientPersonID,RelationshipID,RelationDescription,ModifiedDate,ModifiedBy)
16651 VALUES
16652 (@ToNewHouseholdPersonID,@NewHouseholdClientPersonID,@NewFamilyRelationshipID,@NewFamilyRelationshipDescription,SYSDATETIME(),@ModifiedBy)
16653 --Remove from old Household
16654 SELECT @ErrNo =@@ERROR
16655
16656 IF @ErrNo<>0
16657 BEGIN
16658 SET @ErrorStatus ='Failed Insert Move to new household'
16659 RAISERROR(@ErrorStatus,16,0)
16660
16661 END
16662
16663 DELETE FROM person.FamilyRelationships
16664 WHERE PersonID = @ToNewHouseholdPersonID AND ClientPersonID=@OldHouseholdClientPersonID
16665
16666 IF @ErrNo<>0
16667 BEGIN
16668 SET @ErrorStatus ='Failed Delete Move to new household'
16669 RAISERROR(@ErrorStatus,16,0)
16670 END
16671
16672 /******************************************************************************************************
16673
16674
16675
16676 *******************************************************************************************************/
16677 COMMIT TRANSACTION;
16678
16679 END TRY
16680
16681 BEGIN CATCH
16682 ROLLBACK TRANSACTION;
16683 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
16684 --We only care if the error was not raised by SSE
16685 IF @@ERROR <> 50000
16686 BEGIN
16687 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @ErrNo);
16688 END
16689 SET @Success =0;
16690 SET @ErrorStatus= @ErrorStatus + '-1001';
16691 RAISERROR(@ErrorStatus, 15, 1);
16692
16693
16694 END CATCH
16695
16696 END
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709GO
16710/****** Object: StoredProcedure [Maintenance].[pRestoreClientRecord] Script Date: 10/16/2020 7:31:03 PM ******/
16711SET ANSI_NULLS ON
16712GO
16713SET QUOTED_IDENTIFIER ON
16714GO
16715
16716
16717
16718
16719
16720/*************************************************************************************************
16721*
16722*Author: Gary Savard
16723*Date: 15 April 2011
16724*
16725Description: This SP covers the instances where a deleted person needs to be restored to the database. We just flip the IsDeleted bit.
16726**************************************************************************************************/
16727CREATE PROCEDURE [Maintenance].[pRestoreClientRecord](
16728 @tRestorePersonID BatchProcessPersonID READONLY,--The person/Household,
16729 @ModifiedBy Name,
16730 @Success bit Output,
16731 @ErrorStatus Nvarchar(50) Output
16732 )
16733AS
16734SET NOCOUNT ON;
16735
16736 DECLARE
16737 @ErrNo INT,
16738 @LogMsg NVarchar(50),
16739 @journalSuccess BIT,
16740 @JournalErrorStatus NVarchar(50),
16741 @ErrorCount int,
16742 @Notes NVarchar(50)
16743
16744
16745 SET @Success = 0;
16746 SET @ErrorStatus ='';
16747 SET @ErrNo =0;
16748 SET @LogMsg ='Restored client record. ';
16749 SET @ErrorCount =0;
16750
16751
16752BEGIN TRY
16753 DECLARE
16754 @RowCount int,
16755 @NumberRecs int,
16756 @tmpPersonID int,
16757 @tmpClientPersonID int
16758
16759
16760 SET @RowCount =1
16761
16762
16763
16764 SELECT @NumberRecs = COUNT(*) FROM @tRestorePersonID --How many records?
16765
16766
16767 WHILE @RowCount <=@NumberRecs
16768 BEGIN
16769 BEGIN TRANSACTION;--TX for each individual record
16770
16771 SET @Notes =''
16772
16773 SELECT @tmpPersonID =PersonID
16774 FROM @tRestorePersonID
16775 WHERE RowID =@Rowcount
16776
16777 UPDATE Person.Person
16778 SET IsDeleted =0
16779 WHERE PersonID =@TmpPersonID
16780
16781 SELECT @ErrNo =@@ERROR
16782
16783 SET @RowCount = @RowCount + 1
16784
16785 IF @ErrNo<>0 OR @@ROWCOUNT =0
16786 BEGIN
16787 SET @ErrorCount = @ErrorCount +1
16788 SET @ErrorStatus ='Fail RestoreID: ' + CONVERT(NVarchar(50),@TmpPersonID)+','
16789 SET @Notes ='Failed restore PersonID' + CONVERT(NVarchar(50),@TmpPersonID)
16790
16791 ROLLBACK TRANSACTION --Rollback only the one that failed!
16792 END--IF@ErrNO
16793
16794 IF @@TRANCOUNT >0
16795 BEGIN
16796 COMMIT TRANSACTION
16797 SET @Notes ='Restored PersonID: '+ CONVERT(NVarchar(50),@TmpPersonID)
16798 END
16799
16800
16801 --Place a record in the Journal Table with the appropriate information before making the change.
16802 EXEC dbo.pInsertJournalClientFamilyChanges @TmpPersonID,
16803 0,--@HeadofHouseholdPersonID not needed
16804 0,--@NewHeadOfHouseholdPersonID
16805 @LogMsg,
16806 @Notes,
16807 @ModifiedBy,
16808 @JournalSuccess,--we don't care about the return values of this and error status for time being
16809 @JournalErrorStatus
16810 END --End While
16811
16812
16813 IF @ErrorCount >0--This goes to the error trap for recording those that failed, but we do not rollback in the error trap.
16814 BEGIN
16815 RAISERROR(@ErrorStatus,16,0)
16816 END
16817
16818
16819
16820
16821
16822 /******************************************************************************************************
16823
16824
16825
16826 *******************************************************************************************************/
16827
16828
16829 END TRY
16830
16831 BEGIN CATCH
16832 --We do not rollback here
16833 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
16834 --We only care if the error was not raised by SSE
16835 IF @@ERROR <> 50000
16836 BEGIN
16837 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @ErrNo);
16838 END
16839 SET @Success =0;
16840 SET @ErrorStatus= @ErrorStatus + '-1001';
16841 RAISERROR(@ErrorStatus, 15, 1);
16842
16843
16844 END CATCH
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863GO
16864/****** Object: StoredProcedure [Maintenance].[pRetrieveClientRecords] Script Date: 10/16/2020 7:31:03 PM ******/
16865SET ANSI_NULLS ON
16866GO
16867SET QUOTED_IDENTIFIER ON
16868GO
16869
16870
16871
16872
16873/*************************************************************************************************
16874
16875*Author: Gary Savard
16876*Date: 11 Jun 11
16877
16878Description: Returns the names DOB of queried records
16879Revisions:
16880**************************************************************************************************/
16881CREATE PROCEDURE [Maintenance].[pRetrieveClientRecords](
16882 @IsDeleted bit,
16883 @IsSoundsLike bit,
16884 @FirstName Name,--if complete query for all deleted, then we don't need names or dob
16885 @LastName Name,
16886 @DOB DateTime,
16887 @IsAllDeletedRecords bit,
16888 @Success bit Output,
16889 @ErrorStatus Nvarchar(50) Output
16890 )
16891AS
16892SET NOCOUNT ON;
16893 DECLARE
16894 @ErrNO int
16895
16896 SET @ErrNO =0;
16897 SET @Success = 0;
16898 SET @ErrorStatus ='';
16899
16900
16901
16902 BEGIN
16903 BEGIN TRY
16904
16905 IF @IsAllDeletedRecords = 1 AND @IsDeleted =1
16906 BEGIN
16907 --Cannot retrieve one record AND all records!
16908 SET @ErrorStatus ='Error ISAllDeltetedRecords & IsDeleted mutually exclusive, both cannot be True: '
16909 RAISERROR(@ErrorStatus,16,0)
16910 END
16911 --return everyone who is delteted
16912 IF @IsAllDeletedRecords =1
16913 BEGIN
16914 SELECT A.FirstName,A.LastName,A.DateOfBirth,
16915 B.AddressLine1, b.City
16916 FROM Person.[Person] AS A,
16917 Person.Address AS B
16918 WHERE (A.PersonID = B.PersonID) AND A.IsDeleted =1
16919 END
16920 --Just one deleted
16921 IF @IsDeleted =1
16922 BEGIN
16923 SELECT A.FirstName, A.LastName, A.DateofBirth,
16924 B.AddressLine1, b.City
16925 FROM person.[Person] AS A,
16926 Person.Address as B
16927 WHERE (A.PersonID = B.PersonID) AND FirstName = @FirstName AND LastName = @LastName AND DateOfBirth = @DOB AND IsDeleted =1
16928 END
16929 --Use soundex on last name to return deleted records like those
16930 IF @IsDeleted =1 AND @IsSoundsLike =1
16931 BEGIN
16932 SELECT A.FirstName,A.LastName,A.DateOfBirth,
16933 B.AddressLine1, b.City
16934 FROM Person.[Person] AS A,
16935 Person.Address AS B
16936 WHERE (A.personid = B.personid) AND soundex(A.Lastname) =SOUNDEX(@LastName) AND A.IsDeleted =1
16937
16938 END
16939
16940 --Completely different query for non deleted record with soundex using both first and last name because IsDeleted =0 and we could have
16941 --a ton of Smiths!
16942 IF @IsDeleted =0 and @IsSoundsLike =1
16943 BEGIN
16944 BEGIN
16945 SELECT A.FirstName,A.LastName,A.DateOfBirth,
16946 B.AddressLine1, b.City
16947 FROM Person.[Person] AS A,
16948 Person.Address AS B
16949 WHERE (A.personid = B.personid) AND SOUNDEX(A.Lastname) =SOUNDEX(@LastName) AND SOUNDEX(a.Firstname) = SOUNDEX (@FirstName) AND A.IsDeleted =0
16950
16951 END
16952 END
16953
16954 SELECT @ErrNO = @@ERROR
16955
16956 IF @ErrNo<>0
16957 BEGIN
16958 SET @ErrorStatus ='Error on query: '
16959 RAISERROR(@ErrorStatus,16,0)
16960
16961 END--IF@ErrNO
16962
16963
16964 END TRY
16965
16966 BEGIN CATCH
16967 ROLLBACK TRANSACTION;
16968 --We are ignoring @Errno because it returns 50000 whenever a string is passed to RAISERROR
16969 --We only care if the error was not raised by SSE
16970 IF @ErrNO <> 50000
16971 BEGIN
16972 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @ErrNO);
16973 END
16974 SET @Success =0;
16975 RAISERROR(@ErrorStatus, 15, 1);
16976
16977
16978 END CATCH
16979
16980 END
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996GO
16997/****** Object: StoredProcedure [Maintenance].[pRetrieveLookupTables] Script Date: 10/16/2020 7:31:03 PM ******/
16998SET ANSI_NULLS ON
16999GO
17000SET QUOTED_IDENTIFIER ON
17001GO
17002
17003
17004
17005/*************************************************************************************************
17006
17007*Author: Gary Savard
17008*Date: 11 Jun 11
17009
17010Description: Returns the names of all look up tables in CV Connect
17011Revisions:
17012**************************************************************************************************/
17013CREATE PROCEDURE [Maintenance].[pRetrieveLookupTables](
17014 @Success bit Output,
17015 @ErrorStatus Nvarchar(50) Output
17016 )
17017AS
17018SET NOCOUNT ON;
17019 DECLARE
17020 @ErrNO int
17021
17022 SET @ErrNO =0;
17023 SET @Success = 0;
17024 SET @ErrorStatus ='';
17025
17026
17027
17028 BEGIN
17029 BEGIN TRY
17030
17031 SELECT * FROM sys.tables WHERE tables.name LIKE 'LU'+'%'
17032 SELECT @ErrNO =@@ERROR
17033
17034 IF @ErrNo<>0
17035 BEGIN
17036 SET @ErrorStatus ='Failed on LU table return: '
17037 RAISERROR(@ErrorStatus,16,0)
17038
17039 END--IF@ErrNO
17040
17041
17042 END TRY
17043
17044 BEGIN CATCH
17045 ROLLBACK TRANSACTION;
17046 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
17047 --We only care if the error was not raised by SSE
17048 IF @@ERROR <> 50000
17049 BEGIN
17050 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
17051 END
17052 SET @Success =0;
17053 SELECT @ErrorStatus= @ErrorStatus +'-60063 DELETE Fail Language';
17054 RAISERROR(@ErrorStatus, 15, 1);
17055
17056
17057 END CATCH
17058
17059 END
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074GO
17075/****** Object: StoredProcedure [Person].[AddPerson] Script Date: 10/16/2020 7:31:03 PM ******/
17076SET ANSI_NULLS ON
17077GO
17078SET QUOTED_IDENTIFIER ON
17079GO
17080create procedure [Person].[AddPerson]
17081(
17082@title varchar(50) = null,
17083@firstname varchar(50),
17084@midname varchar(50) = null,
17085@lastname varchar(50) ,
17086@suffix varchar(10) = null,
17087@datbirth datetime = null,
17088@emaddress varchar(50) = null,
17089@emcontactpref int,
17090@modby varchar(50),
17091@worker bit = 0,
17092@output int Output
17093)
17094as
17095begin
17096 insert into person.Person
17097 (Title,
17098 FirstName,
17099 MiddleName,
17100 LastName,
17101 Suffix,
17102 DateOfBirth,
17103 EmailAddress,
17104 EmailContactPreference,
17105 ModifiedDate,
17106 ModifiedBy,
17107 IsVolunteer,
17108 IsDeleted)
17109
17110 values
17111 (
17112 @title,
17113 @firstname,
17114 @midname,
17115 @lastname,
17116 @suffix,
17117 @datbirth,
17118 @emaddress,
17119 @emcontactpref,
17120 sysdatetime(),
17121 @modby,
17122 @worker,
17123 0
17124 )
17125 select @output = @@IDENTITY;
17126 return
17127end
17128GO
17129/****** Object: StoredProcedure [Signature].[pInsertSignature] Script Date: 10/16/2020 7:31:03 PM ******/
17130SET ANSI_NULLS ON
17131GO
17132SET QUOTED_IDENTIFIER ON
17133GO
17134
17135
17136
17137
17138
17139/*************************************************************************************************
17140*Author: Gary Savard
17141*Date: 8 Oct 10
17142*Table Name: Signature.Signatures and Signature.Signature
17143Description: The signature history for each client must be kept in the signature table,thus there is an interchange
17144table called signatures that creates the relationship ties between the person and signature table.This procedure first
17145insterts to Singnature, retrieves the new SignatureID and makes the tie by inserting a row in the Signatures table.
17146We do not need to do updates to this procedure since a new row must always be generated for the client.
17147Revisions:
17148**************************************************************************************************/
17149
17150CREATE PROCEDURE [Signature].[pInsertSignature](
17151 @PersonID int,
17152 @Signature varChar(MAX),
17153 @ModifiedBy Name,
17154 @NewSignatureID int Output,
17155 @NewSignaturesID int Output,
17156 @Success bit Output,
17157 @ErrorStatus Nvarchar(50) Output
17158 )
17159AS
17160
17161Set NoCount ON;
17162
17163
17164 DECLARE
17165 @TempSignatureID int,
17166 @TempPersonID int,
17167 @ProcedureLocation varchar,
17168 @TempSignaturesID int;
17169
17170
17171 SET @TempSignatureID =0;
17172 SET @TempPersonID =0;
17173 SET @TempSignaturesID =0;
17174 SET @Success = 0;
17175 SET @ProcedureLocation ='';
17176 SET @ErrorStatus ='';
17177
17178
17179
17180BEGIN TRANSACTION; --We will wrap both inserts in the same transaction to avoid orphaned data
17181 BEGIN TRY
17182 /****************************************************************************/
17183 --Check to see if this person already has a signaure. This is not required with the current procedure but
17184 --is potentially required in the future so it remains.
17185 SELECT @TempPersonID = @PersonID
17186 FROM Signature.Signature
17187 WHERE Signature.PersonID = @PersonID
17188
17189/****************************************************************************/
17190
17191 IF @@Error <> 0
17192 BEGIN
17193 SET @ErrorStatus = @@ERROR + '-4000'; --Range for Signature/Signatures
17194 SET @Success = 0;
17195 RAISERROR (@ErrorStatus,16,1);
17196 END
17197
17198 BEGIN
17199
17200 INSERT INTO Signature.Signature(PersonID,Signature.Signature,ModifiedDate, ModifiedBy)
17201 VALUES (@PersonID,@Signature,SYSDATETIME(),@ModifiedBy)
17202
17203 SET @TempSignatureID =@@IDENTITY;
17204 SET @ErrorStatus =@@ERROR;
17205 SET @ProcedureLocation = 'Signature';
17206
17207 If @ErrorStatus = 0
17208 BEGIN
17209 INSERT INTO Signature.signatures(PersonID, SignatureID, ModifiedDate, ModifiedBy)
17210 Values (@PersonID, @TempSignatureID,SYSDATETIME(),@ModifiedBy)
17211
17212 SET @TempSignaturesID = @@IDENTITY;
17213 SET @ErrorStatus =@@ERROR;
17214 SET @ProcedureLocation ='Signatures';
17215 END
17216 IF @ErrorStatus =0
17217 BEGIN
17218 SET @ProcedureLocation='';
17219 SET @success =1;
17220 COMMIT TRANSACTION;
17221 END
17222 ELSE
17223 BEGIN
17224 SELECT @ProcedureLocation = 'Insert failed at:' +@ProcedureLocation;
17225 RAISERROR( @ProcedureLocation,16,1);
17226 END
17227 END
17228 END TRY
17229
17230
17231 BEGIN CATCH
17232 --Add in some granularity by returning an error id that indicates whether the failure was in Signature or Signatures.
17233 ROLLBACK TRANSACTION;
17234 --We are ignoring @@Error because it returns 50000 whenever a string is passed to RAISERROR
17235 --We only care if the error was not raised by SSE
17236 IF @@ERROR <> 50000
17237 BEGIN
17238 SELECT @ErrorStatus = @ErrorStatus + CONVERT(nVarchar(50), @@Error);
17239 END
17240 SELECT @ProcedureLocation = @ProcedureLocation + '4001 ' +@ErrorStatus;
17241 SET @Success =0;
17242 RAISERROR(@ProcedureLocation, 16, 1);
17243
17244 END CATCH;
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262GO
17263/****** Object: StoredProcedure [Volunteer].[AddDay] Script Date: 10/16/2020 7:31:03 PM ******/
17264SET ANSI_NULLS ON
17265GO
17266SET QUOTED_IDENTIFIER ON
17267GO
17268CREATE procedure [Volunteer].[AddDay]
17269(
17270@DayofWeek int,
17271@AvailableBeginTime time(0),
17272@AvailableEndTime time(0),
17273@IsNoShow bit,
17274@ActualHoursTotal numeric(18,0),
17275@VolunteerPersonID int,
17276@modby varchar(50),
17277@Date date,
17278@month int,
17279@Year int,
17280@JobID int,
17281@output int output
17282)
17283as
17284begin
17285 declare
17286 @tempID int;
17287 set @tempID = 0;
17288 select @tempID = VolunteerPersonID from Volunteer.VolunteerContactInformation
17289 where VolunteerPersonID = @VolunteerPersonID
17290
17291 if @tempID <> 0
17292 begin
17293 insert into Volunteer.VolunteerScheduleDayTime
17294 (
17295 [DayOfWeek],
17296 AvailableBeginTime,
17297 AvailableEndTime,
17298 IsNoShow,
17299 ActualHoursTotal,
17300 ModifiedDate,
17301 VolunteerPersonID,
17302 ModifiedBy,
17303 [Date],
17304 [Month],
17305 [Year],
17306 JobID
17307 )
17308
17309 Values
17310 (
17311 @DayofWeek,
17312 @AvailableBeginTime,
17313 @AvailableEndTime,
17314 @IsNoShow,
17315 @ActualHoursTotal,
17316 sysdatetime(),
17317 @VolunteerPersonID,
17318 @modby,
17319 @Date,
17320 @month,
17321 @Year,
17322 @JobID
17323 )
17324
17325 select @output = @@IDENTITY
17326 end
17327 return
17328end
17329GO
17330/****** Object: StoredProcedure [Volunteer].[AddEMContact] Script Date: 10/16/2020 7:31:03 PM ******/
17331SET ANSI_NULLS ON
17332GO
17333SET QUOTED_IDENTIFIER ON
17334GO
17335create procedure [Volunteer].[AddEMContact]
17336(
17337@VolunteerPersonID int,
17338@ContactFirstName varchar(50),
17339@ContactMidName varchar(50) = null,
17340@ContactLastName varchar(50),
17341@ContactPrimaryPhone varchar(50) = null,
17342@ContactAltPhone varchar(50) = null,
17343@ContactEmail varchar(50) = null,
17344@ContactAddress varchar(250) = null,
17345@Modby varchar(50)
17346)
17347as
17348begin
17349 declare
17350 @tempID int;
17351 set @tempID = 0;
17352 select @tempID = VolunteerPersonID from Volunteer.VolunteerContactInformation
17353 where VolunteerPersonID = @VolunteerPersonID
17354
17355 if @tempID <> 0
17356 begin
17357 insert into Volunteer.EmContact
17358 (
17359 VolunteerPersonID,
17360 ContactFirstName,
17361 ContactMidName,
17362 ContactLastName,
17363 ContactPrimaryPhone,
17364 ContactAltPhone,
17365 ContactEmail,
17366 ContactAddress,
17367 ModifiedBy,
17368 ModifiedDate
17369 )
17370 values
17371 (
17372 @VolunteerPersonID,
17373 @ContactFirstName,
17374 @ContactMidName,
17375 @ContactLastName,
17376 @ContactPrimaryPhone,
17377 @ContactAltPhone,
17378 @ContactEmail,
17379 @ContactAddress,
17380 @Modby,
17381 sysdatetime()
17382 )
17383 end
17384 return
17385end
17386GO
17387/****** Object: StoredProcedure [Volunteer].[AddVol] Script Date: 10/16/2020 7:31:03 PM ******/
17388SET ANSI_NULLS ON
17389GO
17390SET QUOTED_IDENTIFIER ON
17391GO
17392CREATE procedure [Volunteer].[AddVol]
17393(
17394@IsActive bit,
17395@personID int,
17396@ModifiedBy varchar(50),
17397@PrimaryPhone varchar(50) = null,
17398@AltPhone varchar(50) = null,
17399@Email varchar(50) = null,
17400@output int output
17401)
17402
17403as
17404begin
17405 insert into Volunteer.VolunteerContactInformation
17406 (
17407 IsActive,
17408 ModifiedDate,
17409 PersonID,
17410 ModifiedBy,
17411 PrimaryPhone,
17412 AltPhone,
17413 Email
17414 )
17415 values
17416 (
17417 @IsActive,
17418 sysdatetime(),
17419 @personID,
17420 @ModifiedBy,
17421 @PrimaryPhone,
17422 @AltPhone,
17423 @Email
17424 )
17425 select @output = @@IDENTITY
17426 return
17427end
17428GO
17429/****** Object: StoredProcedure [Volunteer].[AddVolJob] Script Date: 10/16/2020 7:31:03 PM ******/
17430SET ANSI_NULLS ON
17431GO
17432SET QUOTED_IDENTIFIER ON
17433GO
17434CREATE procedure [Volunteer].[AddVolJob]
17435(
17436@VolunteerPersonID int,
17437@Job varchar(50),
17438@Modby varchar(50),
17439@PositionCode int
17440)
17441as
17442Begin
17443 declare
17444 @tempID int;
17445 set @tempID = 0;
17446 select @tempID = VolunteerPersonID from Volunteer.VolunteerContactInformation
17447 where VolunteerPersonID = @VolunteerPersonID
17448
17449 if @tempID <> 0
17450 begin
17451 insert into Volunteer.VolunteerJobs
17452 (
17453 VolunteerPersonID,
17454 Job,
17455 ModifiedDate,
17456 ModifiedBy,
17457 PositionCode
17458 )
17459 Values
17460 (
17461 @VolunteerPersonID,
17462 @Job,
17463 sysdatetime(),
17464 @Modby,
17465 @PositionCode
17466 )
17467 end
17468End
17469GO
17470/****** Object: StoredProcedure [Volunteer].[AddVolNote] Script Date: 10/16/2020 7:31:03 PM ******/
17471SET ANSI_NULLS ON
17472GO
17473SET QUOTED_IDENTIFIER ON
17474GO
17475CREATE procedure [Volunteer].[AddVolNote]
17476(
17477@VolunteerPersonID int,
17478@Note varchar(250),
17479@ModifiedBy varchar(50)
17480)
17481as
17482begin
17483 declare
17484 @tempID int;
17485 set @tempID = 0;
17486 select @tempID = VolunteerPersonID from Volunteer.VolunteerContactInformation
17487 where VolunteerPersonID = @VolunteerPersonID
17488
17489 if @tempID <> 0
17490 begin
17491 insert into Volunteer.VolunteerNotes
17492 (
17493 VolunteerPersonID,
17494 Note,
17495 ModifiedDate,
17496 ModifiedBy
17497 )
17498 values
17499 (
17500 @VolunteerPersonID,
17501 @Note,
17502 sysdatetime(),
17503 @ModifiedBy
17504 )
17505 end
17506
17507end
17508GO
17509/****** Object: StoredProcedure [Volunteer].[AddVolunteer] Script Date: 10/16/2020 7:31:03 PM ******/
17510SET ANSI_NULLS ON
17511GO
17512SET QUOTED_IDENTIFIER ON
17513GO
17514CREATE procedure [Volunteer].[AddVolunteer]
17515(
17516--These values are for inserting the person into Person.Person
17517@title varchar(50) = null,
17518@firstname varchar(50),
17519@midname varchar(50) = null,
17520@lastname varchar(50) ,
17521@suffix varchar(10) = null,
17522@datbirth datetime = null,
17523@modby varchar(50),
17524
17525--These values are for inserting the person into Volunteer.VolunteerContactInformation
17526@IsActive bit,
17527@PrimaryPhone varchar(50) = null,
17528@AltPhone varchar(50) = null,
17529@Email varchar(50) = null
17530)
17531
17532as
17533begin
17534
17535declare
17536@TempPersID int,
17537@TempVolID int,
17538@errorstat varchar(50);
17539set @TempPersID = 0;
17540
17541begin try
17542
17543 begin transaction
17544 select @TempPersID = PersonID from Person.Person
17545 where @firstname = FirstName and @lastname = LastName
17546
17547 if @TempPersID <> 0
17548 begin
17549 select @errorstat = 'That person is in the database';
17550 raiserror(@errorstat, 11, 1);
17551 end
17552
17553 set @TempPersID = null;
17554
17555
17556 exec Person.AddPerson
17557 @title,
17558 @firstname,
17559 @midname,
17560 @lastname,
17561 @suffix,
17562 @datbirth,
17563 'volunteer',
17564 null,
17565 @modby,
17566 1,
17567 @TempPersID output
17568
17569 exec Volunteer.AddVol
17570 @IsActive,
17571 @TempPersID,
17572 @modby,
17573 @PrimaryPhone,
17574 @AltPhone,
17575 @Email,
17576 @TempVolID output
17577
17578 commit transaction
17579
17580 select @TempPersID as 'New PersonID', @TempVolID as 'NewVolunteerPersonID' ,@firstname as 'FirstName', @lastname as 'LastName'
17581end try
17582
17583begin catch
17584 select @errorstat as 'Error Status';
17585 rollback transaction;
17586end catch
17587end
17588GO
17589/****** Object: StoredProcedure [Volunteer].[DeleteAllEmContacts] Script Date: 10/16/2020 7:31:03 PM ******/
17590SET ANSI_NULLS ON
17591GO
17592SET QUOTED_IDENTIFIER ON
17593GO
17594create procedure [Volunteer].[DeleteAllEmContacts]
17595(
17596@VolunteerPersonID int
17597)
17598as
17599begin
17600
17601 declare @TempID int, @Errorstat varchar(50);
17602 set @TempID = 0;
17603 begin try
17604 begin transaction
17605 select @TempID = VolunteerPersonID from Volunteer.EmContact
17606 where VolunteerPersonID = @VolunteerPersonID
17607
17608 if @TempID = 0
17609 begin
17610 select @Errorstat = 'That record does not exist';
17611 raiserror(@Errorstat, 11, 1);
17612 end
17613
17614 delete from Volunteer.EmContact where VolunteerPersonID = @VolunteerPersonID
17615 commit transaction
17616 end try
17617
17618 begin catch
17619 select @Errorstat as 'ERROR status';
17620 rollback transaction;
17621 end catch
17622end
17623GO
17624/****** Object: StoredProcedure [Volunteer].[DeleteAllJobs] Script Date: 10/16/2020 7:31:03 PM ******/
17625SET ANSI_NULLS ON
17626GO
17627SET QUOTED_IDENTIFIER ON
17628GO
17629create procedure [Volunteer].[DeleteAllJobs]
17630(
17631@VolunteerPersonID int
17632)
17633as
17634begin
17635
17636 declare @TempID int, @Errorstat varchar(50);
17637 set @TempID = 0;
17638 begin try
17639 begin transaction
17640 select @TempID = VolunteerPersonID from Volunteer.VolunteerJobs
17641 where VolunteerPersonID = @VolunteerPersonID
17642
17643 if @TempID = 0
17644 begin
17645 select @Errorstat = 'That record does not exist';
17646 raiserror(@Errorstat, 11, 1);
17647 end
17648
17649 delete from Volunteer.VolunteerJobs where VolunteerPersonID = @VolunteerPersonID
17650 commit transaction
17651 end try
17652
17653 begin catch
17654 select @Errorstat as 'ERROR status';
17655 rollback transaction;
17656 end catch
17657end
17658GO
17659/****** Object: StoredProcedure [Volunteer].[DeleteALLNotes] Script Date: 10/16/2020 7:31:03 PM ******/
17660SET ANSI_NULLS ON
17661GO
17662SET QUOTED_IDENTIFIER ON
17663GO
17664create procedure [Volunteer].[DeleteALLNotes]
17665(
17666@VolunteerPersonID int
17667)
17668as
17669begin
17670
17671 declare @TempID int, @Errorstat varchar(50);
17672 set @TempID = 0;
17673 begin try
17674 begin transaction
17675 select @TempID = VolunteerPersonID from Volunteer.VolunteerNotes
17676 where VolunteerPersonID = @VolunteerPersonID
17677
17678 if @TempID = 0
17679 begin
17680 select @Errorstat = 'That record does not exist';
17681 raiserror(@Errorstat, 11, 1);
17682 end
17683
17684 delete from Volunteer.VolunteerNotes where VolunteerPersonID = @VolunteerPersonID
17685 commit transaction
17686 end try
17687
17688 begin catch
17689 select @Errorstat as 'ERROR status';
17690 rollback transaction;
17691 end catch
17692end
17693GO
17694/****** Object: StoredProcedure [Volunteer].[DeleteOneEmContact] Script Date: 10/16/2020 7:31:03 PM ******/
17695SET ANSI_NULLS ON
17696GO
17697SET QUOTED_IDENTIFIER ON
17698GO
17699create procedure [Volunteer].[DeleteOneEmContact]
17700(
17701@VolunteerEmergencyContactID int
17702)
17703as
17704begin
17705
17706 declare @TempID int, @Errorstat varchar(50);
17707 set @TempID = 0;
17708 begin try
17709 begin transaction
17710 select @TempID = VolunteerEmergencyContactID from Volunteer.EmContact
17711 where VolunteerEmergencyContactID = @VolunteerEmergencyContactID
17712
17713 if @TempID = 0
17714 begin
17715 select @Errorstat = 'That record does not exist';
17716 raiserror(@Errorstat, 11, 1);
17717 end
17718
17719 delete from Volunteer.EmContact where VolunteerEmergencyContactID = @VolunteerEmergencyContactID
17720 commit transaction
17721 end try
17722
17723 begin catch
17724 select @Errorstat as 'ERROR status';
17725 rollback transaction;
17726 end catch
17727end
17728GO
17729/****** Object: StoredProcedure [Volunteer].[DeleteOneJob] Script Date: 10/16/2020 7:31:03 PM ******/
17730SET ANSI_NULLS ON
17731GO
17732SET QUOTED_IDENTIFIER ON
17733GO
17734create procedure [Volunteer].[DeleteOneJob]
17735(
17736@VolunteerJobsID int
17737)
17738as
17739begin
17740
17741 declare @TempID int, @Errorstat varchar(50);
17742 set @TempID = 0;
17743 begin try
17744 begin transaction
17745 select @TempID = VolunteerJobsID from Volunteer.VolunteerJobs
17746 where VolunteerJobsID = @VolunteerJobsID
17747
17748 if @TempID = 0
17749 begin
17750 select @Errorstat = 'That record does not exist';
17751 raiserror(@Errorstat, 11, 1);
17752 end
17753
17754 delete from Volunteer.VolunteerJobs where VolunteerJobsID = @VolunteerJobsID
17755 commit transaction
17756 end try
17757
17758 begin catch
17759 select @Errorstat as 'ERROR status';
17760 rollback transaction;
17761 end catch
17762end
17763GO
17764/****** Object: StoredProcedure [Volunteer].[DeleteOneNote] Script Date: 10/16/2020 7:31:03 PM ******/
17765SET ANSI_NULLS ON
17766GO
17767SET QUOTED_IDENTIFIER ON
17768GO
17769create procedure [Volunteer].[DeleteOneNote]
17770(
17771@VolunteerNotesID int
17772)
17773as
17774begin
17775
17776 declare @TempID int, @Errorstat varchar(50);
17777 set @TempID = 0;
17778 begin try
17779 begin transaction
17780 select @TempID = VolunteerNotesID from Volunteer.VolunteerNotes
17781 where VolunteerNotesID = @VolunteerNotesID
17782
17783 if @TempID = 0
17784 begin
17785 select @Errorstat = 'That record does not exist';
17786 raiserror(@Errorstat, 11, 1);
17787 end
17788
17789 delete from Volunteer.VolunteerNotes where @VolunteerNotesID = @VolunteerNotesID
17790 commit transaction
17791 end try
17792
17793 begin catch
17794 select @Errorstat as 'ERROR status';
17795 rollback transaction;
17796 end catch
17797end
17798GO
17799/****** Object: StoredProcedure [Volunteer].[GetSchedule] Script Date: 10/16/2020 7:31:03 PM ******/
17800SET ANSI_NULLS ON
17801GO
17802SET QUOTED_IDENTIFIER ON
17803GO
17804CREATE procedure [Volunteer].[GetSchedule]
17805(
17806@VolunteerPersonID int,
17807@DateStart date,
17808@DateEnd date
17809)
17810as
17811begin
17812 declare @tempID int, @errorstat varchar(50);
17813 set @tempID = 0;
17814 begin try
17815-----------------------------------------------------------------------------------------------------
17816/*
17817These checks ensure that the volunteer exists and whether or not they have ever been scheduled as well
17818as whether or not the person is scheduled in the range specified.
17819*/
17820 select @tempID = VolunteerPersonID from Volunteer.VolunteerContactInformation
17821 where VolunteerPersonID = @VolunteerPersonID
17822
17823 if @tempID = 0
17824 begin
17825 select @errorstat = 'That volunteer does not exist';
17826 raiserror(@errorstat, 11, 1);
17827 end;
17828
17829 set @tempID = 0;
17830
17831 select @tempID = VolunteerPersonID from Volunteer.VolunteerScheduleDayTime
17832 where VolunteerPersonID = @VolunteerPersonID
17833
17834 if @tempID = 0
17835 begin
17836 select @errorstat = 'That volunteer has never been scheduled.';
17837 raiserror(@errorstat, 11, 1);
17838 end;
17839
17840 set @tempID = 0;
17841
17842 with schedule as
17843 (
17844 select [Date], VolunteerPersonID from Volunteer.VolunteerScheduleDayTime
17845 where [Date] between @DateStart and @DateEnd
17846 )
17847
17848 select @tempID = VolunteerPersonID from schedule
17849 where VolunteerPersonID = @VolunteerPersonID
17850
17851 if @tempID = 0
17852 begin
17853 select @errorstat = 'That volunteer was not scheduled then.';
17854 raiserror(@errorstat, 11, 1);
17855 end
17856
17857
17858-----------------------------------------------------------------------------------------------------
17859--This is the select statement that produces the list of scheduled days.
17860
17861 select sch.VolunteerPersonID, na.LastName, na. Firstname, sch.[DayOfWeek], sch.[Date],
17862 sch.AvailableBeginTime, sch.AvailableEndTime, sch.ActualHoursTotal, sch.IsNoShow from Volunteer.VolunteerScheduleDayTime as sch
17863 join Volunteer.VolunteerContactInformation as vol on vol.VolunteerPersonID = sch.VolunteerPersonID
17864 join Person.person as na on na.PersonID = vol.PersonID
17865 where sch.[Date] between @DateStart and @DateEnd
17866
17867 end try
17868
17869 begin catch
17870 select @errorstat as 'ERROR status';
17871 end catch
17872end
17873GO
17874/****** Object: StoredProcedure [Volunteer].[TotalRemoveVolunteer] Script Date: 10/16/2020 7:31:03 PM ******/
17875SET ANSI_NULLS ON
17876GO
17877SET QUOTED_IDENTIFIER ON
17878GO
17879CREATE procedure [Volunteer].[TotalRemoveVolunteer]
17880(
17881@VolunteerPersonID int,
17882@PersonID int,
17883@modby varchar(50)
17884)
17885as
17886begin
17887
17888 declare @TempID int, @Errorstat varchar(50);
17889 set @TempID = 0;
17890 begin try
17891 begin transaction
17892 select @TempID = VolunteerPersonID from Volunteer.VolunteerContactInformation
17893 where VolunteerPersonID = @VolunteerPersonID
17894
17895 if @TempID = 0
17896 begin
17897 select @Errorstat = 'That record does not exist';
17898 raiserror(@Errorstat, 11, 1);
17899 end
17900
17901 delete from Volunteer.VolunteerScheduleDayTime where VolunteerPersonID = @VolunteerPersonID;
17902 delete from Volunteer.VolunteerNotes where VolunteerPersonID = @VolunteerPersonID;
17903 delete from Volunteer.VolunteerJobs where VolunteerPersonID = @VolunteerPersonID;
17904 delete from Volunteer.EmContact where VolunteerPersonID = @VolunteerPersonID;
17905 delete from Volunteer.VolunteerContactInformation where VolunteerPersonID = @VolunteerPersonID;
17906
17907 update Person.Person
17908 set EmailAddress = '', EmailContactPreference = 0, IsVolunteer = 0, IsDeleted = 1, ModifiedDate = sysdatetime(), ModifiedBy = @modby
17909 where PersonID = @PersonID
17910
17911
17912 commit transaction
17913 end try
17914
17915 begin catch
17916 select @Errorstat as 'ERROR status';
17917 rollback transaction;
17918 end catch
17919end
17920GO
17921/****** Object: StoredProcedure [Volunteer].[UpdateDay] Script Date: 10/16/2020 7:31:03 PM ******/
17922SET ANSI_NULLS ON
17923GO
17924SET QUOTED_IDENTIFIER ON
17925GO
17926CREATE procedure [Volunteer].[UpdateDay]
17927(/*These variables are to ensure the day to be modified exists in the database*/
17928@VolunteerScheduleDayTimeID int,
17929@VolunteerPersonID int,
17930
17931/*These variabls are the values that may be modified*/
17932@DayOfWeek int,
17933@AvailableBeginTime time(0),
17934@AvailableEndTime time(0),
17935@IsNoShow bit,
17936@ActualHoursTotal numeric(18,0),
17937@Modby varchar(50),
17938@date date,
17939@Month int,
17940@Year int,
17941@JobID int
17942)
17943as
17944begin
17945 declare
17946 @success varchar(50),
17947 @errorstat varchar(50),
17948 @TempDayID int;
17949 set @TempDayID = 0;
17950 begin try
17951 begin transaction
17952/*********************************************************************************************************************************/
17953/*This checks to see if the day to be modified exists in the database*/
17954
17955 select @TempDayID = VolunteerScheduleDayTimeID from Volunteer.VolunteerScheduleDayTime as da
17956 where @VolunteerScheduleDayTimeID = da.VolunteerScheduleDayTimeID and @VolunteerPersonID = da.VolunteerPersonID
17957
17958 if @TempDayID = 0
17959 begin
17960 select @errorstat = 'The day you are trying to modify is not in the database.';
17961 raiserror(@errorstat, 11, 1);
17962 end
17963
17964/*********************************************************************************************************************************/
17965/*This part of the code is the actual update statement*/
17966
17967
17968 update Volunteer.VolunteerScheduleDayTime
17969 set [DayOfWeek] = @DayOfWeek, AvailableBeginTime = @AvailableBeginTime,
17970 AvailableEndTime = @AvailableEndTime, IsNoShow = @IsNoShow, ActualHoursTotal = @ActualHoursTotal,
17971 ModifiedBy = @Modby, [Date] = @date, [Month] = @Month, [Year] = @Year, JobID = @JobID
17972 where VolunteerScheduleDayTimeID = @VolunteerScheduleDayTimeID;
17973
17974 set @success = 'The Day has been updated successfully.';
17975 select @success as 'STATUS';
17976 commit transaction
17977
17978/*********************************************************************************************************************************/
17979
17980
17981
17982 end try
17983
17984 begin catch
17985 select @errorstat as 'STATUS';
17986 rollback transaction;
17987 end catch
17988end
17989GO
17990/****** Object: StoredProcedure [Volunteer].[UpdateEMContacts] Script Date: 10/16/2020 7:31:03 PM ******/
17991SET ANSI_NULLS ON
17992GO
17993SET QUOTED_IDENTIFIER ON
17994GO
17995CREATE procedure [Volunteer].[UpdateEMContacts]
17996(
17997@VolunteerEmergencyContactID int,
17998@VolunteerPersonID int,
17999@ContactFirstName varchar(50),
18000@ContactMidName varchar(50),
18001@ContactLastName varchar(50),
18002@ContactPrimaryPhone varchar(50),
18003@ContactAltPhone varchar(50),
18004@ContactEmail varchar(50),
18005@contactAddress varchar(250),
18006@Modby varchar(50)
18007)
18008as
18009begin
18010 declare
18011 @tempID int,
18012 @errorstat varchar(50);
18013 set @tempID = 0;
18014
18015
18016
18017 begin try
18018 begin transaction
18019 select @tempID = VolunteerEmergencyContactID from Volunteer.EmContact
18020 where VolunteerEmergencyContactID = @VolunteerEmergencyContactID
18021
18022 if @tempID = 0
18023 begin
18024 select @errorstat = 'That record does not exist';
18025 raiserror(@errorstat, 11, 1);
18026 end
18027
18028
18029 update Volunteer.EmContact
18030 set ContactFirstName = @ContactFirstName, ContactMidName = @ContactMidName, ContactLastName = @ContactLastName,
18031 ContactPrimaryPhone = @ContactPrimaryPhone, ContactAltPhone = @ContactAltPhone, ContactEmail = @ContactEmail,
18032 ContactAddress = @contactAddress, ModifiedBy = @Modby, ModifiedDAte = sysdatetime()
18033 where VolunteerEmergencyContactID = @VolunteerEmergencyContactID
18034 commit transaction
18035 end try
18036
18037 begin catch
18038 select @errorstat as 'ERROR STATUS';
18039 rollback transaction;
18040 end catch
18041
18042end
18043GO
18044/****** Object: StoredProcedure [Volunteer].[Updatejobs] Script Date: 10/16/2020 7:31:03 PM ******/
18045SET ANSI_NULLS ON
18046GO
18047SET QUOTED_IDENTIFIER ON
18048GO
18049CREATE procedure [Volunteer].[Updatejobs]
18050(
18051@VolunteerJobsID int,
18052@VolunteerPersonID int,
18053@Job varchar(50),
18054@Modby varchar(50),
18055@PositionCode int
18056)
18057as
18058begin
18059
18060 declare
18061 @tempID int,
18062 @errorstat varchar(50);
18063 set @tempID = 0;
18064
18065 begin try
18066 begin transaction
18067 select @tempID = VolunteerJobsID from Volunteer.VolunteerJobs
18068 where VolunteerJobsID = @VolunteerJobsID
18069
18070 if @tempID = 0
18071 begin
18072 select @errorstat = 'That record does not exist';
18073 raiserror(@errorstat, 11, 1);
18074 end
18075
18076 update VolunteerJobs
18077 set Job = @job, ModifiedDate = sysdatetime(), ModifiedBy = @Modby, PositionCode = @PositionCode, VolunteerPersonID = @VolunteerPersonID
18078 where VolunteerJobsID = @VolunteerJobsID
18079 commit transaction
18080 end try
18081
18082 begin catch
18083 select @errorstat as 'ERROR Status';
18084 rollback transaction;
18085 end catch
18086end
18087GO
18088/****** Object: StoredProcedure [Volunteer].[UpdateNotes] Script Date: 10/16/2020 7:31:03 PM ******/
18089SET ANSI_NULLS ON
18090GO
18091SET QUOTED_IDENTIFIER ON
18092GO
18093create procedure [Volunteer].[UpdateNotes]
18094(
18095@VolunteerNotesID int,
18096@VolunteerPersonID int,
18097@Note varchar(250),
18098@Modby varchar(50)
18099)
18100as
18101
18102begin
18103 declare
18104 @tempID int, @Errorstat varchar(50);
18105 set @tempID = 0;
18106
18107 begin try
18108 begin transaction
18109 select @tempID = VolunteerNotesID from Volunteer.VolunteerNotes
18110 where VolunteerNotesID = @VolunteerNotesID
18111
18112 if @tempID = 0
18113 begin
18114 select @Errorstat = 'That record does not exist';
18115 raiserror(@Errorstat, 11, 1);
18116 end
18117
18118 update Volunteer.VolunteerNotes
18119 set Note = @Note, ModifiedDate = sysdatetime(), ModifiedBy = @Modby
18120 where VolunteerNotesID = @VolunteerNotesID
18121 commit transaction
18122 end try
18123
18124 begin catch
18125 select @Errorstat as 'ERROR status';
18126 rollback transaction;
18127 end catch
18128end
18129GO
18130/****** Object: StoredProcedure [Volunteer].[UpdateVolunteerContact] Script Date: 10/16/2020 7:31:03 PM ******/
18131SET ANSI_NULLS ON
18132GO
18133SET QUOTED_IDENTIFIER ON
18134GO
18135CREATE procedure [Volunteer].[UpdateVolunteerContact]
18136(
18137@VolunteerPersonID int,
18138@IsActive bit,
18139@PersonID int,
18140@Modby varchar(50),
18141@PrimaryPhone varchar(50),
18142@Altphone varchar(50),
18143@Email varchar(50)
18144)
18145as
18146begin
18147
18148 declare @Errorstat varchar(50), @tempID int;
18149 set @tempID = 0;
18150
18151 begin try
18152 begin transaction
18153 select @tempID = VolunteerPersonID from Volunteer.VolunteerContactInformation
18154 where VolunteerPersonID = @VolunteerPersonID
18155
18156 if @tempID = 0
18157 begin
18158 select @Errorstat = 'That record does not exist.';
18159 raiserror(@Errorstat, 11, 1);
18160 end
18161
18162 update Volunteer.VolunteerContactInformation
18163 set IsActive = @IsActive, ModifiedDate = sysdatetime(), PersonID = @PersonID, ModifiedBy = @Modby,
18164 PrimaryPhone = @PrimaryPhone, AltPhone = @Altphone, Email = @Email
18165 where VolunteerPersonID = @VolunteerPersonID
18166 commit transaction
18167 end try
18168
18169 begin catch
18170 select @Errorstat as 'ERROR Status';
18171 rollback transaction;
18172 end catch
18173end
18174
18175GO
18176EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Collection of XML schemas for the AdditionalContactInfo column in the Person.Contact table.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'XML SCHEMA COLLECTION',@level1name=N'AdditionalContactInfoSchemaCollection'
18177GO
18178EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Contains objects related to names and addresses of customers, vendors, and employees' , @level0type=N'SCHEMA',@level0name=N'Person'
18179GO
18180EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Yearly Certification and Signature' , @level0type=N'SCHEMA',@level0name=N'Foodshelf', @level1type=N'TABLE',@level1name=N'FoodShelfCertification'
18181GO
18182EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Makes each row unique for those who utilize the service more than once' , @level0type=N'SCHEMA',@level0name=N'Foodshelf', @level1type=N'TABLE',@level1name=N'FoodTypeGiven', @level2type=N'CONSTRAINT',@level2name=N'UK_FoodTypeGivenRecord'
18183GO
18184EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'This is the electronic signature capture table.' , @level0type=N'SCHEMA',@level0name=N'Foodshelf', @level1type=N'TABLE',@level1name=N'Signature'
18185GO
18186EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ID being used instead of the actual code because it may be possible to avoid duplicate addresses in the future' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Address', @level2type=N'COLUMN',@level2name=N'AddressTypeID'
18187GO
18188EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'The clientPersonID is the PersonID of the client. All in the household are stored here in the PersonID column, except for the client. This ties household members to the client' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'FamilyRelationships', @level2type=N'COLUMN',@level2name=N'ClientPersonID'
18189GO
18190EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Lookup Table for Family Relationships. Data source is client' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'FamilyRelationships'
18191GO
18192EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'This is called IncomeSourceRowID because we already have IncomeID from the LUIncomeType, avoid confusion!' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Income', @level2type=N'COLUMN',@level2name=N'IncomeSourceRowID'
18193GO
18194EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'The Person can have multiple income sources, but we only want to record each source once, thus uniqueness' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Income', @level2type=N'CONSTRAINT',@level2name=N'UK_IncomeSource'
18195GO
18196EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'This table lists all languages spoken by employee or volunteer' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LanguagesSpoken'
18197GO
18198EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Primary key for AddressType records.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUAddressType', @level2type=N'COLUMN',@level2name=N'AddressTypeID'
18199GO
18200EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Address type description. For example, Billing, Home, etc.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUAddressType', @level2type=N'COLUMN',@level2name=N'AddressType'
18201GO
18202EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Date and time the record was last updated.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUAddressType', @level2type=N'COLUMN',@level2name=N'ModifiedDate'
18203GO
18204EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Types of addresses stored in the Address table. ' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUAddressType'
18205GO
18206EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Primary key (clustered) constraint' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUAddressType', @level2type=N'CONSTRAINT',@level2name=N'PK_AddressType_AddressTypeID'
18207GO
18208EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'City for the hierarchy State, County City, PostalCode' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUCity'
18209GO
18210EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Primary key for ContactType records.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUContactType', @level2type=N'COLUMN',@level2name=N'ContactTypeID'
18211GO
18212EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Contact type description.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUContactType', @level2type=N'COLUMN',@level2name=N'Name'
18213GO
18214EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Date and time the record was last updated.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUContactType', @level2type=N'COLUMN',@level2name=N'ModifiedDate'
18215GO
18216EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Lookup table containing the types of contacts stored in Contact.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUContactType'
18217GO
18218EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Primary key (clustered) constraint' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUContactType', @level2type=N'CONSTRAINT',@level2name=N'PK_ContactType_ContactTypeID'
18219GO
18220EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'This is the lookup table for Country of Origin for clients. The list is based on the CIA World Facts Book' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUCountryOfOrigin'
18221GO
18222EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'List of counties' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUCounty'
18223GO
18224EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Lookup Table for levels of education. Source is Client''s categories' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUEducationCategory'
18225GO
18226EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'This is the ethnicity lookup table based on US Census Categories' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUEthnicity'
18227GO
18228EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Where the client gets income. Source is organization''s categories' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUIncomeSource'
18229GO
18230EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'This is the lookup table for race. It is based on US Census Categories' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LURace'
18231GO
18232EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Primary key for State records.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUState', @level2type=N'COLUMN',@level2name=N'StateID'
18233GO
18234EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ISO standard state code.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUState', @level2type=N'COLUMN',@level2name=N'StateCode'
18235GO
18236EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'State.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUState', @level2type=N'COLUMN',@level2name=N'Name'
18237GO
18238EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Date and time the record was last updated.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUState', @level2type=N'COLUMN',@level2name=N'ModifiedDate'
18239GO
18240EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'State lookup table.' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUState'
18241GO
18242EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Primary key (clustered) constraint' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'LUState', @level2type=N'CONSTRAINT',@level2name=N'PK_State_StateID'
18243GO
18244EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Join table to allow multiple addresses per person' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'PersonAddresses'
18245GO
18246EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'This table associates a person with a particluar program (division) within the organization' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'Programs', @level2type=N'COLUMN',@level2name=N'ModifiedBy'
18247GO
18248EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'This table associates a person with one or more services within a program' , @level0type=N'SCHEMA',@level0name=N'Person', @level1type=N'TABLE',@level1name=N'ProgramServicesUsed'
18249GO
18250EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'This is the electronic signature capture table. It lives in its own schema and may be encrypted for security reasons' , @level0type=N'SCHEMA',@level0name=N'Signature', @level1type=N'TABLE',@level1name=N'Signature'
18251GO
18252EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Only one SSN per person!' , @level0type=N'SCHEMA',@level0name=N'SSN', @level1type=N'TABLE',@level1name=N'SSN', @level2type=N'CONSTRAINT',@level2name=N'UK_SSN'
18253GO
18254EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'The types of jobs that the volunteer can do' , @level0type=N'SCHEMA',@level0name=N'Volunteer', @level1type=N'TABLE',@level1name=N'VolunteerJobs'
18255GO
18256EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
18257Begin DesignProperties =
18258 Begin PaneConfigurations =
18259 Begin PaneConfiguration = 0
18260 NumPanes = 4
18261 Configuration = "(H (1[40] 4[20] 2[20] 3) )"
18262 End
18263 Begin PaneConfiguration = 1
18264 NumPanes = 3
18265 Configuration = "(H (1 [50] 4 [25] 3))"
18266 End
18267 Begin PaneConfiguration = 2
18268 NumPanes = 3
18269 Configuration = "(H (1 [50] 2 [25] 3))"
18270 End
18271 Begin PaneConfiguration = 3
18272 NumPanes = 3
18273 Configuration = "(H (4 [30] 2 [40] 3))"
18274 End
18275 Begin PaneConfiguration = 4
18276 NumPanes = 2
18277 Configuration = "(H (1 [56] 3))"
18278 End
18279 Begin PaneConfiguration = 5
18280 NumPanes = 2
18281 Configuration = "(H (2 [66] 3))"
18282 End
18283 Begin PaneConfiguration = 6
18284 NumPanes = 2
18285 Configuration = "(H (4 [50] 3))"
18286 End
18287 Begin PaneConfiguration = 7
18288 NumPanes = 1
18289 Configuration = "(V (3))"
18290 End
18291 Begin PaneConfiguration = 8
18292 NumPanes = 3
18293 Configuration = "(H (1[56] 4[18] 2) )"
18294 End
18295 Begin PaneConfiguration = 9
18296 NumPanes = 2
18297 Configuration = "(H (1 [75] 4))"
18298 End
18299 Begin PaneConfiguration = 10
18300 NumPanes = 2
18301 Configuration = "(H (1[66] 2) )"
18302 End
18303 Begin PaneConfiguration = 11
18304 NumPanes = 2
18305 Configuration = "(H (4 [60] 2))"
18306 End
18307 Begin PaneConfiguration = 12
18308 NumPanes = 1
18309 Configuration = "(H (1) )"
18310 End
18311 Begin PaneConfiguration = 13
18312 NumPanes = 1
18313 Configuration = "(V (4))"
18314 End
18315 Begin PaneConfiguration = 14
18316 NumPanes = 1
18317 Configuration = "(V (2))"
18318 End
18319 ActivePaneConfig = 0
18320 End
18321 Begin DiagramPane =
18322 Begin Origin =
18323 Top = 0
18324 Left = 0
18325 End
18326 Begin Tables =
18327 Begin Table = "FoodshelfRules (Foodshelf)"
18328 Begin Extent =
18329 Top = 6
18330 Left = 38
18331 Bottom = 230
18332 Right = 504
18333 End
18334 DisplayFlags = 280
18335 TopColumn = 0
18336 End
18337 End
18338 End
18339 Begin SQLPane =
18340 End
18341 Begin DataPane =
18342 Begin ParameterDefaults = ""
18343 End
18344 End
18345 Begin CriteriaPane =
18346 Begin ColumnWidths = 11
18347 Column = 1440
18348 Alias = 900
18349 Table = 1170
18350 Output = 720
18351 Append = 1400
18352 NewValue = 1170
18353 SortType = 1350
18354 SortOrder = 1410
18355 GroupBy = 1350
18356 Filter = 4350
18357 Or = 1350
18358 Or = 1350
18359 Or = 1350
18360 End
18361 End
18362End
18363' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'vGetFoodshelfRules'
18364GO
18365EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'vGetFoodshelfRules'
18366GO
18367USE [master]
18368GO
18369ALTER DATABASE [ChamplainCharityLLC] SET READ_WRITE
18370GO
18371