Adding an arbitrary sequential counter to a query view
I'm trying to add an ability to achieve the equivalent of a “SELECT TOP (X)” records in a Selection to restrict the number of records returned. I'm striking out.
I've come close by creating a Query View Extension using an un-ordered ROW_NUMBER. When run in SSMS it seems to do exactly what I'm looking for. However, when used in CRM, it returns the same counter values for each Constituent consistently - not an arbitrarily numbered list. It's unclear to me what the counter becomes tied to. It doesn't seem relate to the clustered index, sequenceid or anything else I've looked at.
From SSMS, I am able to get a similarly wrong result when I also add a pseudo RANDOM field and then sort by that - which, of course, is my ultimate goal. When I do that - the COUNTER field also becomes consistent. I'm guessing these things are related - I just don't understand how or what I might be able to do about it.
These give me what I'm looking for:
SELECT TOP 100 ID, LOOKUPID, COUNTER, RANDOM FROM V_QUERY_CONSTITUENT ORDER BY DATEADDED
SELECT TOP 100 ID, LOOKUPID, COUNTER, RANDOM FROM V_QUERY_CONSTITUENT ORDER BY KEYNAME, FIRSTNAME
When run within CRM, it does not. Also, the following does not:
SELECT TOP 100 ID, LOOKUPID, COUNTER, RANDOM FROM V_QUERY_CONSTITUENT ORDER BY RANDOM
<QueryViewSpecExtension
xmlns="bb_appfx_queryview"
xmlns:c="bb_appfx_commontypes"
ID="DBC72166-990E-4029-A13C-76588BF6B27A"
Name="Constituent Arbitrary Counter Query Extension (custom)"
Description="An extension to the Constituent query view to add an arbitrary counter"
Author="PHS - Mitch Gibbs"
ExtendsViewName="V_QUERY_CONSTITUENT"
><AddFields>
<AddField>
<SelectClause AliasAs="COUNTER">ROW_NUMBER() OVER(ORDER BY (SELECT NULL))</SelectClause>
<OutputField Name="COUNTER" Caption="Counter" DataType="Integer" />
</AddField>
<AddField>
<SelectClause AliasAs="RANDOM">CONVERT(INT, CRYPT_GEN_RANDOM(4))</SelectClause>
<OutputField Name="RANDOM" Caption="Random number" DataType="Integer" />
</AddField>
</AddFields></QueryViewSpecExtension>
Any ideas? Or, has anyone achieved anything similar? Thanks!
Comments
-
@Mitchell Gibbs Hi! We have a forum dedicated to Blackbaud CRM API's which might get you the developer help you need. Would you like me to move this over to here: Blackbaud CRM™ APIs? Thanks!
1 -
@Crystal Bruce No. This isn't Sky or API related. This is CRM SDK-related. I would think this Developer forum would make the most sense. I appreciate the thought though! Thanks!
1 -
@Mitchell Gibbs I'm only guessing but I imagine that the SQL is being interpreted differently when being executed the web app. Have you tried making this determenistic? I've not tested to see if this generates the randomness you are looking for but this may be helpful:
ORDER BY (SELECT 1)
or you could try this which I think is more likley to work for you
ORDER BY (SELECT newid())
I've not tested either of these in SDK so I don't know if you will hit the same issue. The only other way I can think of approaching this is to stage the data in another table using a global change and building this as a child view. Thats not great though of course! I'm sure someone else will have a better suggestion than that.0 -
Dear @Mitchell Gibbs,
We'd find something like very useful. I've experimented with it before and had no luck.
There is a Blackbaud ‘idea’ for it, so please add your voice to that. See https://bbcrm.ideas.aha.io/ideas/CRM-I-3279.
I did build a limit counter into our bulk add Interaction Global Change, but even there I couldn't get it to choose the top n, it's just any n. It's still occasionally useful, but a general feature in Query would be much better.
Ciao,
David.
0
Categories
- All Categories
- 6 Blackbaud Community Help
- 213 bbcon®
- 1.4K Blackbaud Altru®
- 403 Blackbaud Award Management™ and Blackbaud Stewardship Management™
- 1.1K Blackbaud CRM™ and Blackbaud Internet Solutions™
- 15 donorCentrics®
- 360 Blackbaud eTapestry®
- 2.6K Blackbaud Financial Edge NXT®
- 656 Blackbaud Grantmaking™
- 577 Blackbaud Education Management Solutions for Higher Education
- 3.2K Blackbaud Education Management Solutions for K-12 Schools
- 939 Blackbaud Luminate Online® and Blackbaud TeamRaiser®
- 84 JustGiving® from Blackbaud®
- 6.6K Blackbaud Raiser's Edge NXT®
- 3.7K SKY Developer
- 248 ResearchPoint™
- 119 Blackbaud Tuition Management™
- 165 Organizational Best Practices
- 241 Member Lounge (Just for Fun)
- 34 Blackbaud Community Challenges
- 37 PowerUp Challenges
- 3 (Open) PowerUp Challenge: Grid View Batch
- 3 (Closed) PowerUp Challenge: Chat for Blackbaud AI
- 3 (Closed) PowerUp Challenge: Data Health
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Product Update Briefing
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Standard Reports+
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Email Marketing
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Gift Management
- 4 (Closed) Raiser's Edge NXT PowerUp Challenge: Event Management
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Home Page
- 4 (Closed) Raiser's Edge NXT PowerUp Challenge: Standard Reports
- 4 (Closed) Raiser's Edge NXT PowerUp Challenge: Query
- 794 Community News
- 2.9K Jobs Board
- 54 Blackbaud SKY® Reporting Announcements
- 47 Blackbaud CRM Higher Ed Product Advisory Group (HE PAG)
- 19 Blackbaud CRM Product Advisory Group (BBCRM PAG)


