SQL Server Developer Center > SQL Server Forums > SQL Server Integration Services > Query containing table variable returning no rows at runtime
Ask a questionAsk a question
 

AnswerQuery containing table variable returning no rows at runtime

  • Wednesday, November 05, 2008 1:17 PMSyed Mehroz Alam Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have a query containing table variables for an Ole Db source. The SSIS designer correctly recognized the column names from the query and when I hit the Preview button, it also shows the data correctly. But when I execute the task, no rows are returned. Am i missing something? Here's a sample query containing the table variable:

    Code Snippet

    declare @mytable table
    (
            col1 int,
            col2 varchar(20)
    )

    insert @mytable values (1, 'one')
    insert @mytable values (2, 'two')
    insert @mytable values (3, 'three')

    select * from @mytable

    Regards,

    Syed Mehroz Alam

Answers

  • Wednesday, November 05, 2008 8:25 PMCharles TalleyrandAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Actually, I just found a comment on one of Jamie's threads.  Issue a

    Code Snippet
    SET NOCOUNT ON

     

     

    and it will work.  I'll need to commit that one to memory or understand the reasoning on it.

All Replies

  • Wednesday, November 05, 2008 8:19 PMCharles TalleyrandAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I can at least confirm that I am experiencing the same behaviour.  Off the top of my head, I can't think of a reason for it unless the OLE DB provider is silently tanking.

     

    I reworked it as a CTE and I saw 3 rows flow through so definitely an oddity. 

    Code Snippet

    WITH D AS
    (
    SELECT 1 AS col1, cast('one' AS varchar(20)) AS col2
    UNION ALL
    SELECT 2, 'two'
    UNION ALL
    SELECT 3, 'three'
    )
    SELECT D.* FROM D

     

     

  • Wednesday, November 05, 2008 8:25 PMCharles TalleyrandAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Actually, I just found a comment on one of Jamie's threads.  Issue a

    Code Snippet
    SET NOCOUNT ON

     

     

    and it will work.  I'll need to commit that one to memory or understand the reasoning on it.
  • Thursday, November 06, 2008 6:51 AMSyed Mehroz Alam Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Great find, Charles. It works perfect now. Looks like the output of insert statements: i.e. x row(s) affected was the source of problem and a SET NOCOUNT ON prevented such interferences. Thanks very much for your help.


    Cheers,
    Syed Mehroz Alam
    MyBlog | MyArticles