can any one please let me know a stored procedure logic for getting a total left count and right count for a particaulr Id. e.g. if i pass Id 2 the procedure should give its total number of left nodes =3 total number of riht nodes = 1

  • total L is 11 and Total R is 1 count all node

  • Snce you're new here, here's how to post your data so that people here can help. Here's your data...

    use tempdb;

    GO

    CREATE TABLE Data (

    ID INT NOT NULL,

    JoiningDate DATE,

    Placement CHAR(1),

    pID INT,

    cID INT,

    referBy INT);

    GO

    INSERT INTO Data(ID, joiningDate, placement,pID, cID, referBy)

    VALUES (4,'2015-02-02','L',4,5,4),

    (6,'2015-02-02','R',5,8,4),

    (8,'2015-02-02','R',4,11,4),

    (9,'2015-02-02','L',5,10,4),

    (25,'2015-12-12','L',8,9,4),

    (31,'2015-08-21','R',8,12,4),

    (33,'2015-08-21','R',12,13,4),

    (36,'2015-08-21','R',9,14,4),

    (37,'2015-08-21','M',9,15,4),

    (38,'2015-08-21','L',10,16,4),

    (39,'2015-08-21','M',4,17,4);

    Given that, could you please provide the answer that should be returned by the query you're working on? (And perhaps an explanation of the rules to get there?)

    Thanks!

    Pieter

  • your question is not clear

    could you please give some more detail ?

  • Please include the description of the problem in the body of the message. Putting it in the title makes it hard to read.

    Read this article[/url] - it explains how to post in order to get the best help.

  • There is a neat technique where you sum a case with a counter to get this kind of information.

    SELECT SUM(CASE WHEN placement = 'L' THEN 1 ELSE 0 END) AS LeftCount,

    SELECT SUM(CASE WHEN placement = 'R' THEN 1 ELSE 0 END) AS RightCount,

    SELECT SUM(CASE WHEN placement NOT IN('L','R') THEN 1 ELSE 0 END) AS ExceptionCount,

    count(*) as TotalCount

    FROM MyTable

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply