日期:2014-05-18  浏览次数:20403 次

一个pro的疑问
USE   MmyeeAd
GO
--   check   existing   of   sp_Import_MmyeeAd
IF   OBJECT_ID   (   'dbo.sp_Import_MmyeeAd ',   'P '   )   IS   NOT   NULL  
        DROP   PROCEDURE   dbo.sp_Import_MmyeeAd
GO

CREATE   PROCEDURE     dbo.sp_Import_MmyeeAd
@Provider_Name   nvarchar(50)   =   'SQLOLEDB ',
@DataSource   nvarchar(50)   =   '. ',
@User_ID   nvarchar(50)   = 'sa ',
@Password   nvarchar(50)= ' '
AS
BEGIN
          /*
                      --Function   Improt   WebUser
                      --relate   to   Three   Table   :   Corp_Info-----------> > Ad_WebSite+Accounts_Users
          */
                        --   select   A.*   from   OpenRowSet( 'SQLOLEDB ', 'ROBOTH\SQLEXPRESS '; 'saa '; '1q ', 'select   *   from   Mayee_Online.dbo.Corp_Info ')   AS   A
                     
          execute( 'select   A.*   from     OpenRowSet( '+@Provider_Name+ ', '+@DataSource+ '; '+@User_ID+ '; '+@Password+ ', ' 'select   *   from   Mayee_Online.dbo.Corp_Info ' ')   AS   A ')
END
GO

execute   dbo.sp_Import_MmyeeAd   'SQLOLEDB ', 'ROBOTH\\SQLEXPRESS ', 'saa ', '1q '

go
execute   dbo.sp_Import_MmyeeAd   'SQLOLEDB ', 'ROBOTH\SQLEXPRESS ', 'saa ', '1q '


2个都不对,执行时报错
消息   102,级别   15,状态   1,第   1   行
'ROBOTH '   附近有语法错误

------解决方案--------------------
try

USE MmyeeAd
GO
-- check existing of sp_Import_MmyeeAd
IF OBJECT_ID ( 'dbo.sp_Import_MmyeeAd ', 'P ' ) IS NOT NULL
DROP PROCEDURE dbo.sp_Import_MmyeeAd
GO

CREATE PROCEDURE dbo.sp_Import_MmyeeAd
@Provider_Name nvarchar(50) = 'SQLOLEDB ',
@DataSource nvarchar(50) = '. ',
@User_ID nvarchar(50) = 'sa ',
@Password nvarchar(50)= ' '
AS
BEGIN
/*
--Function Improt WebUser
--relate to Three Table : Corp_Info-----------> > Ad_WebSite+Accounts_Users
*/
-- select A.* from OpenRowSet( 'SQLOLEDB ', 'ROBOTH\SQLEXPRESS '; 'saa '; '1q ', 'select * from Mayee_Online.dbo.Corp_Info ') AS A

execute( 'select A.* from OpenRowSet( ' ' '+@Provider_Name+ ' ' ', ' ' '+@DataSource+ ' ' '; ' ' '+@User_ID+ ' ' '; ' ' '+@Password+ ' ' ', ' 'select * from Mayee_Online.dbo.Corp_Info ' ') AS A ')
END
GO

execute dbo.sp_Import_MmyeeAd 'SQLOLEDB ', 'ROBOTH\\SQLEXPRESS ', 'saa ', '1q '

go
execute dbo.sp_Import_MmyeeAd 'SQLOLEDB ', 'ROBOTH\SQLEXPRESS ', 'saa ', '1q '