Solved

How to populate an array and compare the data

Posted on 2008-10-09
9
1,521 Views
Last Modified: 2012-05-05
Hi all,

Im wondering how/where (withing the custom code?) im able to fill an array with data.  What im doing is retrieving postal codes from clients and stripping the first 3 characters and trying to put those values into an array.  With this array i will then compare each value against a string value (will be a list of all Alberta's postal codes) and keep a count so i can then display the number of clients from that certain area of Alberta.

eg.  The array will contain thousands of postal codes (T2W, T0E, T0L, etc...) and then compare it to a string (such as T2W) and i would like it to return the total number within the array that are T2W.

Im just trying to figure out how im able to create the array within SSRS and populate it, then pass the array to another method or procedure that does the string comparison and returns a count value.

This may not be explained very well but any help is greatly appreciated.

Thanks!
0
Comment
Question by:agilebiz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 1

Expert Comment

by:timberbt
ID: 22680252
If you're really just looking to get a list or a count, why not do it all in SQL?   Could you provide a sample table structure that you're pulling from?   Should be a pretty trivial query after that if I understand correctly.
0
 
LVL 1

Expert Comment

by:timberbt
ID: 22680324
Something like this maybe....
DECLARE @SearchString VARCHAR(3)
SELECT @SearchString='T2W'
 
DECLARE @PostalCodes TABLE
(
	Code VARCHAR(6)
	)
	
INSERT @PostalCodes VALUES ('T0E123')
INSERT @PostalCodes VALUES ('T0E124')
INSERT @PostalCodes VALUES ('T2W123')
INSERT @PostalCodes VALUES ('T0L123')
INSERT @PostalCodes VALUES ('T0E125')
INSERT @PostalCodes VALUES ('T2Wzzz')
INSERT @PostalCodes VALUES ('T0L456')
 
--List matching codes
SELECT * FROM @PostalCodes
WHERE
	LEFT(Code,3) = @SearchString
 
--Get a count of matching codes
SELECT COUNT(1) AS [MatchingCount] FROM @PostalCodes
WHERE
	LEFT(Code,3) = @SearchString

Open in new window

0
 

Author Comment

by:agilebiz
ID: 22680425
My search string will be every postal code in alberta.  Basically the company wants to see how many clients came from each area of Alberta.  There are 150 differnt postal codes in Alberta so ill need to iterate through each and spit out the number of clients per area in alberta.  Attached is my select statement.  

Basically what they got me doing is retreiving the number of clients who contacted this company via certain referral methods (ie. Yellow pages, Friend, etc)  In my report i have it displaying the different types of referral sources as well as the different postal codes of the clients who contacted them (with out duplicates).  Where im having troubles is displaying the total number of referrals per postal location.

What im looking for:

Referral Source         Location              Total Referrals
Yellow Pages               T2W                           5
                                      L0E                            2
etc..
Friends                        T7E                              1
etc..
etc..
SELECT     dbo.tlkpReferralSource.refPK, dbo.tlkpReferralSource.refDescription, dbo.tblBankruptsAddress.addPostalCode, dbo.tblBankrupts.banBankruptPK
FROM         dbo.tblBankrupts INNER JOIN
                      dbo.tlkpReferralSource ON dbo.tblBankrupts.banReferralSource = dbo.tlkpReferralSource.refDescription INNER JOIN
                      dbo.tblBankruptsDates ON dbo.tblBankrupts.banBankruptPK = dbo.tblBankruptsDates.datBankruptPK INNER JOIN
                      dbo.tblBankruptsAddress ON dbo.tblBankrupts.banBankruptPK = dbo.tblBankruptsAddress.addBankruptPK
WHERE     (dbo.tblBankruptsDates.datInsolvency >= @startDate) AND (dbo.tblBankruptsDates.datInsolvency <= @endDate)
GROUP BY dbo.tlkpReferralSource.refPK, dbo.tlkpReferralSource.refDescription, dbo.tblBankruptsAddress.addPostalCode, 
                      dbo.tblBankrupts.banBankruptPK
ORDER BY dbo.tlkpReferralSource.refPK

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:agilebiz
ID: 22680440
Excuse my inability to really explain what im asking for, i have very limited knowledge in SSRS.
0
 
LVL 1

Accepted Solution

by:
timberbt earned 500 total points
ID: 22680462
Okay so you hae multiples... this is showing just locations, but I still say SQL is the right place to handle this...

Something with output more like this...
DECLARE @SearchString VARCHAR(3)
SELECT  @SearchString = 'T2W'
 
DECLARE @PostalCodes TABLE ( Code VARCHAR(6) )
        
INSERT  @PostalCodes
VALUES  ( 'T0E123' )
INSERT  @PostalCodes
VALUES  ( 'T0E124' )
INSERT  @PostalCodes
VALUES  ( 'T2W123' )
INSERT  @PostalCodes
VALUES  ( 'T0L123' )
INSERT  @PostalCodes
VALUES  ( 'T0E125' )
INSERT  @PostalCodes
VALUES  ( 'T2Wzzz' )
INSERT  @PostalCodes
VALUES  ( 'T0L456' )
 
SELECT  b.code,
        COUNT(1) [MatchingCount]
FROM    @PostalCodes a
        JOIN ( SELECT DISTINCT
                        LEFT(Code, 3) AS [Code]
               FROM     @PostalCodes
             ) b ON LEFT(a.Code, 3) = b.Code
GROUP BY b.Code

Open in new window

0
 

Author Comment

by:agilebiz
ID: 22688871
I will give this a shot and get back to you. Thanks
0
 
LVL 1

Expert Comment

by:timberbt
ID: 22689032
No problem.  It looks like you'll have to work a couple tables into that join, but doing the subselect with the distinct filter on the first 3 character of the postal code sounds like what you need.   Enjoy!

0
 
LVL 1

Expert Comment

by:timberbt
ID: 22831097
All done and working?
0
 

Author Comment

by:agilebiz
ID: 22850263
Sorry timberbt, we have decided to go with a more graphical representation of the data using mappoint, although this was helpful, Thank you.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best book for Internet security 4 55
Sorting a SQL script 5 42
I need to clear List Box in MVVM panel. 15 27
Restore a log backup compressed 3 17
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question