Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Grouping Code/Function that works in MS Access - Can't get it to work in SQL Server.

$
0
0
Howdy and Good Afternoon!

I'm in bit of a dilemma here re: this here snippet.

(*Works) MS Access:

GroupNum: Val(DCount("*","wodq","grp=" & [grp] & " And [ID]<" & [ID]))\4

(*Doesn't Work) SQL:

SELECT ID, FacilityPerStream, GRP, WOID,
(SELECT COUNT(*) AS ANiceCount
WHERE (dbo.wodq.GRP = dbo.wodq.GRP) AND (dbo.wodq.ID < dbo.wodq.ID)) / 4 AS GroupNum
FROM dbo.wodq

*DESIRED RESULT* (GroupNum to move +1 after every 4 w/ the same ID/Facility/GRP/WOID Combo) Example Below:

ID FacilityPerStream GRP WOID GroupNum
616 Transformer Technologies 29436 294 0
617 Transformer Technologies 29436 294 0
618 Transformer Technologies 29436 294 0
619 Transformer Technologies 29436 294 0
620 Transformer Technologies 29436 294 1

Any help would be loaded w/ appreciation.

Much Thanks!

*Attached a few pics for a better idea.

Attached Images
File Type: bmp Grp MSA.bmp (3.71 MB)
File Type: bmp Grp MSA Result.bmp (3.71 MB)
File Type: bmp Grp SQL.bmp (3.71 MB)

Viewing all articles
Browse latest Browse all 13329

Trending Articles