Hello friend i need to store the result of a dinamic query

  • Hello friends , i need to store the result of a dynamic query in a variable or variable type table but not in a temporal table or physical table, is possible that? thanks for any helpings

    example

    declare @a varchar (30), @b-2 varchar (50)

    set @a = ' select x from mytable '

    set @a = (exec @b-2) but it doesnt work

  • Hello,

    You can do it like this

    Decare @yourtable table

    (colname datatype,

    colname2 datatype)

    insert into @yourtable select col1, col2 from yoursecondtable where condition

    select * from @yourtable

    Hope this helps.

    Thanks

     


    Lucky

  • Thanks but itisnt that i was looking for

    well but i found like to solve my problem look

    DECLARE @iCount int

    DECLARE @table sysname

    DECLARE @SQLString nvarchar(100)

    DECLARE @ParmDefinition

    nvarchar(100)

    SET @table = 'sysobjects'

    SET @SQLString = N'SELECT @C = COUNT(*) FROM '+ @table SET

    @ParmDefinition = N'@c int OUTPUT'

    EXECUTE sp_executesql @SQLString, @ParmDefinition,@c = @iCount OUTPUT

    SELECT @iCount AS [Count]

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

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