I have a column of Strings that represent hours like this: 00:11:34. And I need to sum the column but I can't do it since they are strings, moreover I can't convert it directly to ints because of the ':' in between. What should I do to get the sum of this hours and get the result in minutes?
You can use a String Tokenizer and then Integer.parseInt
StringTokenizer st = new StringTokenizer("00:11:34",":");
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
Related
Hi I am loading data from flat file to my table through SSAS I want to derive a conditional column to append zeros to is numeric data in the zip code column when the length is <5
Derived Column Expression I am using : (CustomerZipCode!="[A-Za-z]")&&(LEN(CustomerZipCode) < 5) ? RIGHT(("00000" + CustomerZipCode),5) : CustomerZipCode
ForExample
the above expression is not working,request to guide me
Thank you.
Is this for SSIS? My last answer assumed that this was an SSAS column because the SSAS tag. If this is a date load via SSIS, you can use a Script Component to do this instead of a Derived Column. The example below uses C# and the CustomerZipCode column will need to be added in the Input Columns pane with the ReadWrite usage type. The TryParse method checks if the column is numeric and will return false if the column contains any text. The String constructor is used to create the zeroesToAppend string, which is set to the number of zeroes below 5 that the length of the column is, and afterwards this is added to the beginning of the column. This will go in the Input0_ProcessInputRow method, which is executed once for each row from the input.
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
int i;
if (int.TryParse(Row.CustomerZipCode, out i) && Row.CustomerZipCode.Length < 5)
{
string zeroesToAppend = new String('0', 5 - Row.CustomerZipCode.Length);
Row.name = String.Concat(zeroesToAppend, Row.CustomerZipCode);
}
}
Do you know how to format the output of a number in hive with thousand separator? For example:
data:146452664
output:146,452,664
I use this in Teradata, but don't know how to achieve in Hive.
cast(cast(cast(number as integer) as format'ZZZ,ZZZ,ZZZ,ZZ9') as char(11))
Use the format_number() function.
select format_number(146452664,0)
The first argument is the number and second is the number of decimal places to round.If D is 0, the result has no decimal point.
Is there any way to convert the number in to string and concatenate '%' to that number. I tried writing expression for this. But what ever I have written it is giving me 0 value.
like i already had one column with number datatype and I created a new column with the name perc and given '%' to that like below.
total perc
1 %
2 %
3 %
here some how i have to concatenate this two columns.
Please help me to achieve this.
Thanks
Using open formula you can convert string into integer and then concatenate.
check sample below
=CONCATENATE(INT(field);"%")
I am trying to build a query that will return different chars from different positions on a string. I'm using this query to get just the string i'll need from a bigger string:
MID(CStr(Movimento_Estoque_Cabecalho.Importados),1,(InStr(1,CStr(Movimento_Estoque_Cabecalho.Importados),"OD")-1))
With that i'm getting a string that looks like this:
OC0=35OC1=36
I need to get only what's after the = positions.
In this case would be 35,36
The Numbers returned after the = sign may vary from 1 to 999999.
Is that possible to do?
BTW, the database i'm using is MS-ACCESS 1997
The Problem
I have a field that stores file keys, such as:
dev/application/document_type_name/document 12345-67890_123.pdf
I need to select the key without the number on the end so the value looks like:
dev/application/document_type_name/document 12345-67890_.pdf
Potential Strategy
It's been a while since I've done T-SQL but coming from the .NET side I think the general strategy would be:
Get the last index of an underscore character
Get the last index of the period character.
Replace the value between those two characters with a blank.
In C#, I think it would be something like:
var test = "dev/application/document_type_name/document 12345-67890_123.pdf"
var indexOfUnderscore = test.LastIndexOf("_");
var indexOfPeriod = test.LastIndexOf(".");
var textToReplace = subtring(indexOfUnderscore + 1, indexOfPeriod -1);
var output = test.Replace(textToReplace, String.Empty);
Notes:
Every key will have that Format
The length of the value between the underscore and the period may be different (could be 1, 12345, etc.
the end result should keep the underscore and period
Try
select left(#s,len(#s)-charindex('_',REVERSE(#s)))+'_.pdf'
where #s is your string.
Or if the file extension can change
select left(#s,len(#s)-charindex('_',REVERSE(#s))+1)
+ right(#s,charindex('.',REVERSE(#s)))