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 8787487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:54:24+00:00 2026-06-13T21:54:24+00:00

I have the following query: insert into [MyDB].[dbo].[Reports_ActivityStat] (ActivityID,TaskID,LS_HowOthersAnswered,LS_ImproveMyChances) ( SELECT ActivityID=tasks.ActivityID, TaskID=tasks.ID, CAST(

  • 0

I have the following query:

insert into [MyDB].[dbo].[Reports_ActivityStat] (ActivityID,TaskID,LS_HowOthersAnswered,LS_ImproveMyChances)
(
SELECT
ActivityID=tasks.ActivityID,
TaskID=tasks.ID,
CAST(
        CASE 
            WHEN CHARINDEX('stats',item.value('(UsedLifeSavers)[1]', 'NVARCHAR(MAX)'))>0
                THEN 1 
            ELSE 0 
        END AS bit) as LS_HowOthersAnswered,
CAST(
        CASE 
            WHEN CHARINDEX('FiftyFifty',item.value('(UsedLifeSavers)[1]', 'NVARCHAR(MAX)'))>0
                THEN 1 
            ELSE 0 
        END AS bit) as LS_ImproveMyChances

FROM  [MyDB].[dbo].[Tasks] as tasks CROSS APPLY [Progress].nodes ('//Progress/Steps/ProgressStep') Progress(item)
)  

which acts on the following Tasks table:

 ID  |   ActivityID    |      Progress  
  1  |        1        |  [example below..]  
  2  |        1        |  [example below..]

Where Progress is an xml of the sort:

<Progress xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <Steps>
    <ProgressStep>
      <FinishedOn>2012-10-30T13:07:52.6374861+02:00</FinishedOn>
      <Score>0</Score>
      <StartedOn>2012-10-30T13:07:45.8234861+02:00</StartedOn>
      <Status>Finished</Status>
      <StepIndex>0</StepIndex>
      <StepType>Summary</StepType>
      <UsedLifeSavers xmlns:a="http://schemas.datacontract.org/2004/07/MindLab.Logic.Study" />
    </ProgressStep>
    <ProgressStep>
      <FinishedOn i:nil="true" />
      <PartNumber>1</PartNumber>
      <Score>0</Score>
      <StartedOn>2012-10-30T13:07:52.6374861+02:00</StartedOn>
      <Status>NotFinished</Status>
      <StepIndex>1</StepIndex>
      <StepType>Information</StepType>
      <SubmittedAnswersCount>0</SubmittedAnswersCount>
      <UsedLifeSavers xmlns:a="http://schemas.datacontract.org/2004/07/MindLab.Logic.Study">
        <a:LifeSavers>Stats</a:LifeSavers>
        <a:LifeSavers>FiftyFifty</a:LifeSavers>
      </UsedLifeSavers>
    </ProgressStep>  
  </Steps>
</Progress>  

(usually there are many more than 2 steps..)

My query yields (not actual data, just sample):

 ID  |   ActivityID    |   TaskID   |    LS_HowOthersAnswered   |   LS_ImproveMyChances
  1  |        1        |      1     |             0             |             0
  2  |        1        |      1     |             1             |             0  
  3  |        1        |      1     |             0             |             0    

This is almost what I need but not quite.
I need for every unique TaskID the SUM of all LS_HowOthersAnswered and LS_ImproveMyChances.
I was trying to group by, but couldn’t make it because it’s just too different from regular inner join in that matter..

  • 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-06-13T21:54:25+00:00Added an answer on June 13, 2026 at 9:54 pm

    Found out:

    insert into [MyDB].[dbo].[Reports_ActivityStat] (ActivityID,TaskID,LS_HowOthersAnswered,LS_ImproveMyChances)
    (
    SELECT
    ActivityID=tasks.ActivityID,
    TaskID=tasks.ID,    
    SUM (CAST(
            CASE 
                WHEN CHARINDEX('stats',item.value('(UsedLifeSavers)[1]', 'NVARCHAR(MAX)'))>0
                    THEN 1 
                ELSE 0 
            END AS int)
            ),
    
    SUM (CAST(
            CASE 
                WHEN CHARINDEX('FiftyFifty',item.value('(UsedLifeSavers)[1]', 'NVARCHAR(MAX)'))>0
                    THEN 1 
                ELSE 0 
            END AS int)
            )  
    
    FROM  [MyDB].[dbo].[Tasks] as tasks CROSS APPLY [Progress].nodes ('//Progress/Steps/ProgressStep') Progress(item)
    group by tasks.ID
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following (not working) query: insert into [MyDB].[dbo].[Reports_StepsStat] (ActivityID,TaskID,StepIndex,StepStatus,TimeSpanInSeconds,Score) VALUES ( SELECT
I have the following query (all tables are innoDB) INSERT INTO busy_machines(machine) SELECT machine
I have the following query: INSERT INTO table (a, b, c) VALUES (NOW(), NOW()
I have the following PostgreSQL query: INSERT INTO persoane_alocate(pa_id_pj,pa_id_corespondent_persoana,pa_procentaj,pa_tip_persoana,pa_data_inceput,pa_data_sfarsit,pa_afisare_in_monitor,audit_data_modificarii,audit_id_utilizator) VALUES ('670', '534', '0', '1',
I have the following query to insert into a table BULK INSERT tblMain FROM
I have the following query in VBA: DoCmd.RunSQL INSERT INTO table (value) VALUES ('example')
I have the following php query... INSERT INTO `demographic2` (id, name, first_name, last_name, link,
I have this problem: If I write the following query: INSERT INTO prodotto (Barcode,
I have the following query: INSERT INTO table (a) VALUES (0) ON DUPLICATE KEY
I have following insert query: INSERT INTO `bid`.`bdate` (`id`, `bid`, `odate`) VALUES (NULL, '1',

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.