carl Brooks carl Brooks - 6 months ago 24
SQL Question

SQL SERVER MOD equivalent

Simple question in regards to MOD alternative in SQL SERVER. I know it the SQL SERVER MOD is written as % but that usually requires a number % number. My question is how can I use the % when I have these clauses in the code:

SELECT NULL,
LeagueID,
COUNT(1),
1,
COUNT(1),
1
FROM Team
GROUP BY LeagueID
HAVING MOD( COUNT(1), 2 ) > 0


OR

CASE away_idx
WHEN num_teams + num_fake - 1
THEN away_idx
ELSE MOD( away_idx + 1, num_teams + num_fake - 1 )
END

Answer

don't quite understand the logic of your query.

anyway . . . here is how you used the MOD %

SELECT   NULL, LeagueID, COUNT(1), 1, COUNT(1), 1 
FROM     Team 
GROUP BY LeagueID 
HAVING   COUNT(1) % 2  > 0