Skip to content

I did the work for the Army biz scenario#44

Open
ChanaCohen3896 wants to merge 2 commits into
CPU-Code-School:mainfrom
ChanaCohen3896:main
Open

I did the work for the Army biz scenario#44
ChanaCohen3896 wants to merge 2 commits into
CPU-Code-School:mainfrom
ChanaCohen3896:main

Conversation

@ChanaCohen3896
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work! See comments, fix and resubmit.

Comment thread 2 table.sql Outdated
constraint c_Soldiers_soldier_last_name_cannot_be_blank check(SoldierLastName <> ''),
SoldierFirstName varchar(25) not null
constraint c_Soldiers_soldier_first_name_cannot_be_blank check(SoldierFirstName <> ''),
SoldierSSN char(10) not null
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SSN must be in specific format. It should be 8 digits followed by a hyphen followed by one digit.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. I deleted the not blank constraint also.

Comment thread 2 table.sql Outdated
constraint c_Soldiers_soldier_SSN_cannot_be_blank check(SoldierSSN <> '')
constraint u_Soldiers_soldier_SSN_ unique,
SoldierDOB date not null
constraint c_Soldiers_soldier_DOB_cannot_be_blank check(SoldierDOB <> ''),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you allow a soldier to be born on 01/01/1900? This is the date returned from a blank date.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted the DOB cannot be blank constraint

Comment thread 2 table.sql Outdated
SoldierRank varchar(25) not null
constraint c_Soldier_soldier_rank_cannot_be_blank check(SoldierRank <> ''),
SoldierIQ int not null
constraint c_Soldiers_soldier_IQ_cannot_be_blank check(SoldierIQ <> ''),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused here. Do you allow 0 IQ? This constraint blocks 0 but the next one allows.

Why do you even have this constraint? This is a int column and this constraint is for varchars.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted the not blank constraint.

Comment thread 2 table.sql Outdated
constraint c_Soldier_soldier_rank_cannot_be_blank check(SoldierRank <> ''),
SoldierIQ int not null
constraint c_Soldiers_soldier_IQ_cannot_be_blank check(SoldierIQ <> ''),
constraint c_Soldiers_soldier_IQ_cannot_be_negative check(SoldierIQ >= 0),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not allow 0.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I switched this constraint to soldier IQ must be greater than 0.

Comment thread 2 table.sql Outdated
SoldierIQ int not null
constraint c_Soldiers_soldier_IQ_cannot_be_blank check(SoldierIQ <> ''),
constraint c_Soldiers_soldier_IQ_cannot_be_negative check(SoldierIQ >= 0),
SoldierAgeAtEnlistment as datepart(year, SoldierDateOfEnlistment) - datepart(year, SoldierDOB) persisted not null,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip: Use datediff(). You don't need the extra not null constraint, both columns don't allow null and this is a computed column.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I fixed it.

Comment thread 2 table.sql Outdated
constraint c_Soldiers_soldier_IQ_cannot_be_blank check(SoldierIQ <> ''),
constraint c_Soldiers_soldier_IQ_cannot_be_negative check(SoldierIQ >= 0),
SoldierAgeAtEnlistment as datepart(year, SoldierDateOfEnlistment) - datepart(year, SoldierDOB) persisted not null,
constraint c_Soldiers_soldier_date_of_enlistment_cannot_be_before_17_years_after_soldier_DOB check(datepart(year, SoldierDateOfEnlistment) >= datepart(year, SoldierDOB) + 17)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a constraint on the computed column not to allow an age less than 17.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thank you. I fixed it.

Comment thread 4 reports.sql Outdated
(This should be done by using a union select and adding a literal column for year range.)
*/

select concat('2017-2019', ' ', s.SoldierFirstName, ' ', s.SoldierLastName, ' - ', s.SoldierSSN, ' (', s.SoldierDateOfEnlistment, ')', ', ', s.ServiceUnit)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add column name.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread 4 reports.sql Outdated

