Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases

Anthony Rubino
Anthony Rubino
1,334 Points

SQL Playground - Stage 4 practice: Format Output with multiple conditions

In the SQL Playground - Stage 4 practice: Format Output task we are asked to format dates in all the loans table in the UK format without the year. Can i do this in one statement with multiple conditionals? Seems like i need to write a statement for each column since i need to check if the value is null first. Below is what i've used but i wonder if there is a more efficient method.

UPDATE loans SET loaned_on = STRFTIME("%d/%m", loaned_on) WHERE loaned_on IS NOT NULL; UPDATE loans SET return_by = STRFTIME("%d/%m", return_by) WHERE return_by IS NOT NULL; UPDATE loans SET returned_on = STRFTIME("%d/%m", returned_on) WHERE returned_on IS NOT NULL;

1 Answer

Steven Parker
Steven Parker
229,708 Points

I don't know any way to make the individual sets in a single UPDATE statement conditional on different tests. Are you sure that's a requirement of the exercise?

It might be helpful to provide a link the the course page you are working with.