none
dynamic sql statement inside stored procedure? RRS feed

  • Frage

  •  

    Hi everyboby,

    is it somehow possible to create a stored procedure, which accepts a column name and/or table name) as a parameter?

    Something like:

    [...]

    CREATEPROCEDURE getWhatever
        @ColData varchar(50),
        @tabData varchar(50)

    AS
    BEGIN

        SET NOCOUNT ON;
        SELECT @Data FROM @tabData;

    END

    [...]

    Would that be possible to create something similar since the above code doesn't work.... ;-)

     

    Cheers,

    Sandra

    Montag, 30. August 2010 07:11

Antworten

Alle Antworten

  • Yes, that's possible and no, most of the times it's not advisable. Why? Check this out: http://www.insidesql.org/beitraege/entwicklung/dynamisches-sql-fluch-und-segen

    ...und übrigens ist das ein deutschsprachiges Forum... ;-)

    --
    Cheers!

     

     


    -- Frank Kalis Microsoft SQL Server MVP Webmaster: http://www.insidesql.org
    Montag, 30. August 2010 07:20
  • Hallo Frank,

    vielen Dank für diesen Link. Das hat mir die Augen geöffnet und ich habe mich entschieden, mein Problem nun anders zu lösen.

    Gerade was das Caching der Abfragepläne angeht, führt mein "objektorientierter" Ansatz eine gespeicherte Prozedur wohl eher ad Absurdum.

     

    Danke nochmal,

     

    Sandra

    Montag, 30. August 2010 07:44