[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 614
  • Last Modified:

Group By DatePart

Experts,
I've got the following SP, my intention is to pull out all the unique minutes (distinct) and i don't want duplicates, but i'm getting them!

DECLARE @Language_IKey INT
SET @Language_IKey =2
SELECT CASE WHEN @Language_IKey=2 THEN Sector_A ELSE Sector_E END AS Sector,Max(ValueDate) ValueDate,Max(Last) Last,Max(LastW) LastW
FROM Feed_KSE_KARS_Indices
WHERE SectorID=0
GROUP BY ValueDate,Sector_A,Sector_E,DATEPART(MINUTE,ValueDate)
ORDER BY ValueDate
0
feesu
Asked:
feesu
1 Solution
 
JulianvaCommented:
look at every column , it wont be exact duplicates.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
please try this:

DECLARE @Language_IKey INT
SET @Language_IKey =2

SELECT CASE WHEN @Language_IKey=2 THEN Sector_A ELSE Sector_E END AS Sector
,Max(ValueDate) ValueDate
,Max(Last) Last
,Max(LastW) LastW
FROM Feed_KSE_KARS_Indices
WHERE SectorID=0
GROUP BY CASE WHEN @Language_IKey=2 THEN Sector_A ELSE Sector_E END , DATEPART(MINUTE,ValueDate)
ORDER BY MAX(ValueDate)
0
 
feesuAuthor Commented:
Hi,
I finally figured it out.
I had to modify the grouping to:
GROUP BY DATEPART(HOUR,ValueDate),Sector_A,Sector_E,DATEPART(MINUTE,ValueDate)

It worked now.
Thanks alot.
0
 
Computer101Commented:
PAQed with points refunded (250)

Computer101
EE Admin
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now