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 2000 Forums
 SQL Server Development (2000)
 sum query

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2007-08-06 : 03:53:15
i have a tablel ike this :
id codes
1 codes15
4 codes18
10 codes11
1 codes19
and i want to sum the total for each id.
the thing is that i need for to convert the codes to number
for example codes15=3,codes19=6.
i dont have them in a table so i want to translate them as part
of the query using a case statment.
and in the end i want the total for each id
how cna i do it?
thnaks in advance
peleg



Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-08-06 : 04:00:05
[code]SELECT id,
SUM(CASE codes
WHEN 'codes15' THEN 3
WHEN 'codes19' THEN 6
. . .
END)
FROM tablel
GROUP BY id[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -