• To get the syntax correct, you should remove the word cursor and move the line starting with INTO before the from statement, similar to:

    SELECT columns

    INTO #temptable --!

    FROM mytable

    WHERE 1 = 0;

    But, if I understand correctly what you are trying to achieve, you don't need a cursor or a temp table. Try this:

    CREATE PROCEDURE tmp

    @col1 INT OUTPUT

    ,@col2 VARCHAR(100) OUTPUT

    AS

    SET NOCOUNT ON ;

    SELECT @col1 = col1

    ,@col2 = col2

    FROM mytable

    WHERE ...;

    To test it, run the following script:

    DECLARE @var1 INT

    ,@var2 VARCHAR(100) ;

    EXEC tmp

    @var1 OUTPUT

    ,@var2 OUTPUT ;

    SELECT @var1

    ,@var2 ;

    An alternative to using output variables that will also work if you want to return values from more than 1 record is:

    CREATE PROCEDURE tmp

    AS

    SET NOCOUNT ON ;

    SELECT col1, col2

    FROM mytable

    WHERE ...;

    And for the calling part:

    CREATE TABLE #tmp (

    col1 INT

    ,col2 VARCHAR(100)) ;

    INSERT INTO #tmp

    EXEC tmp ;

    SELECT *

    FROM #tmp ;

    Regards,

    Willem
    http://wschampheleer.wordpress.com[/url]