Home Forums SQL Server 7,2000 T-SQL OPENROWSET linked server "(null)" error RE: OPENROWSET linked server "(null)" error

  • Hi Jeff,

    Thank you for your reply.

    I've a generic procedure which prints messages on screen and used in validation step in other procedures.

    Ex: Print error message if querying table doesn't have data for a specified date.

    I've to create a text file using output of a procedure, which intern uses above procedure for validation and displays required result if no validation errors. Now, I copy this data manually into a text file.

    However, I wanted to create a generic script to copy output data into text file.

    Sample code:

    @tempsql AS varchar(max)

    ,@execstring AS varchar(max) = 'exec ash_test 160808;';

    SET @tempsql = 'SELECT * INTO ##SwitchInput FROM OPENROWSET(''SQLNCLI'', ''Server=vm01;Trusted_Connection=Yes;'','''+@execstring+''')';

    EXEC (@tempsql);

    SELECT top 10 * FROM ##SwitchInput;

    Later, I'm planning to use master..xp_cmdshell (BCP) to copy this data to a specific text file.

    However, got stuck in the EXEC(@tempsql) step and am trying to resolve this error.