SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SELECT STATEMENT NOT WORKING
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

divan
Posting Yak Master

153 Posts

Posted - 04/11/2013 :  12:57:06  Show Profile  Reply with Quote
I have a table CLAIM_FNCL_TRANS that has the following fields

OCCUR_NUMBER ACCOUNT_CD
18 E
18 I
18 I
18 E
18 E
18 E
18 E
18 E

And I run the following script

DROP TABLE #TEMP1
SELECT C.OCCUR_NUMBER
INTO #TEMP1---,O.OCCUR_STATUS_CD
FROM CLAIM_FNCL_TRANS C
GROUP BY C.OCCUR_NUMBER HAVING MAX (C.ACCOUNT_CD) = 'I'
SELECT * FROM #TEMP1

and Occur_number 18 does not get selected..

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 04/11/2013 :  13:51:57  Show Profile  Reply with Quote
Say what?
DECLARE @CLAIM_FNCL_TRANS TABLE (OCCUR_NUMBER INT, ACCOUNT_CD CHAR(1))
INSERT @CLAIM_FNCL_TRANS VALUES
(18, 'E'),
(18, 'I'),
(18, 'I'),
(18, 'E'),
(18, 'E'),
(18, 'E'),
(18, 'E'),
(18, 'E')


SELECT C.OCCUR_NUMBER
FROM @CLAIM_FNCL_TRANS C
GROUP BY C.OCCUR_NUMBER HAVING MAX (C.ACCOUNT_CD) = 'I'

-- Result
OCCUR_NUMBER
------------
18

(1 row(s) affected)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 04/12/2013 :  04:37:51  Show Profile  Reply with Quote
do you've any other values also present for ACCOUNT_CD which you've not shown us?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000