• DataAnalyst011 (12/12/2012)


    Thanks for your reply also.

    I didn't do a very good job setting this up. I just tried to create a quick example to ask about a concept - Is it possible to loop through multiple variables in a single statement. In my production project, the values don't exist and I use the variables to print them into a row for a business process need.

    A table called x has these values in a Prog column: 1, 2, 3, 4

    What I want to do is pass each of those variables in the below statement:

    insert into q (resultcolumn)

    select @prog

    from a

    All you have done here is insert whatever value is in your @prog variable for each row.

    and the results in resultcolumn is:

    1

    2

    3

    4

    This would keep me from declaring and setting the value for @prog 4 times (one for each of the numbers). Does that make sense?

    Your example is so abstract it is really hard to tell what you are doing. What about a temp table. or a cross apply to a cte?

    If you can be a bit more specific in what you are doing we can come up with a way to do this.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/