473,581 Members | 3,067 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help for best logic

Hai all,

My problem not just releated to sql.
My problem is releated to good logic.

I should not this type of questions hear.
But just i am trying. If any body gave suggestions, or help i am the
lockest person that time.

I just started working with sql server 3 Months back.
please excuse any errors in code.
The following Code is working fine with one type of placement. but i
don't require that. I have different business logic.
Here is Actual Trinary Tree:
because of space scercity i am spliting in to rows
1 --0 Level
2 3
5 6 8 9 10 11
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

4 --1 level
12 13 14 --2 level
32 33 34 35 36 37 38 39 40 -- 3 level
and so on
1) business logic: Existing member must sponser new members (except
first member) and he can sponsor n number of members and new member has
to place under his childrens list only.

And I need this way of placement only. I don't want to store in database
who is sponsered. No need to sponser for me because if i know the
placement no of any member i can get his parents parents by a
mathematical formula.

1) if no members is there one get placed fine
2) Assume 1 sponsered 40 members
3) by execting this code i will get 2 fine
4) next time i will get 3 fine,next 4 fine,next time 5,next time
8,11,6,9,12,7,1 0,13 upto hear fine(No change)
5) next 14,17,20,23,26, 29,32,35,38,15, 18,21,24,27,30, 33,36
39,16,19,22,25, 28,31,34,37,40, 41 this placement is wrong

6) i need 14,23,32,17,26, 35,20,29,38,15, 24,33,18,27,36, 21,30,39,16,25
34,19,28,37,22, 31,40,41 so on

Table Name: MemCardDetails
Fields: MemberID (Numeric(32,0) Primary key
Name (Varchar(40))
CREATE Procedure PBNewID
@SponserID as Numeric(36,0),
@AllocNo as Numeric(36,0) OUTPUT,


DECLARE @fMemberId as Numeric(36,0),@ mMemberID as Numeric(36,0),@ temp1
as Numeric(36,0),@ temp2 as Numeric(36,0)
DECLARE @iLevel as SmallInt,@iCoun ter as Numeric(36,0),@ nextNo as
--If there is no members Of it is the first member LEVEL is 0
--Only one member in this level
SET @AllocNo=1
Return 0

--Level 0 contiains 1 member
--Level 1 contains 3 members
--Level 2 contains 9 Members
--Level n contains power(3,Level)

Set @iLevel = 1
While @iLevel<=50

--dbo.fnMinus(@iL evel) function returns Middle number in this level
--round(total numbers in this level/2)-1
--Level 0 I won't call
--Level 1 returns 1
--Level 2 returns 4
--Level 3 returns 13 so on
SET @mMemberID = dbo.fnMinus(@iL evel)

--getting the first number in this level
--Level 1 returns 2
--level 2 returns 5
--level 3 returns 14 so on
Set @fMemberId = @SponserID * Power(3,@iLevel ) - @mMemberId
--Checking the first number in that level is empty
IF NOT EXISTS (Select MemberId from MemCardDetails where
MemberId=@fMemb erId)
SET @AllocNo=@fMemb erId
Return 0
--if first member in that level is already alloted
--assigning the variable with that
SET @temp1 = @fMemberId
SET @temp2 = @fMemberId
SET @iCounter=@fMem berID

--Checking until total no of members in that level is alloted
While @iCounter<@Spon serID * Power(3,@iLevel ) +@mMemberId
--incrementing 3 so next member will go under his sibling
SET @NextNo = @temp1 + 3
--Checking if our next no will exceeds max memberId in that level
If @NextNo > @SponserID *Power(3 , @iLevel) + @mMemberID

SET @NextNo= @temp2 + 1
SET @temp2 = @temp2 + 1
SET @temp1 = @temp2
SET @temp1 = @NextNo
If Not Exists (Select MemberId from MemCardDetails where
MemberId=@NextN o)
SET @AllocNo=@NextN o

SET @iCounter=@iCou nter+1
SET @iLevel = @iLevel + 1

thx for a lot. If any body wants personally help me my mail id is
po***********@y ahoo.co.in (just tell when they can available)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
0 1346

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Jack Addington | last post by:
I have a base form and a base logic class. Each has to know of the other. I'm then inheriting to create descendant form and descendant logic which extend both objects and again have to know of each other. I'm getting mixed up in the syntax/technique on how to refer to the references generically in the code. I want to be able to always call...
by: Art | last post by:
Hi folks, I'm writing a traditional desktop app using VB.NET and am stumbling over what seems like a very basic question: My app does not need to be connected to a server or another computer. It just runs locally. So what is the best way to store user-entered data? The app is like an address book, where users can enter contacts and save...
by: D Witherspoon | last post by:
Coming up with a scenario here. For example there is the standard .NET MailMessage class. I am creating a project (let's call it CommonBase) that has the following 2 classes EmailMessage_Base ( inherits System.Net.Mail.MailMessage and provides additional methods and properties) EmailMessage_Abstract ( inherits EmailMessage_Base and...
by: netasp | last post by:
hi all, I need your help with the following scenario: I am using VS 2005 and SQL server DB, my form has 3 textboxes txtTotalAmount, txtAmountEntered, txtAmountBalance. If txtTotalAmount is $20.00 for example then user can enter $2.00 in cash, $2.00 in MasterCard, $16.00 in Cash ,..etc until total amount is reached then balance will show to...
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and efficient navigating within Visual Studio 2005. Let's say your project (or solution) has dozens of forms and hundreds or even thousands of routines. ...
by: Guy Thornton | last post by:
I have an application in asp.net using vb. The asp.net portion of this application is mainly the user interface. The UI has references made to our business logic layer. And the business logic layer uses a database class to access our data environment. The business logic layer and database class is compiled into a class library. The...
by: John Sitka | last post by:
Hi, sorry for a crosspost but that other news group was showing last post was a week ago so I guess it dosen't see much use... I'm about to start a solution and I'm curious about the approach of a webservices project. Should the objects be represented in classes such as... public class Orders (ie Orders.cs) within a project and then have...
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
by: Burt | last post by:
There's an architect at my 200 person company that advocates having many layers in all my C# apps. He wants web services, use case handlers, facade layers, data gateways, etc. When I ask why all this complexity is necessary, he gives me what if scenarios: "What if you ever want to access the business logic with another front end?", for...
by: Chuck Cheeze | last post by:
This might be in the wrong group, but... Here is an example of my data: entry_id cat_id 1 20 2 25 3 30 4 25 5 35
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.