implemented army biz scenario#27
Conversation
ghost
left a comment
There was a problem hiding this comment.
Excellent! Some changes needed. See comments on PR, fix and resubmit.
| SoldierID int not null identity primary key, | ||
| FirstName varchar (30) not null constraint first_name_cannot_be_blank check (FirstName <> ''), | ||
| LastName varchar (30) not null constraint last_name_cannot_be_blank check (LastName <> ''), | ||
| SSN char (10) not null constraint ck_ssn_10_characters check (len (SSN) = 10) |
There was a problem hiding this comment.
len(SSN) is not enough when using char(10), as this adds extra spaces and it will always be 10 characters. Remove trailing/leading spaces and then check the len()
There was a problem hiding this comment.
I'm not quite sure what you mean. Can you explain?
There was a problem hiding this comment.
Can you tell me how to do it?
There was a problem hiding this comment.
Sorry, I thought it was necessary, but I tried it and saw that SQL is restricting to insert even when inserting spaces.
| SSN char (10) not null constraint ck_ssn_10_characters check (len (SSN) = 10) | ||
| constraint u_SSN_must_be_Unique unique, | ||
| DOB date not null , | ||
| DateOfEnlistment date not null, |
| PlaceOfResidence varchar (50) not null constraint ck_POR_cannot_be_blank check (PlaceOfResidence <> ''), | ||
| ServiceUnit varchar(20) not null constraint ck_serviceunit_navy_land_or_air check (ServiceUnit in ('Navy', 'Ground Force', 'Air Force')), | ||
| SoldierRank varchar (50) not null constraint ck_soldier_rank_cannot_be_blank check (SoldierRank <> ''), | ||
| IQLevel int not null, |
There was a problem hiding this comment.
Cannot be negative. And maybe don't allow more than max IQ level.
There was a problem hiding this comment.
What is the max IQ level? I tried to google but didn't get concrete answer
| order by IQLevel desc | ||
|
|
||
| --2) I need a list of all soldiers sorted by age at enlistment from high to low. Do not include columns that are not relevant to this list. | ||
| select LastName, FirstName, Age= year(DateOfEnlistment)-year(DOB) |
There was a problem hiding this comment.
There's a better way to check diff in dates.
| where YearRange = '2017-2019' | ||
| union select Recruitment =concat(YearRange, ', ', FirstName, ' ', LastName, ' - ', SSN, ' ', '(', DateOfEnlistment, ')', ', ', ServiceUnit) | ||
| from soldiers s | ||
| where YearRange = '2020-2022' |
There was a problem hiding this comment.
For example, year. It should be in sensible order.
| ServiceUnit varchar(20) not null constraint ck_serviceunit_navy_land_or_air check (ServiceUnit in ('Navy', 'Ground Force', 'Air Force')), | ||
| SoldierRank varchar (50) not null constraint ck_soldier_rank_cannot_be_blank check (SoldierRank <> ''), | ||
| IQLevel int not null, | ||
| constraint ck_Soldier_must_be_at_least_17 check (year(DateOfEnlistment) - year(DOB) >=17) |
There was a problem hiding this comment.
There's a better way to check diff in dates.
| SoldierID int not null identity primary key, | ||
| FirstName varchar (30) not null constraint first_name_cannot_be_blank check (FirstName <> ''), | ||
| LastName varchar (30) not null constraint last_name_cannot_be_blank check (LastName <> ''), | ||
| SSN char (10) not null constraint ck_ssn_10_characters check (len (SSN) = 10) |
There was a problem hiding this comment.
Sorry, I thought it was necessary, but I tried it and saw that SQL is restricting to insert even when inserting spaces.
| PlaceOfResidence varchar (50) not null constraint ck_POR_cannot_be_blank check (PlaceOfResidence <> ''), | ||
| ServiceUnit varchar(20) not null constraint ck_serviceunit_navy_land_or_air check (ServiceUnit in ('Navy', 'Ground Force', 'Air Force')), | ||
| SoldierRank varchar (50) not null constraint ck_soldier_rank_cannot_be_blank check (SoldierRank <> ''), | ||
| IQLevel int not null, |
| where YearRange = '2017-2019' | ||
| union select Recruitment =concat(YearRange, ', ', FirstName, ' ', LastName, ' - ', SSN, ' ', '(', DateOfEnlistment, ')', ', ', ServiceUnit) | ||
| from soldiers s | ||
| where YearRange = '2020-2022' |
There was a problem hiding this comment.
For example, year. It should be in sensible order.
I implemented the Army Biz-Scenario.