select concat('2017-2019', ' ', s.SoldierFirstName, ' ', s.SoldierLastName, ' - ', s.SoldierSSN, ' (', s.SoldierDateOfEnlistment, ')', ', ', s.ServiceUnit)
from Soldiers s
where datepart(year, s.SoldierDateOfEnlistment) between 2017 and 2019
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip: Use year() function.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Author

@ChanaCohen3896 ChanaCohen3896 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I went through all the comments and fixed the table and reports.

Comment thread 4 reports.sql Outdated
(This should be done by using a union select and adding a literal column for year range.)
*/

select concat('2017-2019', ' ', s.SoldierFirstName, ' ', s.SoldierLastName, ' - ', s.SoldierSSN, ' (', s.SoldierDateOfEnlistment, ')', ', ', s.ServiceUnit)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread 4 reports.sql Outdated

select concat('2017-2019', ' ', s.SoldierFirstName, ' ', s.SoldierLastName, ' - ', s.SoldierSSN, ' (', s.SoldierDateOfEnlistment, ')', ', ', s.ServiceUnit)
from Soldiers s
where datepart(year, s.SoldierDateOfEnlistment) between 2017 and 2019
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread 2 table.sql Outdated
constraint c_Soldiers_soldier_last_name_cannot_be_blank check(SoldierLastName <> ''),
SoldierFirstName varchar(25) not null
constraint c_Soldiers_soldier_first_name_cannot_be_blank check(SoldierFirstName <> ''),
SoldierSSN char(10) not null
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. I deleted the not blank constraint also.

Comment thread 2 table.sql Outdated
constraint c_Soldiers_soldier_SSN_cannot_be_blank check(SoldierSSN <> '')
constraint u_Soldiers_soldier_SSN_ unique,
SoldierDOB date not null
constraint c_Soldiers_soldier_DOB_cannot_be_blank check(SoldierDOB <> ''),
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted the DOB cannot be blank constraint

Comment thread 2 table.sql Outdated
SoldierRank varchar(25) not null
constraint c_Soldier_soldier_rank_cannot_be_blank check(SoldierRank <> ''),
SoldierIQ int not null
constraint c_Soldiers_soldier_IQ_cannot_be_blank check(SoldierIQ <> ''),
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted the not blank constraint.

Comment thread 2 table.sql Outdated
constraint c_Soldier_soldier_rank_cannot_be_blank check(SoldierRank <> ''),
SoldierIQ int not null
constraint c_Soldiers_soldier_IQ_cannot_be_blank check(SoldierIQ <> ''),
constraint c_Soldiers_soldier_IQ_cannot_be_negative check(SoldierIQ >= 0),
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I switched this constraint to soldier IQ must be greater than 0.

Comment thread 2 table.sql Outdated
SoldierIQ int not null
constraint c_Soldiers_soldier_IQ_cannot_be_blank check(SoldierIQ <> ''),
constraint c_Soldiers_soldier_IQ_cannot_be_negative check(SoldierIQ >= 0),
SoldierAgeAtEnlistment as datepart(year, SoldierDateOfEnlistment) - datepart(year, SoldierDOB) persisted not null,
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I fixed it.

Comment thread 2 table.sql Outdated
constraint c_Soldiers_soldier_IQ_cannot_be_blank check(SoldierIQ <> ''),
constraint c_Soldiers_soldier_IQ_cannot_be_negative check(SoldierIQ >= 0),
SoldierAgeAtEnlistment as datepart(year, SoldierDateOfEnlistment) - datepart(year, SoldierDOB) persisted not null,
constraint c_Soldiers_soldier_date_of_enlistment_cannot_be_before_17_years_after_soldier_DOB check(datepart(year, SoldierDateOfEnlistment) >= datepart(year, SoldierDOB) + 17)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thank you. I fixed it.

Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! 100% All good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant