I need to display numbers in Arabic in a report developed in SSRS. I am able to display numbers such as 23000.00 in Arabic by setting the Language property to "ar-SA" and NumeralVariant to 3. However this doesn't work for TextBox that display date in the format dd/MM/yyyy.
Any help appreciated.
It appears there isn't a built in way to do this, so you have to do it manually in your dataset query. I would recommend returning both a date type and your Arabic date as a nvarchar to retain filtering and ease of date logic. If you cannot be bothered to use the below on all your dates you could wrap the replace logic into a function:
declare #d date = '20171231';
select #d as DateValue
,convert(nvarchar(10), #d,103) as StringValue
,replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
convert(nvarchar(10), #d,103)
,'0',N'٠')
,'1',N'١')
,'2',N'٢')
,'3',N'٣')
,'4',N'٤')
,'5',N'٥')
,'6',N'٦')
,'7',N'٧')
,'8',N'٨')
,'9',N'٩') as ArabicValue
Output:
+------------+-------------+-------------+
| DateValue | StringValue | ArabicValue |
+------------+-------------+-------------+
| 2017-12-31 | 31/12/2017 | ٣١/١٢/٢٠١٧ |
+------------+-------------+-------------+
Create the following function in the SSRS report.
Public Function ToArabicNumber(input As String) As String
Dim output As String
output = input.Replace("1","١")
output = output.Replace("2","٢")
output = output.Replace("3","٣")
output = output.Replace("4","٤")
output = output.Replace("5","٥")
output = output.Replace("6","٦")
output = output.Replace("7","٧")
output = output.Replace("8","٨")
output = output.Replace("9","٩")
output = output.Replace("0","٠")
Return output
End Function
And consume in the report using expression as follows
=Code.ToArabicNumber(Format(DateTime.Today,"dd/MM/yyyy"))
Related
I am trying to import a CSV file that has a datetime string in this format '43924.84611'. I am at a loss as to how to convert this into a readable datetime string.
Have tried:
STR_TO_DATE()
CAST()
CONVERT()
Any help would be appreciated.
Tom
Please try
select from_unixtime(round('43924.84611')) as datetime;
Result:
"1970-01-01 12:12:05"
datetime string in this format '43924.84611'.
Looks like Excel-encoded '2020-04-03 20:18:24'.
If so then
SET #val := 43924.84611;
select from_unixtime((#val - 25569)*86400)
| from_unixtime((#val - 25569)*86400) |
| :---------------------------------- |
| 2020-04-03 21:18:23.904000 |
db<>fiddle here
I'm having an issue with this apps script that's attempting to add data to my Google Cloud database. The problem variables are Open, High, Low, Close; which are all values found by formulas in the 'RAW' sheet. The formulas behind Open, High, Low, Close looks like this:
=round(index(B6:B35,match($A$3,$A$6:$A$35,0))/index(AUD!C:C,match(A3,AUD!A:A,0)),8)
When the query tries to execute the getValue() is returning #N/A, as is getDisplayValue(), which doesn't align with the table parameters.
The problem only occurs when the reference cells include formulas, when I change those cells to integers to test it goes through to the db no problem.
Is there a different way to do this, or stop getValue() returning #N/A?
Many thanks!
OM.
function insert() {
// RAW Variables
var date_ = Utilities.formatDate(SpreadsheetApp.getActiveSpreadsheet().getSheetByName('RAW').getRange('A3').getValue(), "GMT+10", "yyyy-MM-dd");
var open_ = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('RAW').getRange('B3').getValue()
var high_ = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('RAW').getRange('C3').getValue()
var low_ = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('RAW').getRange('D3').getValue()
var close_ = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('RAW').getRange('E3').getValue()
var volume_= SpreadsheetApp.getActiveSpreadsheet().getSheetByName('RAW').getRange('F3').getValue()
// Connection Variables
var connectionName = '.....';
var user = '.....';
var userPwd = '......';
var db = '.....';
var dbUrl = 'jdbc:google:mysql://' + connectionName + '/' + db;
var conn = Jdbc.getCloudSqlConnection(dbUrl, user, userPwd);
var stmt = conn.createStatement()
// Query
var query="insert into test(Date, Open, High, Low, Close, Volume) values('"+date_+"','"+open_+"','"+high_+"','"+low_+"','"+close_+"','"+volume_+"')"
stmt.execute(query)
stmt.close()
conn.close()
}
Update:
Adding iferror() to the begging of the formulas I was able to get the error value through to the table, however that's not an ideal result for me.
The fact that getValue() or getDisplayValues() doesn't return the result of the formula is my biggest concern. What is most strange is that the right most column is also a formula: =index(F6:F35,match($A$3,$A$6:$A$35,0))
The only difference between that formula and the problem ones is a division operator '/'. Any thoughts regarding that?
Outside of testing on the insert query I've also been testing by using the Open, High.. to cell.setValue(), within sheets, and getting the same #N/A result.
| 2018-05-13 | 11278.421244330 | 11620.21125128 | 11118.99605973 | 11554.50481772 | 5866380000 |
| 2018-05-14 | 11576.562811400 | 11799.80070418 | 11118.00969906 | 11581.46548861 | 7364150000 |
| 2018-05-15 | 11657.201395350 | 11832.62472130 | 11324.11133355 | 11396.32950125 | 6705710000 |
| 2018-05-16 | 0.000000000 | 0.00000000 | 0.00000000 | 0.00000000 | 6760220000 |
+------------+-----------------+----------------+----------------+----------------+-------------+
Result from insert query ^
Use IFERROR to eliminate N/A and #DIV/0!
=IFERROR(formula, "value to display if an error occurs")
I can't test yours but I'd say this is what you are looking for:
=IFERROR(round(index(B6:B35,match($A$3,$A$6:$A$35,0))/index(AUD!C:C,match(A3,AUD!A:A,0)),8), 0)
getValue() will now always return 0 or the result.
I had a similar problem when trying to get information from a query with importrange. I think you can't use data from an importrange as a value, though it could be the combination of have both. If your index value in the formula is an importrange data it probably is the reason.
I was trying to make a dynamic formula to paste on my sheets based on the selected column. It kept giving the #N/A while I tried to get information of the column from the importrange. As soon as I went from a match that used the importrange data to a calculated way to determine the column it worked.
I got an XML file looking like this:
<ns0:Currency xmlns:ns0="http://bla.bla.Currency">
<Currency>
<IntComp>08</IntComp>
<Active>1</Active>
<Currency>USD</Currency>
<Text>US Dollar</Text>
</Currency>
</ns0:Currency>
Edit: I need to take all these fields inside Currency and fit them into table, this should work for all files looking like this. Not only these values.
I want to put these values into my sql table which have the same columns, i would like to Merge these values into the table so it will Update if the IntComp value && Currency match match with another file. And it will Insert if the file doesnt match.
I havent figured out how to write this sql query.
EDIT:
The tables look like this.
dbo.Integration
ID | XMLData | Entity | EntityId | Action | ....
XMLData is the string with XMLData that i want to send to another table and pick out those node from that field.
The other table:
dbo.Currency
ID | IntComp | Active | Currency | Text
This is what ive been trying so far:
SELECT XMLData.value('(/ns0:Currency xmlns:ns0="http://bla.bla.Currency/Currency/IntComp/node())[1]', 'int') as intComp,
XMLData.value('(/ns0:Currency xmlns:ns0="http://bla.bla.Currency/Currency/Active/node())[1]', 'int') as Active,
XMLData.value('(/ns0:Currency xmlns:ns0="http://bla.bla.Currency"/Currency/Currency/node())[1]', 'varchar(10)') as Currency,
XMLData.value('(/ns0:Currency xmlns:ns0="http://bla.bla.Currency"/Currency/text/node())[1]', 'varchar(MAX)') as Active
FROM dbo.Integration
May be you can try something like this..
DECLARE #DocHandle AS INT;
DECLARE #XmlDocument AS NVARCHAR(1000);
SET #XmlDocument = '<ns0:Currency xmlns:ns0="http://bla.bla.Currency"><Currency><IntComp>08</IntComp><Active>1</Active><Currency>USD</Currency><Text>US Dollar</Text></Currency></ns0:Currency>';
EXEC sys.sp_xml_preparedocument #DocHandle OUTPUT, #XmlDocument,'<ns0:Currency xmlns:ns0="http://bla.bla.Currency"/>';
MERGE INTO tmp1 AS TGT
USING (SELECT IntComp,Active,Currency,Text FROM OPENXML (#DocHandle, '/ns0:Currency/Currency',11) WITH (IntComp INT,Active INT,Currency varchar(10),Text nvarchar(100)))
AS SRC ON SRC.IntComp = TGT.IntComp and SRC.Currency = TGT.Currency
WHEN MATCHED THEN UPDATE
SET TGT.IntComp = SRC.IntComp , TGT.Currency = SRC.Currency
WHEN NOT MATCHED THEN INSERT
VALUES(SRC.IntComp,SRC.Active, SRC.Currency, SRC.Text);
select * from tmp1
I'm currently developing a search & replace function for my application and I want it to be able to replace a specified string at the beginning/end of a string.
For example:
string = "DadaLalaDada"
gets
string = "DuduLalaDada"
when a search & replace at the beginning of the string with
search = "Dada"
replace = "Dudu"
is performed.
How can I do this in MySQL? I use REPLACE to hit every occurrence in a string, but how to perform this only at the beginning/end?
If you're willing to have the relevant values appear multiple times in your query, this seems to work:
select tab.val,
concat(replace(substring(tab.val, 1, char_length('Dada')), 'Dada', 'Dudu'),
substring(tab.val, char_length('Dada') + 1)) as replace_beginning,
concat(substring(tab.val, 1, char_length(tab.val) - char_length('Dada')),
replace(substring(tab.val, -char_length('Dada')), 'Dada', 'Dudu')) as replace_end
from ( select "DadaLalaDada" as val union select "BlahDadaBlah" ) as tab
Results:
+--------------+-------------------+--------------+
| val | replace_beginning | replace_end |
+--------------+-------------------+--------------+
| DadaLalaDada | DuduLalaDada | DadaLalaDudu |
| BlahDadaBlah | BlahDadaBlah | BlahDadaBlah |
+--------------+-------------------+--------------+
I recently recoded one of my sites, and the database structure is a little bit different.
I'm trying to convert the following:
*----*----------------------------*
| id | file_name |
*----*----------------------------*
| 1 | 1288044935741310953434.jpg |
*----*----------------------------*
| 2 | 1288044935741310352357.rar |
*----*----------------------------*
Into the following:
*----*----------------------------*
| id | file_name |
*----*----------------------------*
| 1 | 1288044935741310953434 |
*----*----------------------------*
| 2 | 1288044935741310352357 |
*----*----------------------------*
I know that I could do a foreach loop with PHP, and explode the file extension off the end, and update each row that way, but that seems like way too many queries for the task.
Is there any SQL query that I could run that would allow me to remove the file exentision from each field in the file_name column?
You can use the REPLACE() function in native MySQL to do a simple string replacement.
UPDATE tbl SET file_name = REPLACE(file_name, '.jpg', '');
UPDATE tbl SET file_name = REPLACE(file_name, '.rar', '');
This should work:
UPDATE MyTable
SET file_name = SUBSTRING(file_name,1, CHAR_LENGTH(file_name)-4)
This will strip off the final extension, if any, from file_name each time it is run. It is agnostic with respect to extension (so you can have ".foo" some day) and won't harm extensionless records.
UPDATE tbl
SET file_name = TRIM(TRAILING CONCAT('.', SUBSTRING_INDEX(file_name, '.', -1) FROM file_name);
You can use SUBSTRING_INDEX function
SUBSTRING_INDEX(str,delim,count)
Where str is the string, delim is the delimiter (from which you want a substring to the left or right of), and count specifies which delimiter (in the event there are multiple occurrences of the delimiter in the string)
Example:
UPDATE table SET file_name = SUBSTRING_INDEX(file_name , '.' , 1);