Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jung1975
Aged Yak Warrior
503 Posts |
Posted - 2002-12-17 : 14:42:12
|
| Hello All, I am tryintg to run this scrip to use two aggregate functions(count and sum) at the same time. But It keep giving me the error message : Ambiguous column name 'policy_key'. I thought I am using the valid ANSI join syntax to void the ambiguities on policy_key. Any information would be appreciated..GOBEGIN CREATE TABLE #ACCTS ( policy_key int, nbr_policy_key int ) INSERT #ACCTS select policy_key,count(policy_key) from policy LEFT JOIN xref_policy_location ON (policy.policy_key = xref_policy_location.policy_key) LEFT JOIN Location ON (location.location_key = xref_policy_location) where location.location_key = #### Group by policy_key Order by policy_key ENDGOSelect CAST(count(policy_key) As Real)/(select sum(nbr_policy_key)as real from #ACCTS) As percentagepop from policyorder by policy_keyGODrop TABLE #ACCTS |
|
|
1fred
Posting Yak Master
158 Posts |
Posted - 2002-12-17 : 14:47:47
|
| INSERT #ACCTS select policy.policy_key,count(policy_key) from policy LEFT JOIN xref_policy_location ON (policy.policy_key = xref_policy_location.policy_key) LEFT JOIN Location ON (location.location_key = xref_policy_location) where location.location_key = #### Group by policy.policy_key Order by policy.policy_key If the same key is existing in both table on the join, you need to specify the table location in your query |
 |
|
|
mohdowais
Sheikh of Yak Knowledge
1456 Posts |
Posted - 2002-12-18 : 01:27:22
|
quote: INSERT #ACCTS select policy.policy_key,count(policy.policy_key) from policy LEFT JOIN xref_policy_location ON (policy.policy_key = xref_policy_location.policy_key) LEFT JOIN Location ON (location.location_key = xref_policy_location) where location.location_key = #### Group by policy.policy_key Order by policy.policy_key If the same key is existing in both table on the join, you need to specify the table location in your query
I think the COUNT() will also need a tablename qualifier before the column name.OS |
 |
|
|
|
|
|