Question
· Sep 26, 2017

extract string value

Hi, i want to extract the timestamp values and order them low to hight , how can i do, you find here a screenchot of my batabase

thank's

Discussion (5)0
Log in or sign up to continue

You can write a function that returns the timestamp of your JSON array, and then SELECT it out like that.   Here's an example:

 


Class Test.JSONProp extends %Persistent
{

	Property JSON as %String (MAXLEN=1000);
	
	Property Type as %String;
	
ClassMethod GetTimestamp(str as %String) as %TimeStamp [SqlProc]
{
	try{
		s j={}.%FromJSON(str)
	    s ts=j.Biometrics.%Get(0).TimeStamp
	    return ts
	}
	catch err
	{	
		return ""
	}
}
}

The query then becomes:

SELECT ID,Type,Test.JSONProp_GetTimestamp(JSON) as TS 
  FROM TEST.JSONProp 
  ORDER BY TS

Give that a try - you'll need to probably do something different with the JSON depending on your version.