how to export sql server-2005 table data into excel sheet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sangeethass
    New Member
    • Mar 2008
    • 4

    how to export sql server-2005 table data into excel sheet

    How to export sql server-2005 table data into excel sheet ..

    Can u tell me how can i do this both my manually and by programmewise using perl

    please help me...

    thanks
    Sangeetha.S
  • deepuv04
    Recognized Expert New Member
    • Nov 2007
    • 227

    #2
    Originally posted by sangeethass
    How to export sql server-2005 table data into excel sheet ..

    Can u tell me how can i do this both my manually and by programmewise using perl

    please help me...

    thanks
    Sangeetha.S
    Hi,
    Assume the table is Users.

    use the following query to export data into excel sheet.
    Make sure that the excel sheet must be on the server and the excel sheet has appropriate column headings at the first row.

    [code=sql]
    INSERT INTO
    OPENROWSET( 'Microsoft.Jet. OLEDB.4.0',
    'Excel 8.0;Database=D: \Test.xls',
    'SELECT UserId, UserName, FirstName,LastN ame FROM [Sheet1$]')
    SELECT UserId, UserName, FirstName,LastN ame FROM Users
    [/code]

    Comment

    • sangeethass
      New Member
      • Mar 2008
      • 4

      #3
      Hi,

      thanks for ur reply..
      But if i try ur coding the below mentioned error msg is apperring..
      So wat i have to do to rectify this.
      thnks
      Sangeetha.S
      P.S.our Db is centralised...


      Msg 15281, Level 16, State 1, Line 1
      SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.









      Originally posted by deepuv04
      Hi,
      Assume the table is Users.

      use the following query to export data into excel sheet.
      Make sure that the excel sheet must be on the server and the excel sheet has appropriate column headings at the first row.

      [code=sql]
      INSERT INTO
      OPENROWSET( 'Microsoft.Jet. OLEDB.4.0',
      'Excel 8.0;Database=D: \Test.xls',
      'SELECT UserId, UserName, FirstName,LastN ame FROM [Sheet1$]')
      SELECT UserId, UserName, FirstName,LastN ame FROM Users
      [/code]

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        By default OPENROWSET is not enabled in most sql-server installation. Talk to your sys-ad or dba to enable it.

        -- CK

        Comment

        • deepuv04
          Recognized Expert New Member
          • Nov 2007
          • 227

          #5
          Originally posted by sangeethass
          Hi,

          thanks for ur reply..
          But if i try ur coding the below mentioned error msg is apperring..
          So wat i have to do to rectify this.
          thnks
          Sangeetha.S
          P.S.our Db is centralised...


          Msg 15281, Level 16, State 1, Line 1
          SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.
          Hi,
          run the following script and then execute your query

          [code=sql]
          sp_configure 'show advanced options', 1
          RECONFIGURE
          GO
          sp_configure 'Ad Hoc Distributed Queries', 1
          RECONFIGURE
          GO
          [/code]
          Thanks

          Comment

          • sangeethass
            New Member
            • Mar 2008
            • 4

            #6
            Originally posted by deepuv04
            Hi,
            run the following script and then execute your query

            [code=sql]
            sp_configure 'show advanced options', 1
            RECONFIGURE
            GO
            sp_configure 'Ad Hoc Distributed Queries', 1
            RECONFIGURE
            GO
            [/code]
            Thanks



            Hi,

            It is very helpful to me..
            Thanks for ur help...

            Sangeetha.S

            Comment

            Working...