Showing posts with label phone. Show all posts
Showing posts with label phone. Show all posts

Monday, March 19, 2012

nested list with mutil-dataset

Hi, All,

I need to have a report with summary and details. The summray list is 'EmpolyeeID' and 'Name'. The details are 'emails' and 'phone numbers'. One Employee could have one or more emails, and one or more phone numbers.

The dataset are
1. select EmployeeID, Name from Empolyee
2. select EmployeeID, email from Emails where EmployeeID = @.ID
3. select EmployeeID, PhoneNumber from PhoneNumbers where EmployeeID = @.ID

I'd like to have one summary list with dataset 1. The list contains two nested lists, one for email, the other for phone numbers.

How to do it? Thanks!

-Zhining Zhang

Probably the easiest way is to create single flat dataset, then group top list by EmpoyeeID|||

1. I can use subreport, but I prefer nested list.

2. In msdn, http://msdn2.microsoft.com/en-us/library/ms157134.aspx, it is said

Nested Data Regions
You can nest data regions within other data regions. For example, if you want to create a sales record for each sales person in a database, you can create a list with text boxes and an image to display information about the employee, and then add table and chart data regions to show the employee's sales record.

Is there any sample?

Thanks!

Monday, February 20, 2012

Need to Strip non-numerics from phone field

I tried searching forums for the last hour and could not find much.

Rather then doing...

REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(RE PLACE(ISNULL(PHONE, ''), ' ', ''), '(', ''), ')', ''), '-', ''), '.', ''), ':', ''), '+', '')

I was hoping there was an equally efficient alternative that utilizes PATINDEX('%[^0-9]%', PHONE)

to some capacity (i.e. uses regular expressions to strip all non-numeric characters from the phone field)

I am certain this has been addressed before, just not sure if the "REPLACE to the nth degree" is the only solution.

THANKS!Any way to make this recursive based on the actual length in the field? Or would I take a performance hit?

SELECT
CASE WHEN SUBSTRING( PHONE , 1 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE , 1 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE , 2 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE , 2 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE , 3 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE , 3 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE , 4 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE , 4 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE , 5 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE , 5 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE , 6 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE , 6 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE , 7 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE , 7 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE , 8 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE , 8 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE , 9 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE , 9 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,10 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,10 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,11 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,11 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,12 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,12 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,13 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,13 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,14 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,14 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,15 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,15 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,16 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,16 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,17 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,17 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,18 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,18 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,19 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,19 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,20 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,20 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,21 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,21 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,22 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,22 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,23 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,23 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,24 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,24 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,25 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,25 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,26 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,26 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,27 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,27 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,28 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,28 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,29 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,29 , 1 ) ELSE '' END +
CASE WHEN SUBSTRING( PHONE ,30 , 1 ) LIKE '[0-9]' THEN SUBSTRING( PHONE ,30 , 1 ) ELSE '' END
AS NUMERICVALUEONLY
FROM COUNCIL_MEMBER|||I'd use one of my old handy-dandys that I wrote for just this kind of job!CREATE FUNCTION dbo.fNumeric(@.pcIn VARCHAR(100)) RETURNS VARCHAR(100) AS
BEGIN
DECLARE @.i INT

SET @.i = PatIndex('%[^0-9]%', @.pcIn)

WHILE 0 < @.i
BEGIN
SET @.pcIn = Stuff(@.pcIn, @.i, 1, '')
SET @.i = PatIndex('%[^0-9]%', @.pcIn)
END

RETURN @.pcIn
END
GO-PatP|||I'd use one of my old handy-dandys that I wrote for just this kind of job!CREATE FUNCTION dbo.fNumeric(@.pcIn VARCHAR(100)) RETURNS VARCHAR(100) AS
BEGIN
DECLARE @.i INT

SET @.i = PatIndex('%[^0-9]%', @.pcIn)

WHILE 0 < @.i
BEGIN
SET @.pcIn = Stuff(@.pcIn, @.i, 1, '')
SET @.i = PatIndex('%[^0-9]%', @.pcIn)
END

RETURN @.pcIn
END
GO-PatP

While it looks pretty, it doesn't look very efficient - it does give me an idea though, I'll post back if I have a more elegant solution then my last post.|||Something like this might work if I packaged it into a UDF, not sure how much of a performance hit I would take with the While loop (I know very similar to what Pat posted - ok nearly identical) :)

DECLARE @.phone VARCHAR(100)
SELECT @.phone = '123ab 34 902x:a123ab 34 902x:a'

WHILE (PATINDEX('%[^0-9]%', @.phone) > 0)
SELECT @.phone = REPLACE(@.phone, SUBSTRING(@.phone, PATINDEX('%[^0-9]%', @.phone), 1), '')

SELECT @.phone|||The only difference is he gets Estimated Row Size of 61 while yours holds at 4 regardless of the string length and contents.|||The only difference is he gets Estimated Row Size of 61 while yours holds at 4 regardless of the string length and contents.I'm not sure that I understand the significance of that comment, but Ok. The PatIndex() call is (or at least was when I wrote this) expensive in terms of both time and resources consumed, so I was trying to minimize those calls.

-PatP|||Nothing significant, Pat, I was just trying to identify the differences, that's all ;)