Forum Replies Created

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

  • RE: Do Not Return Matching Rows

    you can use the following code to get the desired O/P-

    SELECT CityName,StateName FROM @Cities where CityName NOT IN (SELECT distinct CityName from @Cities WHERE StateNAme = 'ALL')

    Thanks,

    Anand

  • RE: need t-sql query

    Hi,

    you can try with below approach-

    declare @t table(Parent_ID char(1),Child_ID char(1))

    insert @t values ('A','B'),('C','D'),('B','C'),('B','E'),('E','F')

    select t1.Parent_ID,t1.Child_ID,isnull(t2.count+t3.t3_cnt,1) Level from @t t1 left join

    (select Parent_ID,count(Child_ID)count from @t group by Parent_ID) t2

    on t1.Parent_ID=t2.Parent_ID

    left join (select...

  • RE: Query

    Hi,

    Please try using following code-

    DECLARE @T TABLE (ID INT, NAME VARCHAR(1))

    INSERT @T VALUES (1000,'A'),(990,'C'),(980,'A'),(970,'A'),(960,'B'),(950,'C'),(930,'A')

    SELECT * FROM(SELECT ROW_NUMBER() OVER( PARTITION BY NAME ORDER BY ID DESC)ROWNUM,ID,NAME FROM @T )T

    WHERE T.ROWNUM<=3

    Regards,

    Anand

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