can use variable in the from clause

  • Is it possible to pass the parameter to the from clause? For example, select @id =max(keyid) from @tablename or insert into @table1 select * from @table2.

    Cheers

    Dev


    Cheers

    Dev

  • not directly. You can, however, use dynamic sql for this.

    Steve Jones

    steve@dkranch.net

  • Do you mean to use exec() function? Yes, it works, but how can I get the result from the dynamic sql, like select @result=max(id) from @tablename. Could you give me an example on how to do that?

    quote:


    not directly. You can, however, use dynamic sql for this.

    Steve Jones

    steve@dkranch.net


    Cheers

    Dev


    Cheers

    Dev

  • Typically a call to Dynamic SQL would look like EXEC('SELECT ' + @columnname + ' FROM ' + @tablename), but I suspect you know that.

    Could you post a fuller example of what you are trying to do.


    I have found it is possible to please all of the people all of the time if you do exactly what they want. Harold Macmillan 1961

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

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