Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 643675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:18:31+00:00 2026-05-13T21:18:31+00:00

I need to be able to query a SharePoint database for survey results. The

  • 0

I need to be able to query a SharePoint database for survey results. The type of data I’m having problems with is a “Rating Scale” value. So the data in each table column represents a whole group of sub-questions and their answers.

So the following is an example of what is found in ONE column:

1. Our function has defined how Availability is measured the hardware/software in Production;#3#2. Availability threshold levels exist for our function (e.g., SLA’s);#3#3. Our function follows a defined process when there are threshold breaches;#4#4. Our function collects and maintains Availability data;#4#5. Comparative analysis helps identify trending with the Availability data;#4#6. Operating Level Agreements (OLA’s) guide our interaction with other internal teams;#4#

The Questions end with a semi-colon and their answers are inside the two # signs. So the answer to the first question is 3.

When I export the results of the survey it formats each question as a column header and the answer as the value in the cell below, which is ideal to get an average for each question, and would love to be able to replicate that from a SQL query.

But if I could get query results into two columns (Question, Answer)…I’d be thrilled with that.

Any help is appreciated.

Thanks very much

Hank Stallings

*****ADDENDUM:**

This was my version of astander’s solution…THANKS again!

DECLARE @Table TABLE(  
        QuestionSource VARCHAR(50),  
        QA VARCHAR(5000)  
) 

DECLARE @ReturnTable TABLE( 
        QuestionSource VARCHAR(50), 
        Question VARCHAR(5000),  
        Answer int  
) 

DECLARE @XmlField XML, 
        @QuestionSource VARCHAR(50) 

INSERT INTO @Table SELECT 
'Availability' AS QuestionSource,CONVERT(varchar(5000),ntext1) FROM UserData WHERE tp_ContentType = 'My Survey' 
INSERT INTO @Table SELECT 
'Capacity' AS QuestionSource,CONVERT(varchar(5000),ntext2) FROM UserData WHERE tp_ContentType = 'My Survey' 

--SELECT * FROM @Table 

DECLARE Cur CURSOR FOR  
SELECT  QuestionSource, 
        CAST(Val AS XML) XmlVal  
FROM    (  
            SELECT  QuestionSource, 
            LEFT(Vals, LEN(Vals) - LEN('<option><q>')) Val  
            FROM    (  
                        SELECT  QuestionSource, 
                            '<option><q>' + REPLACE(REPLACE(REPLACE(QA,'&','&amp;'), ';#','</q><a>'), '#', '</a></option><option><q>') Vals  
                        FROM @Table 

                    ) sub  
        ) sub  

OPEN Cur  
FETCH NEXT FROM Cur INTO @QuestionSource,@XmlField  

WHILE @@FETCH_STATUS = 0   
BEGIN  
    INSERT INTO @ReturnTable  
    SELECT  @QuestionSource, 
            T.split.query('q').value('.', 'nvarchar(max)') question,  
            T.split.query('a').value('.', 'nvarchar(max)') answer  
    FROM    @XmlField.nodes('/option') T(split)  
    FETCH NEXT FROM Cur INTO @QuestionSource,@XmlField  
END  

CLOSE Cur  
DEALLOCATE Cur  

SELECT * FROM @ReturnTable 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:18:32+00:00Added an answer on May 13, 2026 at 9:18 pm

    OK, let see. I had to use a cursor, as this would probably have been better achieved from a programming language like C#, but here goes… Using Sql Server 2005, try the following. Let me know if you need any explanations.

    DECLARE @Table TABLE(
            QuestionSource VARCHAR(50),
            QA VARCHAR(1000)
    )
    
    DECLARE @ReturnTable TABLE(
            QuestionSource VARCHAR(50),
            Question VARCHAR(1000),
            Answer VARCHAR(10)
    )
    
    DECLARE @XmlField XML,
            @QuestionSource VARCHAR(40)
    
    INSERT INTO @Table SELECT
    'Availability','1. Our function has defined how Availability is measured the hardware/software in Production;#3#2. Availability threshold levels exist for our function (e.g., SLA''s);#3#3. Our function follows a defined process when there are threshold breaches;#4#4. Our function collects and maintains Availability data;#4#5. Comparative analysis helps identify trending with the Availability data;#4#6. Operating Level Agreements (OLA''s) guide our interaction with other internal teams;#4#'
    INSERT INTO @Table SELECT
    'Capacity', '1. Our function has defined how Availability is measured the hardware/software in Production;#1#2. Availability threshold levels exist for our function (e.g., SLA''s);#2#3. Our function follows a defined process when there are threshold breaches;#3#4. Our function collects and maintains Availability data;#4#5. Comparative analysis helps identify trending with the Availability data;#5#6. Operating Level Agreements (OLA''s) guide our interaction with other internal teams;#6#'
    
    
    DECLARE Cur CURSOR FOR
    SELECT  QuestionSource,
            CAST(Val AS XML) XmlVal
    FROM    (
                SELECT  QuestionSource,
                        LEFT(Vals, LEN(Vals) - LEN('<option><q>')) Val
                FROM    (
                            SELECT  QuestionSource,
                                    '<option><q>' + REPLACE(REPLACE(QA, ';#','</q><a>'), '#', '</a></option><option><q>') Vals
                            FROM    @Table
                        ) sub
            ) sub
    
    OPEN Cur
    FETCH NEXT FROM Cur INTO @QuestionSource, @XmlField
    
    WHILE @@FETCH_STATUS = 0 
    BEGIN
        INSERT INTO @ReturnTable
        SELECT  @QuestionSource,
                T.split.query('q').value('.', 'nvarchar(max)') question,
                T.split.query('a').value('.', 'nvarchar(max)') answer
        FROM    @XmlField.nodes('/option') T(split)
        FETCH NEXT FROM Cur INTO @QuestionSource, @XmlField
    END
    
    CLOSE Cur
    DEALLOCATE Cur
    
    SELECT  * 
    FROM    @ReturnTable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to be able to have an SQL query that searches my database
Where I'm working, we have multiple database we need to be able to query.
I have records with a time value and need to be able to query
I need to be able to query a PostgreSQL database to obtain information about
What privileges do you need to be able to query the sys.obj$, sys.col$ etc
I need to be able to run an Oracle query which goes to insert
I need to store some data that is essentially just an array of key-value
I have a sqlite database. I am able to query it and get a
I need to be able to allow query strings that contain characters like '<'
In Oracle 11g we need to be able to query a table to pull

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.