

(select sum(price) from t_product b where b.xh <= a.xh) as totalprice
from t_product a

(select sum(price) from t_product b where b.xh < a.xh) as totalprice
from t_product a

(case when totalprice is null then price else totalprice end ) as totalprice
from
(select a.xh, (select sum(price) from t_product b where b.xh < a.xh) as totalprice , a.price
from t_product a) x
from t_product a
begin
return (select
(case when totalprice is null then @price else totalprice end) as totalprice
from ( select sum(price) as totalprice from t_product where xh < @xh) x)
end
from t_product
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[t_product]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[t_product](
[xh] [int] NOT NULL,
[price] [int] NOT NULL,
CONSTRAINT [PK_t_product] PRIMARY KEY CLUSTERED
(
[xh] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
















