Results 1 to 7 of 7

ODBC connection Query shows no resultt

This is a discussion on ODBC connection Query shows no resultt within the Excel Questions forums, part of the Question Forums category; Does anyone know why this sql query doesn't return values? My excel version is 2007. Thanks in advance. Code: if ...

  1. #1
    New Member
    Join Date
    Mar 2013
    Posts
    4

    Default ODBC connection Query shows no result

    Does anyone know why this sql query doesn't return values? My excel version is 2007.

    Thanks in advance.

    Code:
    if object_id( 'TEMPDB..#TMPDOC') is not null
    begin
      drop table #TMPDOC
    end
     
    create table #TMPDOC (Code varchar(5) NOT NULL)
     
     
    insert into #TMPDOC (code) VALUES
    ('AAAAA'),
    ('BBBBB'),
    ('CCCCC'),
    ('DDDDD'),
    ('EEEEE')
    
    
    select * from #TMPDOC
    
    
    if object_id( 'TEMPDB..#TMPDOC') is not null
    begin
      drop table #TMPDOC
    end

  2. #2
    Banned user
    Join Date
    Oct 2012
    Posts
    141

    Default Re: ODBC connection Query shows no result

    Works in SSMS.

  3. #3
    New Member
    Join Date
    Mar 2013
    Posts
    4

    Default Re: ODBC connection Query shows no result

    I know it does.. It doesn't work in excel however

  4. #4
    Banned user
    Join Date
    Oct 2012
    Posts
    141

    Default Re: ODBC connection Query shows no result

    Quote Originally Posted by antonh View Post
    I know it does.. It doesn't work in excel however
    By the process of elimination, that indicates your ODBC parameters are incorrect.

    Post them together with your SSMS connection details.

  5. #5
    New Member
    Join Date
    Mar 2013
    Posts
    4

    Default Re: ODBC connection Query shows no result

    I don't think it has anything to do with my connection while it doesn't throw me an error and simple statements like 'Select * from dbo.table' do work.

  6. #6
    New Member
    Join Date
    Mar 2013
    Posts
    4

    Default Re: ODBC connection Query shows no resultt

    Setting NOCOUNT ON at the beginning of the query and turning it off at the end of the query solved the problem:
    Code:
    SET NOCOUNT ON
    if object_id( 'TEMPDB..#TMPDOC') is not null
    begin
      drop table #TMPDOC
    end
     
    create table #TMPDOC (Code varchar(5) NOT NULL)
     
     
    insert into #TMPDOC (code) VALUES
    ('AAAAA'),
    ('BBBBB'),
    ('CCCCC'),
    ('DDDDD'),
    ('EEEEE')
    
    select * from #TMPDOC
    
    if object_id( 'TEMPDB..#TMPDOC') is not null
    begin
      drop table #TMPDOC
    end
    SET NOCOUNT OFF

  7. #7
    Banned user
    Join Date
    Oct 2012
    Posts
    141

    Default Re: ODBC connection Query shows no resultt

    God bless SQL, probably the sloppiest piece of generic coding ever released onto the unsuspecting public.

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com