dbTalk Databases Forums  

Aggregate Function in Set List of Update Statement

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Aggregate Function in Set List of Update Statement in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Robert Hamilton
 
Posts: n/a

Default Aggregate Function in Set List of Update Statement - 05-11-2005 , 03:10 PM






I want to use an aggregate function (Count) to set a field value in an Update
statement. I get an error that states this is not allowed. I could do the
aggregation in a view and then update the field value based on the view, but
is there a better? Following is what I want to do:

UPDATE PCP_Measures
SET Med_Claim_Memb_Cnt = COUNT(DISTINCT CLAIM_MASTERS.MEMBID)
FROM CLAIM_MASTERS
WHERE
CLAIM_MASTERS.PCP = PCP_Measures.PCP
AND CLAIM_MASTERS.LOB = PCP_Measures.LOB
GROUP BY
CLAIM_MASTERS.PCP,
CLAIM_MASTERS.LOB


Reply With Quote
  #2  
Old   
Ilya Margolin
 
Posts: n/a

Default Re: Aggregate Function in Set List of Update Statement - 05-12-2005 , 07:23 AM






Robert,

UPDATE PCP_Measures
SET Med_Claim_Memb_Cnt = (SELECT COUNT(DISTINCT CLAIM_MASTERS.MEMBID)
FROM CLAIM_MASTERS
WHERE
CLAIM_MASTERS.PCP =
PCP_Measures.PCP
AND CLAIM_MASTERS.LOB =
PCP_Measures.LOB
)



Ilya

"Robert Hamilton" <RobertHamilton (AT) discussions (DOT) microsoft.com> wrote in
message news:371AE6A1-BA7B-41A7-A93D-D726EE12E0DE (AT) microsoft (DOT) com...
Quote:
I want to use an aggregate function (Count) to set a field value in an
Update
statement. I get an error that states this is not allowed. I could do the
aggregation in a view and then update the field value based on the view,
but
is there a better? Following is what I want to do:

UPDATE PCP_Measures
SET Med_Claim_Memb_Cnt = COUNT(DISTINCT CLAIM_MASTERS.MEMBID)
FROM CLAIM_MASTERS
WHERE
CLAIM_MASTERS.PCP = PCP_Measures.PCP
AND CLAIM_MASTERS.LOB = PCP_Measures.LOB
GROUP BY
CLAIM_MASTERS.PCP,
CLAIM_MASTERS.LOB




Reply With Quote
  #3  
Old   
Robert Hamilton
 
Posts: n/a

Default Re: Aggregate Function in Set List of Update Statement - 05-12-2005 , 06:10 PM



Thanks!

"Ilya Margolin" wrote:

Quote:
Robert,

UPDATE PCP_Measures
SET Med_Claim_Memb_Cnt = (SELECT COUNT(DISTINCT CLAIM_MASTERS.MEMBID)
FROM CLAIM_MASTERS
WHERE
CLAIM_MASTERS.PCP =
PCP_Measures.PCP
AND CLAIM_MASTERS.LOB =
PCP_Measures.LOB
)



Ilya

"Robert Hamilton" <RobertHamilton (AT) discussions (DOT) microsoft.com> wrote in
message news:371AE6A1-BA7B-41A7-A93D-D726EE12E0DE (AT) microsoft (DOT) com...
I want to use an aggregate function (Count) to set a field value in an
Update
statement. I get an error that states this is not allowed. I could do the
aggregation in a view and then update the field value based on the view,
but
is there a better? Following is what I want to do:

UPDATE PCP_Measures
SET Med_Claim_Memb_Cnt = COUNT(DISTINCT CLAIM_MASTERS.MEMBID)
FROM CLAIM_MASTERS
WHERE
CLAIM_MASTERS.PCP = PCP_Measures.PCP
AND CLAIM_MASTERS.LOB = PCP_Measures.LOB
GROUP BY
CLAIM_MASTERS.PCP,
CLAIM_MASTERS.LOB





Reply With Quote
  #4  
Old   
Robert Hamilton
 
Posts: n/a

Default Re: Aggregate Function in Set List of Update Statement - 05-16-2005 , 12:47 PM



Hi Ilya,

I think you suggestion is in the right ballpark, but I still can't get it to
work properly. What happens when I use your suggestion is that all update
fields are updated to the result of the last combination of LOB/PCP. Any
ideas?

"Ilya Margolin" wrote:

Quote:
Robert,

UPDATE PCP_Measures
SET Med_Claim_Memb_Cnt = (SELECT COUNT(DISTINCT CLAIM_MASTERS.MEMBID)
FROM CLAIM_MASTERS
WHERE
CLAIM_MASTERS.PCP =
PCP_Measures.PCP
AND CLAIM_MASTERS.LOB =
PCP_Measures.LOB
)



Ilya

"Robert Hamilton" <RobertHamilton (AT) discussions (DOT) microsoft.com> wrote in
message news:371AE6A1-BA7B-41A7-A93D-D726EE12E0DE (AT) microsoft (DOT) com...
I want to use an aggregate function (Count) to set a field value in an
Update
statement. I get an error that states this is not allowed. I could do the
aggregation in a view and then update the field value based on the view,
but
is there a better? Following is what I want to do:

UPDATE PCP_Measures
SET Med_Claim_Memb_Cnt = COUNT(DISTINCT CLAIM_MASTERS.MEMBID)
FROM CLAIM_MASTERS
WHERE
CLAIM_MASTERS.PCP = PCP_Measures.PCP
AND CLAIM_MASTERS.LOB = PCP_Measures.LOB
GROUP BY
CLAIM_MASTERS.PCP,
CLAIM_MASTERS.LOB





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.