In my office, I often have people come over to my desk and say something like “Zach, I’ve got a SQL Challenge for you…”, and I love it. It gives me a chance to just take a break from what I’m doing and engage my brain in something different for a few minutes.
I thought it might be fun to post some of these challenges up on my site, just to see what people come up with – so, here’s the latest:
SQL Challenge: Snap To Nearest Factor
A user will select a whole number between 1 and 100 – You need to be able to “snap” that number to the nearest factor of another number.
Example one – Using a factor of 5 and a number of 19 you should return 20, which is the nearest factor of 5 to 19.
Example two – Using a factor of 9 and a number of 41, you should return 45.
Lets see what you can come up with. I’ll post my attempt in the comments at a later date as to not spoil the fun.
DECLARE @Factor INT = 5 DECLARE @Num INT = 19 |













I love it when Zach thinks it’s a game instead of realising he’s doing my work work me. ;)
PS the working solution has now made it into a real working UI component. Soopercoolness!