Skip to content
Advertisement

How to divide SQL results into equal parts using where clause and/or case statement?

Context: I am preparing this dataset to be used for an SSRS report, my goal is to split the list into about multiple parts (equally) for employees to receive. It will be used as a “task list” of sorts.

I have tried two different ways, both of which are causing issues.

Attempt #1 – Error is ‘incorrect syntax’:

Attempt #2 – Error is ‘incorrect syntax’:

Is there any way to accomplish this using my method or similar method?

Advertisement

Answer

In both of your attempts it seems to me you have WHEN and THEN values/statements reversed.

Something like this should work…

Also, if your ID is sequential you could just skip the whole ROW_NUMBER() logic and replace rn with ID like this…

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement