dynamic query

  • create table dbo.dynamic(id int, name varchart)

    insert into dbo.dynamic(id,name)

    select 1,'pirana'

    union

    select 2,'shark'

    union

    select 3,'whale'

    union

    select 4, 'octopus'

  • Was there a question in there? I don't really get what you're asking for. (?)

    Sigerson

    "No pressure, no diamonds." - Thomas Carlyle

  • question is how to get the desired output.

  • Right, but you want an output column of 'value' that isn't in your input table, just 'rootid.' Are you looking for a way to generate that field 'value' as a string?

    So that for octopus you get a 'value' field = 4, octopus, '*%**%***%***%' ? Is that what you want?

    Sigerson

    "No pressure, no diamonds." - Thomas Carlyle

  • yes for octopus

    shark>octopus>whale

  • i was unclear on the requirements, myself....i thought this was a visualization of a hierarchy, so he'd want whale--shark--pirana--octopus

    his sample table is a varchar(1), also, which would probably be an issue.

    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!

  • sorry the post is confusing and will be corrected.

  • I'm not sure how I would do this without using a CTE or a query.

    One question I have is why you need to create the strings since the rootid values are giving you the ability to rank the result records. Or will there be many, many levels of ranking?

    Also, will there be multiple names with the same value, such as:

    *%octopus

    *%tuna

    *%lobster

    **%shark

    **%halibut

    Sigerson

    "No pressure, no diamonds." - Thomas Carlyle

  • scottichrosaviakosmos (1/12/2015)


    question is how to get the desired output.

    What is the desired output?

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

Viewing 9 posts - 1 through 8 (of 8 total)

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