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
Related
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
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
I have two dialoglist fields Cutt_Start and Cutt_End, both of the fields has example choices of: January | 1
February | 2
March | 3
...
December | 12
Now, what I want to happen is that, when you select January on the Cutt_Startand March on the Cutt_End, it should prompt an error that Month2 should be next to Month1. I tried this code, but nothing happens.
If Cutt_Start = "January" & Cutt_End <> "February" Then
Msgbox "Month2 should be next to Month1"
Else
Msgbox "January to February selected"
End If
Can you help me?
As already mentioned, the stored field values are the ones right of the pipe. BUT: such fields are always text- fields!!!!
To do a computation, you need to transform the text to numbers...
_start := #TextToNumber( Cutt_Start );
_end := #TextToNumber( Cutt_End );
_res := _end - #Modulo(_start; 12)
#If( !#IsError(_res) &_res != 1; #Failure( "your message" ); #Success)
This goes into the field validation of the Cutt_end- field.
If you need LotusScript (to have it in the QuerySave or the OnChange-Event of the field, then the code would be:
Option declare
Dim ws as New NotosUiWorkspace
Dim doc as NotesDocument
Set doc = ws.CurrentDocument.Document
If Cint(doc.Cutt_End) - CInt(doc.Cutt_Start) <> 1 then
messagebox "your Message"
End if
This code does NOT contain any errror handler.
And as mentioned in the other comments: this for sure is not the right way to do it. If cut_end always has to be one month later, then simply change it to computed and write as value:
#If(Cutt_Start = ""; ""; #Text(#Modulo(#TextToNumber( Cutt_Start ); 12) + 1))
Then you would not need to make your check...
The number to the right of the pipe character is the value of the field. The name to the left of the pipe is what is displayed to the user.
So if you just test that the numbers are sequential, and add a special case for Dec to Jan (1 comes after 12) then you should get the result you are looking for.
Note that the number value is still in text format so you'll need to cast it to a number first
If Cutt_End - Cutt_Start <> 1 Then Msgbox "Error!"
That said, if the Cutt_End must always be 1 month after Cutt_Start, then why have that field at all? Just calculate that field and make the user just choose the start month.
Please check the following and put your code into the onchange event. For web and the notes client the onchange function behavior is different.
I have a stored procedure that is generating a string that it will call EXECUTE() on. The string contains an UPDATE statement. However, the columns and values that it is executing are not known beforehand. These are coming into the stored procedure through an XML string. I then use XML queries to get the data out and into a temporary table.
This is not sanitizing the data.
DECLARE #TBL_FLD TABLE (
TBL VARCHAR(MAX),
COL VARCHAR(MAX),
VAL VARCHAR(MAX)
);
-- Fill #TBL_FLD via xml parsing (omitted for brevity)
DECLARE TBL_CURSOR CURSOR FOR
SELECT distinct (TBL) FROM #TBL_FLD;
OPEN TBL_CURSOR;
WHILE 1 = 1
BEGIN
FETCH NEXT FROM TBL_CURSOR INTO #TABLE_NAME
IF ( ##FETCH_STATUS <> 0 )
BREAK
SET #SETTING_STR = '';
SELECT #SETTING_STR = STUFF( ( SELECT ', ' + COL + ' = ''' + VAL + '''' FROM #TBL_FLD WHERE TBL = #TABLE_NAME FOR XML PATH('') ), 1, 2, '');
SET #SQL_QUERY += 'UPDATE ' + #TABLE_NAME + ' SET ' + #SETTING_STR + ' WHERE KEY = ' + CONVERT(VARCHAR(MAX), #KEY_VAL) + '; ';
END
CLOSE TBL_CURSOR
DEALLOCATE TBL_CURSOR
EXECUTE (#SQL_QUERY);
I trust the COL field of #TBL_FLD, but the VAL will have come from a user. Which leaves a massive security hole since I am just concatenating the data together. There has to be a better way.
Since there are an unknown number of columns, I can't easily create parameters for the statement so that the data is cleaned up. If worst comes to worst, I can do it, (see the answer to Dynamically Create Update SQL In Stored Procedure) but it will be uglier than I would like.
Is there a function, or method, to sanitize the data, before I blindly add it to the statement? Or is there a better way to do what I'm trying to do?
I think that just doubling single quotes with a REPLACE on VAL would fix any issues since an attacker would not be able to exit the "string scope" to execute arbitrary code :
SELECT #SETTING_STR = STUFF( ( SELECT ', ' + COL + ' = ''' + REPLACE(VAL, '''', '''''') + '''' FROM #TBL_FLD WHERE TBL = #TABLE_NAME FOR XML PATH('') ), 1, 2, '');
I don't remember a built-in T-SQL function that does the same thing
My code:
tell application "iTunes"
set ofi to fixed indexing
set fixed indexing to true
set sel to selection
repeat with i from 1 to (count sel)
tell (item i of my sel)
set fileLoc to the location as Unicode text
set fileLoc to my findAndReplace(":", "
", fileLoc)
--display dialog return & fileLoc buttons {"Ok"} default button 1 with icon 0
--Show Name
set showName to paragraph -3 of fileLoc
set show to (showName as text)
--Season #
set seasonNum to the last word of paragraph -2 of fileLoc
try
set season number to (seasonNum as number)
end try
--Episode #
--*****ERROR HAPPENS HERE*****
set test to the first word of the last paragraph
set episodeNum to (the word 2 of paragraph -1)
--set episode number to episodeNum as number
--Episode name
set episodeName to characters 4 thru -5 of paragraph -1 of fileLoc
set name to episodeName as text
--Video Kind
set video kind to TV show
end tell
end repeat
set fixed indexing to ofi
end tell
on findAndReplace(tofind, toreplace, TheString)
set ditd to text item delimiters
set res to missing value
set text item delimiters to tofind
repeat with tis in text items of TheString
if res is missing value then
set res to tis
else
set res to res & toreplace & tis
end if
end repeat
set text item delimiters to ditd
return res
end findAndReplace
and I get:
error "iTunes got an error: Can’t get word 1 of last paragraph of file track id 7141 of user playlist id 5157 of source id 69." number -1728 from word 1 of last paragraph of file track id 7141 of user playlist id 5157 of source id 69
The text I'm trying to parse looks like:
Users
christopher
TV Shows
How I Met Your Mother
Season 5
01 Definitions.m4v
Turns out I needed "of fileLoc" in there to make it work.