Query

  • I have TEST table in database A,B and C.

    I choose the database from the listbox.

    I need the db to be passed to the query below :

    SELECT DISTINCT K.MAXCOM_ID FROM A.DBO.TEST

    The  A.DBO.TEST , the A is dynamic and can be B or C.

    Please say whether it is possible.

    Thanks in advance.

  • DECLARE @Query varchar(8000), @DBName varchar(20)

    SET @DBName = 'A' -- or 'B' or 'C', it should be parameter for your SP

    SET @Query = 'SELECT DISTINCT K.MAXCOM_ID FROM ' + @DBName + '.DBO.TEST'

    EXECUTE (@Query)

    _____________
    Code for TallyGenerator

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

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