Object Names in Variables to Re use code, over and over..

  • Hi,

    In Visual basic you can great a sub Like this, transfering object name as a parameter into sub, so code can be re used with all types of tables.

    Sub SelectAnyTable(tbl as string, CWhere as string)

    Dim Str as string

    Str = "SELECT * FROM " & tbl & CWhere & ";"

    ....Run select statement to connected recordset

    end Sub

    QUESTION : How do you make TSQL re usable with different objects of the same type, ie Tables ??

    Any examples or articles to help a learner

  • Look up dynamic SQL on this site.  Please be sure to find a posting with the article title similar to "The curse and blessing of Dynamic SQL".  It is VERY important you understand the potential dangers involved in using Dynamic SQL. 

    I wasn't born stupid - I had to study.

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

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