Sqlserver
 sql >> Cơ Sở Dữ Liệu >  >> RDS >> Sqlserver

Chèn dữ liệu máy chủ SQL vào Salesforce bằng con trỏ

Blog này cung cấp một ví dụ về chuyển dữ liệu từ bảng SQL Server cục bộ sang Salesforce. Chúng tôi đang sử dụng Trình điều khiển ODBC Salesforce.com để chèn ba bản ghi vào bảng Salesforce Product2.

  1. Định cấu hình một máy chủ được liên kết kết nối với Salesforce.
  2. Trong SQL Server Management Studio, thay đổi Máy chủ được liên kết> Thuộc tính máy chủ được liên kết> Tùy chọn máy chủ> RPC Out cài đặt thành True.
  3. Tạo bảng này trong SQL Server:
    create table NewProducts ( "Name" nvarchar(30), ProductCode nvarchar(10), Description nvarchar(max))
    insert into NewProducts values ( 'Test1', 'TEST01', 'Test 1st description')
    insert into NewProducts values ( 'Test2', 'TEST02', '2nd description' )
    insert into NewProducts values ( 'Test3', 'TEST03', '3rd Test description')

    Bạn có thể chèn dữ liệu vào bất kỳ cột nào trong bảng Product2, giả sử bạn có các quyền cần thiết.

  4. Thực thi SQL sau:
    -- Declare a variable for each column you want to insert:
    declare @Name nvarchar(30)
    declare @ProductCode nvarchar(10)
    declare @Description nvarchar(max)
    
    -- Use a cursor to select your data, which enables SQL Server to extract
    -- the data from your local table to the variables.
    declare ins_cursor cursor for 
            select "Name", ProductCode, Description from NewProducts
        open ins_cursor
        fetch next from ins_cursor into @Name, @ProductCode, @Description -- At this point, the data from the first row
                                                                          -- is in your local variables.
    
        -- Move through the table with the @@FETCH_STATUS=0 
        while @@FETCH_STATUS=0
        Begin
    
             -- Execute the insert to push this data into Salesforce. Replace "SF_LINK" with the name of your Salesforce Linked Server.
            exec ('insert into Product2 ( "Name", ProductCode, Description ) Values (?, ?, ?)', @Name, @ProductCode ,@Description ) at SF_LINK
    
             -- Once the execution has taken place, you fetch the next row of data from your local table.
            fetch next from ins_cursor into @Name, @ProductCode, @Description
        End
    
        -- When all the rows have inserted you must close and deallocate the cursor.
        -- Failure to do this will not let you re-use the cursor.    
        close ins_cursor
        deallocate ins_cursor

Xem thêm

  • Mẹo Sử dụng SQL Server với Salesforce

  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Nhật ký giao dịch SQL Server, Phần 3:Khái niệm cơ bản về ghi nhật ký

  2. Thay đổi thông báo với Sql Server 2008

  3. Đổi tên khóa ngoại trong SQL Server bằng T-SQL

  4. Cách kết hợp ngày từ một trường với thời gian từ một trường khác - MS SQL Server

  5. Thủ thuật nhanh và tốt nhất để khôi phục tệp SQL Server MDF