Click here to Skip to main content
15,886,678 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a two table in SQL Server.One Table Name is tsim_hasta_say:

--group--HospitalCode--tsimHastaSay--Donem--tsimToplamHasta--id
  1.Grup    2784        8433         51       268391       3288
  2.Grup    676        7434          51       197388       3289
  1.Grup    4527        6563         51       158885       3290

And also we have a SMHASTANEDONEMVERILERI_Y table

--HospitalCode -- Donem -- Bagil -- Vaka--tigFrekans

   2784           51        154.23   1.23  300
   676            51        165.12   1.05  500 
   4527           51        123.32   1.32  400 

I want to calculate to paying using two tables.

Here its formulas:

A: indicates tsim_hasta_say.tsimHastaSay column
B: indicates SMHASTANEDONEMVERILERI_Y.tigFrekans column
C: indicates SMHASTANEDONEMVERILERI_Y.Bagil /SUM(SMHASTANEDONEMVERILERI_Y.Bagil) 
D: indicates SMHASTANEDONEMVERILERI_Y.Vaka /SUM(SMHASTANEDONEMVERILERI_Y.Vaka)

I want to calculate using this indicates shown in below:

STD_u=(A/B)
STD_e=(C+D)


How Can I calculate this using SQL SERVER Strored Procedure or Function?

Thanks
Posted
Updated 25-Feb-15 22:12pm
v3

1 solution

Try this:
SQL
SELECT A/B AS STD_u, (C1/C2)+(D1/D2) AS STD_e
FROM (
    SELECT ths.tsimHastaSay AS A, shd.tigFrekans AS B, shd.Bagil AS C1, (SELECT SUM(Bagil) FROM SMHASTANEDONEMVERILERI_Y) AS C2,
        shd.Vaka AS D1, (SELECT SUM(Vaka) FROM SMHASTANEDONEMVERILERI_Y) AS D2
    FROM tsimHastaSay AS ths INNER JOIN SMHASTANEDONEMVERILERI_Y AS shd ON ths.HospitalCode= shd.HospitalCode
) AS DT
 
Share this answer
 
Comments
Tahsin Çetin 26-Feb-15 5:01am    
Its return this error "ubquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression."
Maciej Los 26-Feb-15 6:09am    
Based on data you provided, the query executes without error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900