Home Forums SQL Server 2008 T-SQL (SS2K8) How to bring in more than one column from left table in a CURSOR/dynamic sql query RE: How to bring in more than one column from left table in a CURSOR/dynamic sql query

  • Alan.B (11/6/2013)


    You could do something like this (I changed @name to @names):

    DECLARE @names varchar(max);

    WITH names(n) AS

    (

    SELECT Name

    FROM dbo.iNamesExcel$

    FOR XML PATH('')

    )

    SELECT @names=CHAR(39)+LEFT(n,LEN(n)-1)+CHAR(39)

    FROM names

    Then, in your DSQL change your and displayName =

    to

    and displayName IN ( @names )

    Hope that makes sense. Let me know if you need clarification.

    I don't think that @names is going to be recognized within the scope of the Dynamic SQL.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St