Clean Phone Number String - string

I have something like this
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:crm_case_add ATTR=ID:CrmCasePhoneNumber EXTRACT=TXT
All the phone numbers are in this format: 800-128-1990 or (800)128-1981 or 291 399 5913
I want it plain text like 8002893884. How can I do this?

Just add the following line into your macro:
SET !EXTRACT EVAL("'{{!EXTRACT}}'.replace(/[-()\\s]/g,'')")

For those looking to do in SQL
I use a function to clean up phone numbers which will fix all phone number issues or clears the field. Returns Null if Blank (To prevent Errors)
Print'/*Fix Phone Numbers Call*/'
Update tblTemp
Set Phone = dbo.fnPhoneFix(tblTemp.Phone)
From tblTemp
To Create the Fuction use the following code:
CREATE FUNCTION [dbo].[fnPhoneFix](#PhoneOld VarChar(20))
Returns VarChar(10)
AS
Begin
Declare #iCnt Int = 0
Declare #PhoneNew VarChar(15) = ''
IF #PhoneOld IS NULL
RETURN NULL;
While #iCnt <= LEN(#PhoneOld)
Begin
IF Substring(#PhoneOld,#iCnt,1) >= '0' AND Substring(#PhoneOld,#iCnt,1) <= '9'
Begin
SET #PhoneNew = #PhoneNew + Substring(#PhoneOld,#iCnt,1)
End
Set #iCnt = #iCnt + 1
End
If LEN(#PhoneNew) > 10 and Left(#PhoneNew, 1) = '1'
Set #PhoneNew = RIGHT(#PhoneNew,10);
Else
Set #PhoneNew = Left(#PhoneNew,10);
If LEN(#PhoneNew) <> 10
Set #PhoneNew ='';
Return #PhoneNew
End

Related

Is there a way to read .xlsx files in Applescript using Microsoft Excel scripting without opening the file?

So I was wondering if I could use the Microsoft Excel scripting in Applescript without opening the actual file. So something like this:
tell application "Microsoft Excel" to return value of cell "E10" of front sheet of "/Path/to/my/file"
Reading .xlsx files without opening them is very hard or nigh impossible. However, .csv-files store their data much more readably. You could set up something like this:
set theText to (read file "/Path/to/my/file")
set theLines to paragraphs of theText
return word 6 of (item 10 of theLines)
You could also write a function to do the work for you so you don't have to write it out every time:
on cell(theColumn, theRow, theTable)
return word theColumn of item theRow of theTable
end cell
return cell(2, 2, theLines)
Here is a bit of a bodgy function I wrote that even takes Excel-style inputs ("E10"):
on cell(theLocation, theTable)
set theChars to every character of theLocation
set letterPosition to 0
repeat with i from 1 to count of theChars
try
set dummy to item i of theChars as number
exit repeat
on error
set letterPosition to letterPosition + 1
end try
end repeat
if letterPosition is equal to 0 then display dialog "Incorrect input"
set theRow to items 1 thru letterPosition of theChars
set theColumn to items (letterPosition + 1) thru (count of theChars) of theChars as string
set theAlphabet to every character of "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set theRowNumber to 0
set theMultiplier to 1
repeat with j from 1 to count of theRow
repeat with i from 1 to count of theAlphabet
if item i of theAlphabet is equal to (item ((count of theRow) - j + 1) of theRow) then
set theRowNumber to theRowNumber + i * theMultiplier
exit repeat
end if
end repeat
set theMultiplier to theMultiplier * (count of theAlphabet)
end repeat
return word theColumn of (item theRowNumber of theTable)
end cell
return cell("AA6", theLines)
Yes, I am aware of the repeat with ... in reverse but, it somehow didn't work with this function. I have no idea why.

SSRS: How can I use a Search parameter with multiple values?

I am creating a report that the business would like to use to spot check 5, 10 or 20 records at a time.
The request was to use a Search parameter (as opposed to dropdown params).
How can I create a Search parameter that will allow for multiple values separated by a comma?
Thanks for the help.
Don't worry about the length of this answer, most of it is a cut/paste job ! I've tried to explain each bit as we go so you understand it better, the actual amount of code you need to craft is minimal.
If you have SQL Server 2016 then you can take advantage of the new string_split function, if you have an older version you'll have to create a similar function yourself, or copy the one I created a few years back which does a similar thing.
Lets get the function created first: I've created it in the fn schema but you can obviously change this to whatever schema you like.
CREATE FUNCTION [fn].[Split](#sText varchar(8000), #sDelim varchar(20) = ' ')
RETURNS #retArray TABLE (idx smallint Primary Key, value varchar(8000))
AS
BEGIN
DECLARE #idx smallint,
#value varchar(8000),
#bcontinue bit,
#iStrike smallint,
#iDelimlength tinyint
IF #sDelim = 'Space'
BEGIN
SET #sDelim = ' '
END
SET #idx = 0
SET #sText = LTrim(RTrim(#sText))
SET #iDelimlength = DATALENGTH(#sDelim)
SET #bcontinue = 1
IF NOT ((#iDelimlength = 0) or (#sDelim = 'Empty'))
BEGIN
WHILE #bcontinue = 1
BEGIN
--If you can find the delimiter in the text, retrieve the first element and
--insert it with its index into the return table.
IF CHARINDEX(#sDelim, #sText)>0
BEGIN
SET #value = SUBSTRING(#sText,1, CHARINDEX(#sDelim,#sText)-1)
BEGIN
INSERT #retArray (idx, value)
VALUES (#idx, #value)
END
--Trim the element and its delimiter from the front of the string.
--Increment the index and loop.
SET #iStrike = DATALENGTH(#value) + #iDelimlength
SET #idx = #idx + 1
SET #sText = LTrim(Right(#sText,DATALENGTH(#sText) - #iStrike))
END
ELSE
BEGIN
--If you can't find the delimiter in the text, #sText is the last value in
--#retArray.
SET #value = #sText
BEGIN
INSERT #retArray (idx, value)
VALUES (#idx, #value)
END
--Exit the WHILE loop.
SET #bcontinue = 0
END
END
END
ELSE
BEGIN
WHILE #bcontinue=1
BEGIN
--If the delimiter is an empty string, check for remaining text
--instead of a delimiter. Insert the first character into the
--retArray table. Trim the character from the front of the string.
--Increment the index and loop.
IF DATALENGTH(#sText)>1
BEGIN
SET #value = SUBSTRING(#sText,1,1)
BEGIN
INSERT #retArray (idx, value)
VALUES (#idx, #value)
END
SET #idx = #idx+1
SET #sText = SUBSTRING(#sText,2,DATALENGTH(#sText)-1)
END
ELSE
BEGIN
--One character remains.
--Insert the character, and exit the WHILE loop.
INSERT #retArray (idx, value)
VALUES (#idx, #sText)
SET #bcontinue = 0
END
END
END
RETURN
END
Once the function is created you can see what it outputs by doing something like
select * from fn.Split('Austria, Belgium, France', ',')
This returns the following
idx value
0 Austria
1 Belgium
2 France
Lets assume we have a geography table with the names of countries and their associated region, we can search for matching entries by simply joining to the output of the function something like this.
select g.CountryID, g.CountryDesc, g.ContinentDesc from dim.Geography g
join (SELECT * FROM fn.Split('Austria, Belgium, France', ',')) s
on g.CountryDesc = s.value
This, in my case, give me this output.
CountryID CountryDesc ContinentDesc
21 Austria West Europe
28 Belgium West Europe
89 France West Europe
To use the split function in your SSRS dataset, simply pass in the search text parameter so the query would now look something like this.
select g.CountryID, g.CountryDesc, g.ContinentDesc from dim.Geography g
join (SELECT * FROM fn.Split(#MySearchText, ',')) s
on g.CountryDesc = s.value

find a string in log file and search another string after the first string

i have a unique id in placed in a log file, i can search the file and get to it, once i find the unique id in the file i need to find another string (naming it string 2) after this unique id and copy the very next line of the string 2 .
Please find below my function and please suggest how to achieve this .
Func getAuthResponse($LogfilePath, $AuthRespFilePath, $UniqueId, $search)
Global $iLine = 0, $sLine = ''
Global $hFile = FileOpen($LogfilePath)
If $hFile = -1 Then
MsgBox(0,'ERROR','Unable to open file for reading.')
Exit 1
EndIf ;If $hFile = -1 Then
; find the line that has the search string
While 1
$iLine += 1
$sLine = FileReadLine($hFile)
If #error = -1 Then ExitLoop
; finding the unique id in the log file
;ConsoleWrite($UniqueId & #LF)
If StringInStr($sLine, $UniqueId) Then
ConsoleWrite($sLine & #LF)
; assuming that unique id is found , now finding the phrase Auth response is as follow : after the unique id
$sNewLine = $sLine+
If StringInStr($sLine, $search) Then
ConsoleWrite($sLine & #LF)
//// SOME LOGIC ////
ExitLoop
EndIf ;If StringInStr($sLine, $search) Then
ExitLoop
EndIf ;If(StringInStr($sLine, $UniqueId) Then
WEnd ;While 1
FileClose($hFile)
EndFunc
Lets see if I understood that correctly:
You need to find an ID, afther this ID a string and after that you need to copy the next line. If that's correct, I made you a new While Loop, it's just a For Loop now.
#include <File.au3>
For $c1 = 1 To _FileCountLines($hFile) Step +1
$sLine = FileReadLine($hFile, $c1)
If (StringInStr($sLine, $UniqueId) > 0) Then
For $c2 = $c1 To _FileCountLines($hFile) Step +1
$sLine = FileReadLine($hFile, $c2)
If (StringInStr($sLine, $search) > 0) Then
$LINE_AFTER_STRING_2 = FileReadLine($hFile, $c2 + 1)
ExitLoop
EndIf
Next
EndIf
Next
If $LINE_AFTER_STRING_2 = "" Then MsgBox(0, "NOT FOUND", "NOT FOUND")
Following things happen: First it loops through all lines and searches for your ID, if it finds it, it starts a new For Loop and searches for your string after the ID, if it finds that one it counts +1 to the line and reads it. This should be the line you are looking for. The variable is called $LINE_AFTER_STRING_2, feel free to change that.
Don't forget to include the File.au3 because i used _FileCountLines
Try this:
#include <File.au3>
Func getAuthResponse($LogfilePath, $UniqueId, $search)
Local $arrayFile = ""
Local $output = ""
If Not FileExists($LogfilePath) Then Return SetError(1, 0, -1)
_FileReadToArray($LogfilePath, $arrayFile)
For $i = 1 To $arrayFile[0]
If StringInStr($arrayFile[$i], $UniqueId) Then
For $j = $i+1 To $arrayFile[0]
If StringInStr($arrayFile[$j], $search) Then
$output = $arrayFile[$j+1]
ExitLoop
EndIf
Next
ExitLoop
EndIf
Next
Return $output
EndFunc

How to use a variable of unix at Bteq Script?

I am creating a Frame work at Unix . This frame Work calls multiple DML's at different different Stages according to the dynamic situations.
All DML's contain set of sql queries. Each query comes under a defined Lable (Say Lable 1 .... Lable 2.... etc)
I want to make this framework so good so that it can trigger the DML from the required LABEL only ....(In case of Failure and restart job)..
So for that i need to take the Unix variable($LABLE) inside the DML's.
I am not getting ...how to do this???
Please help !!!! if you ever try this.....
Sample DML -
.LOGON TDPS/admin_dxwx_p05,store123;
.LABEL FIRST
CREATE SET TABLE DXWX_P05_DLWORK_DB01.WorKTable_1 ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT,
DEFAULT MERGEBLOCKRATIO
(
Customer_Name VARCHAR(25) CHARACTER SET LATIN NOT CASESPECIFIC,
Age INTEGER,
Product_Name VARCHAR(25) CHARACTER SET LATIN NOT CASESPECIFIC,
Price INTEGER)
PRIMARY INDEX ( Customer_Name );
.IF ERRORCODE <> 0 THEN .GOTO ERRORFOUND
.LABEL SECOND
CREATE SET TABLE DXWX_P05_DLWORK_DB01.WorkTable_2 ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT,
DEFAULT MERGEBLOCKRATIO
(
Customer_Name VARCHAR(25) CHARACTER SET LATIN NOT CASESPECIFIC,
Age INTEGER
Product_Name VARCHAR(25) CHARACTER SET LATIN NOT CASESPECIFIC,
Price INTEGER)
PRIMARY INDEX ( Customer_Name );
.IF ERRORCODE <> 0 THEN .GOTO ERRORFOUND
.LABEL THIRD
Insert into DXWX_P05_DLWORK_DB01.WorKTable_1
Sel * from
DXWX_P05_DLWORK_DB01.Source_Table;
.IF ERRORCODE <> 0 THEN .GOTO ERRORFOUND
.LABEL FOUR
Insert into DXWX_P05_DLWORK_DB01.WorKTable_2
Sel * from
DXWX_P05_DLWORK_DB01.WorKTable_1;
.IF ERRORCODE <> 0 THEN .GOTO ERRORFOUND
.QUIT 0;
.label ERRORFOUND
.QUIT 8;
.LOGOFF;
EOF

SQL Server 2005: Two or more string into one string and pass as parameter [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Parameterizing a SQL IN clause?
Hi All,
I am writing a SQL command for my project. I have to pass one string parameter to cursor.
But at that parameter I have to concatenate many strings, like this:
DECLARE #strParam VARCHAR(MAX)
SET #strParam = 'string1' + ',' + 'string2' + ',' ... etc
Then I want to use like this:
SELECT * FROM tblResult WHERE Field1 IN (#strParam)
instead of the following statement:
SELECT * FROM tblResult WHERE Field1 IN ('string1' + ',' + 'string2' + ',' ... etc)
So I need to get the format as like we set above.
How can I do that?
Best Regards,
Reds
This will split the csv into a table.
CREATE FUNCTION GetIDs(
#ids_csv nvarchar(255))
RETURNS #table_ids TABLE
(
ID INT,
PRIMARY KEY(ID)
) AS
BEGIN
DECLARE #app_id varchar(10)
DECLARE #pos int
SET #ids_csv = LTRIM(RTRIM(#ids_csv))+ ','
SET #pos = CHARINDEX(',', #ids_csv, 1)
IF REPLACE(#ids_csv, ',', '') <> ''
BEGIN
WHILE #pos > 0
BEGIN
SET #app_id = LTRIM(RTRIM(LEFT(#ids_csv, #pos - 1)))
INSERT INTO #table_ids(ID) VALUES(#app_id)
SET #ids_csv = RIGHT(#ids_csv, LEN(#ids_csv) - #pos)
SET #pos = CHARINDEX(',', #ids_csv, 1)
END
END
RETURN
END
Then, you can do this:
SELECT * FROM tblResult WHERE Field1 IN (SELECT * FROM GetIDs(#strParam))

Resources