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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Count problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

zganjei
Starting Member

3 Posts

Posted - 01/31/2013 :  00:53:04  Show Profile  Reply with Quote
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

India
52249 Posts

Posted - 01/31/2013 :  00:56:48  Show Profile  Reply with Quote
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 - 01/31/2013 :  01:57:55  Show Profile  Reply with Quote
Thank you for your correct & quick answer :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 01/31/2013 :  01:59:26  Show Profile  Reply with Quote
welcome

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

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.03 seconds. Powered By: Snitz Forums 2000