if you are doing it manually, use the Import and Export Data wizard in the SQL Server program groupif you want to do it programmatically, you can use bcp utility, for example, you can run the following query:execute master..xp_cmdshell 'bcp "select * from [Pubs].[dbo].[Authors]" queryout c:\test1.xls -c -Usa -P'

解决方案 »

  1.   

    something like
    Dim conn As New ADODB.Connection
    strServerName = "localhost"
    strDBName = "pubs"
    strLoginName = "sa"
    strPassword = ""strConn = "Provider=SQLOLEDB;Server=" & strServerName & ";Database=" & strDBName & ";UID=" & strLoginName & ";PWD=" & strPasswordconn.Open strConnstrTableName = "Authors"
    strFileName = "c:\test1.xls"sql = "execute master..xp_cmdshell 'bcp ""select * from [" & strDBName & "].[dbo].[" & strTableName & "]"" queryout " & strFileName & " -c -U" & strLoginName & " -P" & YourPassword & " -S" & strServerName & "'"
    MsgBox sql
    conn.Execute sqlconn.Close