| Author |
Topic |
|
sharona
Yak Posting Veteran
75 Posts |
Posted - 2011-09-21 : 14:40:39
|
| i have the following script where i would like it to update the columns _BCP and ABACCREATE TABLE #FINAL( ACTIONCODE VARCHAR (24), ROLECODE VARCHAR(4), FUNDCODE VARCHAR(4), _BCP VARCHAR(24), ABAC VARCHAR(24))-- GET ALL FUNDS ---SELECT DISTINCTR.ACTIONCODE,R.ROLECODE,R.FUNDCODEINTO #FUNDfrom dbo.RoleAction Rwhere R.FundCode IN ('_BCP','ABAC')GROUP BY R.ACTIONCODE,R.ROLECODE,R.FUNDCODE--Add all data to the final tableINSERT #Final( ACTIONCODE, ROLECODE, FUNDCODE)SELECT DISTINCT ACTIONCODE, ROLECODE, FUNDCODEFROM #FUND -- Update final tableUPDATE #FinalSET _BCP = R.ROLECODEFROM #fund r, #Final fWHERE f.FUNDCODE = r.FUNDCODE and f.ACTIONCODE = r.ACTIONCODE AND r.FUNDCODE = '_BCP'UPDATE #FinalSET ABAC = R.ROLECODEFROM #fund r, #Final fWHERE f.FUNDCODE = r.FUNDCODE and f.ACTIONCODE = r.ACTIONCODE AND r.FUNDCODE = 'ABAC'--Final selectselect distinct ACTIONCODE, _BCP, ABACfrom #FINALgroup byACTIONCODE, _BCP, ABAC--DROP TABLE #FUND--DROP TABLE #Finali keep getting duplicated actioncodesACTIONCODE --------_BCP ------ABACAddCashAccounts -----NULL -------FR AddCashAccounts -----ITA -------NULLwhat i would like to see isACTIONCODE --------_BCP-------- ABACAddCashAccounts --------ITA ------ FR any idea how to accomplish this. i have written successful update scripts to |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-21 : 22:31:54
|
that means the insert itself has inserted multiple records per ACTIONCODE in #Final. can you post what below query returns?SELECT DISTINCTACTIONCODE,ROLECODE,FUNDCODEFROM #FUND ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sharona
Yak Posting Veteran
75 Posts |
Posted - 2011-09-22 : 08:25:48
|
| these are the resultseach fund can have multiple actions. each action can exist in multiple fundsACTIONCODE --------ROLECODE -------FUNDCODEAddCashAccounts ---------FR ------- _BCPAddCashAccounts ---------FR ------- ABACAddCashAccounts ---------ITA -------- _BCPAddCashAccounts ---------ITA -------- ABAC |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-22 : 12:09:21
|
| you want ROLECODE and FUNDCODE side by side with pivoted values? (_BCP,ABAC etc)------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sharona
Yak Posting Veteran
75 Posts |
Posted - 2011-09-22 : 12:40:05
|
| yes |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-22 : 13:07:39
|
| what significance does it make?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-22 : 13:09:10
|
| also provided you group by ROLECODE,FUNDCODE which have more than one distinct combination for each ACTIONCODE then how do you think you can reduce them to single record? thats not possible if you want to return ROLECODE,FUNDCODE along with pivoted values.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sharona
Yak Posting Veteran
75 Posts |
Posted - 2011-09-22 : 14:11:38
|
| i actually got it to work they way i want to see it, ACTIONCODE _BCP ABACAddCashAccounts ITA FR AddCounterparty TDM ITA AddEditBroker ID TDM AddNewDeal SET ITA AddServicer ITA TDM how i was able to accomplish this was to remove some joins in my update statmentnow i just would like to be able to put in the column multiple valuesso for _BCP AddCashAccounts should show in _BCP columnITA,FR, EO. multiple permissions for code and action. is there a way to do that? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-22 : 22:48:11
|
| sorry can you post how the output would be in that case?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|