Friday, 15 January 2010

sql - How to recursively work on input set -


Working on SQL Server 2008 R2 requires assistance on recursive charging calculation process. To write an SP, I need to calculate the base number of the head on the parameter top and given amount in my SP: Picture, from the input set describing my DB input set, to calculate the total charge amount on the given head Required,

Enter image details here

My Table script:

  create table [dbo]. [INSERE] [INSERT] [INN] [INSERE] NELL, [zodiac] [decimal] (decimal) (18, 6) tap, [easter] [bit] null, [head percent] [int] tap) [original] go INSERT [dbo ] [Test charge] ([Head], [zodiac], [incense], [head percentage]) value (100, cast (10.000000 AS decimal (18, 6)), 1, 103) INSERT [DBO]. [Test charge] ([head], [zodiac], [illustrator], [head percentage]) value (101, cast (10.000000 AS decimal (18, 6)), 1, 102) INSERT [DBO]. [Test charge] ([Head], [zodiac], [incense], [head percentage]) Price (102, cast (5 0.000000 AS decimal (18, 6)), 0, zero) INSERT [dbo]. [Test charge] ([head], [zodiac], [incense], [head percentage] value (103, cast (20.000000 AS decimal 18, 6)), 1, 101)  

Pole syntax used for revised values, the problem here is how to calculate on CTE.

  DECLARE @HeadID INT = 103; Receive the charge as headquarters (--- base selection chief, [head percentage] separately, the amount from the test amount where prominent = @ hedged union all - select the basis related record. Charge [ Head Percentage] In charge. In charge. Charge Charges on the Cta [Head Percentage] = Charge. Skip to MyStele CT Manner. Select from my CTE  

Suppose:

The parameter of my head is utility and the amount given is 400 SP 10 returns for my inputset-2 is wages and the amount given is 800 SP return 11 is my head parameter utility for my inputset-3 and given The amount returned is 500 SP return is 56.1

How to be repeated recursive on the input set.

Note: There is no need to think about my input, input set, already in DB.


No comments:

Post a Comment