How2get rows relation between same table - Need Solution

  • Could you pls. advice me on following dilemma

     

    I am having table called ‘UNITCONVERTION’, its containing following records.

     

    IDfrom                                     FromValue                               toValue                    IDto

    -------------------------------------------------------------------------------------------------------------

     

    2                                              1000                                        1                              3

    3                                              1000                                        1                              4

    4                                              1000                                        1                              8

    33                                            1000                                        1                              38           

    103                                          2                                              1                              205

    56                                            1000                                        1                              33

    38                                            10                                            1                              45

    205                                          10                                            1                              506

    45                                            8                                              1                              103

     

    ------------------------------------------------------------------------------------------------------------

     

    IDfrom and IDto values are I am getting from another table called ‘UNITNAMES

     

    Example with first row

     

    ID 2 is ‘Gram’

    ID 3 is ‘KiloGram’ means I am using unitconvertion 1000 gram = 1 Kilogram

     

    With above scenario, if i pass parameter within IDfrom or IDto, I need all the corresponding values and rows

     

    For example (if parameter value is 38 I need rows like following order)

     

    IDfrom                                     FromValue                               toValue                    IDto

    -------------------------------------------------------------------------------------------------------------

     

    56                                            1000                                        1                              33

    33                                            1000                                        1                              38           

    38                                            10                                            1                              45

    45                                            8                                              1                              103

    103                                          2                                              1                              205

    205                                          10                                            1                              506

     

    ------------------------------------------------------------------------------------------------------------

     

    Anyone please help me with T-SQL scripting

     

     

  • How do you mean, pass parameter? What kind of solution are you looking for?
    Maybe
    SELECT *
    FROM UNITCONVERTION 
    WHERE 38 IN ( IDFrom , IDto )
    is enough?
     
    //Hanslindgren
  • Are you passing a parameter to a stored procedure ?! The only thing I see in the result that you want is that you seem to want an "order by" on the column ?!?! Could you explain some more ?!







    **ASCII stupid question, get a stupid ANSI !!!**

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

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