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

  • 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 cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001