简体   繁体   中英

Querying SharePoint list with SQL

I know that SQL does not currently support SharePoint queries, but has anyone found a workaround for that? I've been running into situations where I could do the task I need with SQL, but I'm working with SharePoint, so I'm stuck using the SSRS Query Designer or XML; the Query Designer doesn't always have the functionality I want (at least not easily) and I can't learn XML quickly enough to be a practical option.

I do this day to day in a live environment but it does require a big setup cost or just access to the tools.

the way i do this is by using a SSIS job to pull the data from SharePoint into a SQL table this requires download of the Sharepoint tool set for SSIS.

STEP 1 - Create a Staging/Holding data for the table this is to make sure data is always available to your report

STEP 2 - Write a job to a)pull the data in the staging table b)compare the data in the live table and update, insert and delete from the live table

STEP 3 - When the job is fully working set it up on a SQL Scheduled to run every hour so the data will be up to date by the hour. it is advised when setting this up to have email alerts to be sent if the job fails

STEP 4 - The data is then in SQL and can be queried as normal query from the Live table not the staging table

If you use SharePoint 2010 here you go

    SELECT
    ud.tp_ID
    , ud.tp_ListId
    , ud.tp_Author
    , ud.nvarchar1
    , ud.nvarchar2
    , ud.nvarchar3
    , ud.nvarchar4
    , ud.nvarchar5
    , ud.nvarchar6
    , ud.nvarchar7
    , ud.nvarchar8
    , ud.nvarchar9
    , ud.nvarchar10
    , ud.nvarchar11
    , ud.nvarchar12
    , ud.*
    FROM dbo.Lists l
    INNER JOIN dbo.UserData ud ON l.tp_ID = ud.tp_ListId
    WHERE (ud.tp_ListId =  '[{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM