Avoiding loop so want to use CTE

  • I have the following table where I store the QuerystringTBL

    QueryString, MatchId

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

    CodeValue between 1 and 100

    DateValue >= '01/01/2015'

    I want to get the querystring in one string something like

    @strWHERE = CodeValue between 1 and 100 and DateValue >= '01/01/2015'

    Is it possible using a CTE? I can do this using a while loop but since that is not an efficient code I wanted to use CTE. I have the following then after that I am stuck.

    WITH CTE_query (query)

    AS

    (

    SELECT Query from QueryStringTBL where matchId = 1

    )

  • Guras (3/9/2015)


    I have the following table where I store the QuerystringTBL

    QueryString, MatchId

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

    CodeValue between 1 and 100

    DateValue >= '01/01/2015'

    I want to get the querystring in one string something like

    @strWHERE = CodeValue between 1 and 100 and DateValue >= '01/01/2015'

    Is it possible using a CTE? I can do this using a while loop but since that is not an efficient code I wanted to use CTE. I have the following then after that I am stuck.

    WITH CTE_query (query)

    AS

    (

    SELECT Query from QueryStringTBL where matchId = 1

    )

    I guess I don't understand the question. If I'm reading it correctly, you don't need a loop or a CTE. If I'm not reading it correctly, is it that you want to generate the values of 1 to 100 for CodeValue?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • No. I am building the where clause based on the rows for matchId 1 from the table. I want all the matching rows concatenated to a string as the result set.

    Thanks

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

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