Lets eliminate something obvious. You Select Window to "sbStudents" But you say "There are two..., "Sandbox"and "sbSTUDENTS",.. Is that a typo?
Can't edit on iPad. Did you try it with the script debugger to see if it's bringing the proper window to the foreground?
According to the documentation, Select Window is case-insensitive. However, I did try it both ways, and (to answer your 2nd question), I used Show Dialog to display the result of Get(Window Name), which showed "Sandbox".
Set Variable [$screenWidth; Value:Get(ScreenWidth)]
Adjust Window [Resize to Fit]
Move/Resize Window [CurrentWindow; Left: 25]
Select Window [Name: "sbStudents"]
Set Variable [$windowWidth; Value: Get(WindowWidth)]
Set Variable [$windowName; Value: Get(WindowName)]
Show Custom Dialog ["Window name: " & "¶" & "Window width"; "Window width: " & $windowWidth]
And the window width is also that of "Sandbox". "sbSTUDENTS" is about 4 times wider than "Sandbox".
A couple things...
1) Try error trapping. Add the script step Set Error Capture [ On ] at the beginning of the script. After the Select Window script step, capture the result by adding Set Variable [ $error ; Get ( lastError ) ] and display $error in your custom dialog.
2) Are both these windows showing layouts from the same file?
I added the Set Error Capture [on] and Set Variable($error...) and it displayed nothing in the Show Custom Dialog.
And no, each window is showing a layout from a different file. Since they both showed up in the WindowNames results, I assumed I could simply select either one with the Select Window. I unchecked the "Current file only". I didn't see a way to specify a file other than "current file".
Oops! My mistake. My Show Custom Dialog had an extra period after $error, so it showed nothing. After removing that, it shows 112 "Window is missing".
After some research, I tried adding Open File [Open hidden; "sbSTUDENTS"] right before the Select Window["sbSTUDENTS"] but it didn't help. Well, it no longer gets the 112 error. But it still doesn't switch windows.
"Window is missing" would indicate that you haven't quite named the window accurately in your select window step and that would explain why you are getting stats from the other window. It can be something very simple and hard to spot in how you specify the window names.