web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics RMS (Archived)

Worksheet Status numbers in SQL database!

(0) ShareShare
ReportReport
Posted on by

Hi, I am trying to make couple of query that pulls the data if there are Red Flag or HQ Client is not connected to the server for certain period of time. All my stores are connect to server every hours. So if HQ Client is turned off and passed the connection time, it will how Blue Flag with a exclamation mark.

My idea is to using SQL Server Agent Job to run every hour to pull data from Worksheet that has the RED FLAG worksheet and pull data that has the Blue Flag with a exclamation mark.

So I come up with a query here and it is not really what I am looking for.

SELECT * FROM Worksheet WHERE EffectiveDate > DateAdd(hh,-5,GetDate()) AND Style=401 AND Status=2

I thought this will pull only worksheet that has not been processed for 5 hours ago... but Status 2 not the one with exclamation mark. 

SELECT * FROM Worksheet WHERE Status=5

This will pull that has red flag.

Can anyone help me finding correct flag? or the numbers?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at
    RE: Worksheet Status numbers in SQL database!

    What about the following query? I made it long time ago and it summarizes the connection status of all stores

    select t1.*,t2.online,t3.lastconnected

    from

    (select Region,storecode,store.name,store.id as storeid,count(*) as WSCount

    from store left join worksheetstore

    on store.id=storeid

    where worksheetstore.status=0

    group by region,storecode,store.name,store.id)t1

    left join(

    select distinct storeid, Online=case when worksheetstore.status=0 then 'no' else  'yes' end

    from worksheetstore left join worksheet

    on worksheetid=worksheet.id

    where style=101 and (worksheetstore.status=1 or worksheetstore.status=0)

    ) t2 on t1.storeid=t2.storeid

    left join (select store.id as ThestoreID,max(eventtime) as LastConnected

    from store left join HQEventlog

    on store.id=storeid

    group by store.id) t3 on t1.storeid=t3.thestoreid

    order by online desc,wscount

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Worksheet Status numbers in SQL database!

    This is another one that could be more helpful: -

    --worksheet.status=3 in progress

    --worksheet.status=5 completed with errors

    --worksheet.status=7 completed with warning

    --worksheet.status=3 in progress

    --worksheetstore.status=3 warning

    --worksheetstore.status=1 processed successfully

    --worksheetstore.status=0 not processed

    --worksheetstore.status=2 processed with error

    select region,storecode,t1.TheStoreID,storename,lastconnected,last401succeeded,lastworksheetsucceeded

    from

    (select store.region,storecode,store.id as ThestoreID,store.name as StoreName,max(eventtime) as LastConnected

    from store left join HQEventlog

    on store.id=storeid

    group by store.region,storecode,store.id,store.name) t1

    inner join

    (select store.id as TheStoreID,max(dateprocessed) as Last401Succeeded

    from store left join WorksheetStore on store.id=WorksheetStore.storeid and Worksheetstore.Status=1

    left join worksheet on worksheet.ID=worksheetStore.WorksheetID and style=401

    group by store.region,storecode,store.id,store.name) t2

    on t1.thestoreid=t2.thestoreid

    inner join

    (select store.id as TheStoreID,max(dateprocessed) as LastWorksheetSucceeded

    from store left join WorksheetStore on store.id=WorksheetStore.storeid and Worksheetstore.Status=1

    group by store.region,storecode,store.id,store.name) t3

    on t1.thestoreid=t3.thestoreid

    order by region,storecode,t1.TheStoreID

    A Nashat

  • Community Member Profile Picture
    on at
    RE: Worksheet Status numbers in SQL database!

    Thank you so much Nashat!

    I have added "where lastworksheetsucceeded < DateAdd(hh,-5,GetDate())"

    So it will show me the result where stores are not connected within 5 hours.

    I have added to my schedule task to send me the result once every night.

    Thank you!!!!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics RMS (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans