Pyraimid Qurey Help Please?

Apr 17, 2008

Hi,

I am working on a multi level payout system with a parent child table for referrers. I am performing multiple In Lists to get to level 3 of the pyramid as you can see by running the code below.

I would like if this is the best way to refer to these folks down on level 3 and is there a better way to go down the levels.

Any help would be greatly appreciated. Thanks.

Here is my code:

-- Make the Table
CREATE TABLE [dbo].[x_Test__Member_Refer](
[ID] [int] IDENTITY(1,1) NOT NULL,
[CustomerID] [int] NOT NULL,
[MemberID] [int] NOT NULL,
[dtmTimeStamp] [datetime] NOT NULL CONSTRAINT [DF_MemberRefer_dtmTimeStamp] DEFAULT (getdate()),
CONSTRAINT [PK_Member_Refer] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

-- Add some Data
Insert Into x_Test__Member_Refer ( CustomerID, MemberID )
Values ( 59108, 59107 )

Insert Into x_Test__Member_Refer ( CustomerID, MemberID )
Values ( 59109, 59107 )

Insert Into x_Test__Member_Refer ( CustomerID, MemberID )
Values ( 59110, 59107 )

Insert Into x_Test__Member_Refer ( CustomerID, MemberID )
Values ( 59123, 59109 )

Insert Into x_Test__Member_Refer ( CustomerID, MemberID )
Values ( 59126, 59123 )

-- Run our Queries
Select * From x_Test__Member_Refer

-- Set Top Member
Declare @MemberID int
Set @MemberID = 59107

-- Select Level 1
Select *
From dbo.x_Test__Member_Refer
Where MemberID = @MemberID

-- Select Level 2
Select *
From dbo.x_Test__Member_Refer mr
Where MemberID In (
Select CustomerID
From dbo.x_Test__Member_Refer
Where MemberID = @MemberID )
-- Select Level 3
Select *
From dbo.x_Test__Member_Refer mr
Where MemberID In (
Select CustomerID
From dbo.x_Test__Member_Refer
Where MemberID In (
Select CustomerID
From dbo.x_Test__Member_Refer
Where MemberID = @MemberID ) )

-- Clean Up Shop!
Drop Table x_Test__Member_Refer


JBelthoff
• Hosts Station is a Professional Asp Hosting Provider
› As far as myself... I do this for fun!

View 1 Replies


ADVERTISEMENT

Sql Qurey For Null Value Of Ids

May 30, 2008

In my C# asp.net website I am using a qurey select GPM.propertyId,GURM.userName,GURM.phone from Gatepropertymaster1 GPM,GateUserMaster GURM  where  GPM.userId=GURM.userId and GPM.propertyTypeId='" + PropertyTypeId + "' and GPM.transationTypeId='" + TransationTypeId + "' and GPM.cityId='" + CityId + "' order by GPM.regDate descin some cases input PropertyTypeId may be 0 or transationTypeId may be 0 or cityId may be 0, How can I use the same qurey even though these Ids(propertyId,TransationTypeId,cityId) may be 0 in some cases Thanks in advanceAnu Palavila 

View 8 Replies View Related

Qurey Showing All The Rows In Table

Jun 10, 2008

Hi guys,

The below query should produce all those customers who are in 'orginalerrorfiles' but not in 'hopefullyworks2'. 3 fields will be used as the check to make sure that the rows, that r identical won't be displayed but those that r different will be displayed.

Instead of doing that it just display everything in the table called 'orginalerrorfiles'.

Note 'orginalerrorfiles' consist of 141455 rows
'hopefullyworks2' consist of 134784 rows


select o.card_no
,o.ref_no
,o.tran_val

from OriginalErrorFiles o

where exists (select h.card_no
,h.ref_no
,h.tran_val
from hopefullyworks2 h
where( h.card_no = o.card_no and
h.ref_no=o.ref_no and
h.tran_val = o.tran_val
))

View 5 Replies View Related

Null Didnt' Work In Qurey

May 2, 2008

I need to change a display value for a database field when its value is NULL,
Exampl I wrote the query like this
CASE MyTable.MyFiled When 'IS NOT NULL' THEN ' ' Else MyTable.MyFiled END
But it works well in sql query screen, but not in Sql panel, can any one help me.
Thank you

View 3 Replies View Related

Error:Qurey Execution Failed In Subreports.

Jan 30, 2008

Hi All,
I have a report which has two subreports in a table.First Sub report1 ,then a detail section and sub report 2.
Sub report1 runs fine.But sub report2 gives error in the main report"

Query execution failed for data set 'DataSet_azshdsd30'.
For both the sub reports parameters passed from the main report are same(2 parameters).
When I run sub report2 indivisually it gives right result.But not in the main report.
Also when I put Subreport 2 in place of subreport 1 I do get the results in the main report.
Any idea,any body??
Thanks.

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved