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 |
Nicolas010
Starting Member
2 Posts |
Posted - 2011-02-18 : 11:02:20
|
Hi all, im new here and im working with asp .net and SQL SERVER 2005. The web page use data from the SQL SERVER and what i need to do i some kind of calculator to get the salary of the employees according to the hours he worked and with the type of product he worked on. The first table is ProductoIdProducto Producto1 SVA12 SVA23 UC14 UC25 CC16 CC27 CC38 CC49 CC510 CC611 OT112 OT213 OT314 OT415 OT516 OT6Second Table is CategoriaIdcategoria IdProducto Nombre Value1 1 qwe 0.202 1 BD 0.203 1 TMP 0.204 1 BAS 0.105 1 HW / SW 0.306 2 J2EE 0.357 2 Web 0.308 2 CCXML E 0.159 2 BD 0.2010 3 Prologic 0.1011 3 vvv 0.6012 3 Voice 0.1513 3 IP 0.1514 4 Meridian 0.4015 4 BCM 0.3016 4 Voice 0.3017 5 CMS 0.3018 5 AES 0.3019 5 IVR 0.2020 5 AIC 0.1021 5 Office 0.1022 6 SECC 0.2023 6 TAPI 0.4024 6 CC 0.4025 7 PA 1.0026 8 PAB 1.0027 9 Definir 1.0028 10 Verint 1.0029 11 Mosaix 1.0030 12 VP 1.0031 13 Dato 1.0032 14 Elearn 1.0033 15 Dato 1.0034 16 PA 1.00Third Table is ConocimientoIdemployee IdProducto IdCategoria Value Expertise Total Value12.697 1 1 0.2 0 0.0012.697 1 2 0.2 2 0.4012.697 1 3 0.2 0 0.0012.697 1 4 0.1 0 0.0012.697 1 5 0.3 0 0.0012.697 2 6 0.35 1 0.3512.697 2 7 0.3 0 0.0012.697 2 8 0.15 0 0.0012.697 2 9 0.2 2 0.4012.697 3 10 0.1 0 0.0012.697 3 11 0.6 0 0.0012.697 3 12 0.15 0 0.0012.697 3 13 0.15 0 0.0012.697 4 14 0.4 0 0.0012.697 4 15 0.3 0 0.0012.697 4 16 0.3 0 0.0012.697 5 17 0.3 0 0.0012.697 5 18 0.3 0 0.0012.697 5 19 0.2 0 0.0012.697 5 20 0.1 0 0.0012.697 5 21 0.1 0 0.0012.697 6 22 0.2 0 0.0012.697 6 23 0.4 0 0.0012.697 6 24 0.4 0 0.0012.697 7 25 1 0 0.0012.697 8 26 1 0 0.0012.697 9 27 1 0 0.0012.697 10 28 1 0 0.0012.697 11 29 1 0 0.0012.697 12 30 1 0 0.0012.697 13 31 1 0 0.0012.697 14 32 1 0 0.0012.697 15 33 1 0 0.0012.697 16 34 1 0 0.00As you can see, there is a "Total Value" in the third table, and what i have to do is "sum this value where IdProducto = '1'. So i sum the example on the table, the sum for IdProduct = 1 will be: 0.40. And with this value i can determine his payment. Please i need this and it has come very complicated to me. Any dudes please post. I have something like this so far. UPDATE Ax50_HorasRegistradasSET ValorRegla = ( SELECT CASE WHEN Ax50_HorasRegistradas.Producto= '1' and Ax50_HorasRegistradas.Rut = '12.697' THEN SUM(sxb_Conocimiento.Resultado) END AS SVA1 FROM Ax50_HorasRegistradas AS Ax50_HorasRegistradas JOIN sxb_Conocimiento AS sxb_Conocimiento ON Ax50_HorasRegistradas.Rut = sxb_conocimiento.rut WHERE Ax50_HorasRegistradas.Rut = sxb_conocimiento.rut GROUP BY Ax50_HorasRegistradas.LINEPROPERTYID, Ax50_HorasRegistradas.Rut) |
|
KlausEngel
Yak Posting Veteran
85 Posts |
Posted - 2011-02-18 : 12:00:28
|
Not sure I understand exactly what you need but in order to get the total amount per employee and product you just need to sum in your third table:SELECT Idemployee, iDProducto, SUM([Total Value]) as TotalValueFROM ConocimientoGROUP BY Idemployee, iDProducto |
 |
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-02-18 : 14:34:42
|
well using the above structure can you name the columns as highlighted in your following statement? i need to do i some kind of calculator to get the salary of the employees according to the hours he worked and with the type of product he worked on. Even better if you come up with only two or three rows for each of the above table and the desired output format you are looking for..Cheers!MIK |
 |
|
Nicolas010
Starting Member
2 Posts |
Posted - 2011-02-18 : 15:18:02
|
quote: Originally posted by KlausEngel Not sure I understand exactly what you need but in order to get the total amount per employee and product you just need to sum in your third table:SELECT Idemployee, iDProducto, SUM([Total Value]) as TotalValueFROM ConocimientoGROUP BY Idemployee, iDProducto
Hi and thanks fow answering. Your sql statement is good and i came to something like these...UPDATE Ax50_HorasRegistradas SET Expertise =(SELECT sxb_Conocimiento.Rut, sxb_conocimiento.IdProducto, Sum(sxb_Conocimiento.Resultado)FROM sxb_Conocimiento as sxb_ConocimientoJOIN Ax50_HorasRegistradas as Ax50_HorasRegistradasON sxb_Conocimiento.Rut = Ax50_HorasRegistradas.RutWHERE sxb_Conocimiento.Rut IS NOT NULL AND Ax50_HorasRegistradas.rut = sxb_Conocimiento.Rut AND sxb_Conocimiento.IdProducto = 6GROUP BY sxb_Conocimiento.RUT, sxb_Conocimiento.IdProducto)FROM sxb_Conocimiento as sxb_ConocimientoJOIN Ax50_HorasRegistradas as Ax50_HorasRegistradasON sxb_Conocimiento.Rut = Ax50_HorasRegistradas.RutWHERE Ax50_HorasRegistradas.rut = sxb_Conocimiento.Rut but i get this error: Only one expression can be specified in the select list when the subquery is not introduced with EXISTS. |
 |
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-02-20 : 14:02:21
|
expertise = expects one value from the subquery ... where your sub query returns more than one .. sxb_conocimiento.Rut(first one), sxb_conocimiento..idProducto (second one) and sum(sxb)conocimiento.Resultado Third One Its similar like you are trying to assign multiple values at a time to a Variable e.g. @x = 1 and 2 and 3 ... and N Cheers MIK |
 |
|
|
|
|
|
|