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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Count problem

Author  Topic 

zganjei
Starting Member

3 Posts

Posted - 2013-01-31 : 00:53:04
Hello all
I have a problem saving count() result in a column.
I use this query

SELECT COUNT(*) AS "edge_weight"
FROM [socialDB].[dbo].[final]
GROUP BY [socialDB].[dbo].[final].[author_key_from] ,
[socialDB].[dbo].[final].[author_key_to]

the table has edge_weight column and the values are computed correctly and are printed in the console but they don't update the column.
what should I do?

p.s : I have tested edge_wight,'edge_weight' and "edge_weight"! but no difference

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-31 : 00:56:48
if you want to update this in table. you need something like

UPDATE t
SET t.edge_weight = tmp.edge_weight
FROM [socialDB].[dbo].[final] t
INNER JOIN
(
SELECT [socialDB].[dbo].[final].[author_key_from] ,
[socialDB].[dbo].[final].[author_key_to],
COUNT(*) AS "edge_weight"
FROM [socialDB].[dbo].[final]
GROUP BY [socialDB].[dbo].[final].[author_key_from] ,
[socialDB].[dbo].[final].[author_key_to]
)tmp
ON tmp.[author_key_from] = t.[author_key_from]
AND tmp.[author_key_to] = t.[author_key_to]


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

zganjei
Starting Member

3 Posts

Posted - 2013-01-31 : 01:57:55
Thank you for your correct & quick answer :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-31 : 01:59:26
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -