dynamic query

  • I have to break dynamic query into two as it was more than 4000 characters long.

    I have to use Execute(@nsql_1 + ' ' + @nsql_2) now

    how can I use two parameters to use sp_executesql?

    EXECUTE @error = sp_executesql @nsql, N'@min_date SMALLDATETIME,@max_date SMALLDATETIME',@min_date,@max_date

    Thanks for help....

  • I don't think you can. Build your parameters inline with your sql, and use the straight EXEC command instead of sp_executesql.

  • [font="Verdana"]

    Declare @sql VarChar(MAX)

    Set @sql = '{You whole select statement}'

    EXECUTE @error = sp_executesql @sql, N'@min_date SMALLDATETIME, @max_date SMALLDATETIME', @min_date,@max_date

    Mahesh

    [/font]

    MH-09-AM-8694

  • Ah yes, varchar(Max). Sorry, I was still in SQL 2000 land...

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

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