I am attempting in a MS Access query to convert currency to a number string. For example $1,348.5588 to 134855. Any assistance is appreciated.
Well, that currency formatting is only for display - the column is a number.
But, you can say do this in the query:
SELECT ID, FirstName, LastName, HotelName, HotelTax,
CStr([HotelTax]) AS HotelTaxS, Description
FROM tblHotelsA
So, the query when run gives this:
Edit: User wants the number scaled by 100 - no decimal point.
Ok, then use this for the expression in the query:
SELECT ID, FirstName, LastName, HotelName, HotelTax,
CStr(format([HotelTax] * 100,"0")) AS HotelTaxS, Description
FROM tblHotelsA
And, we get this:
Related
SELECT * FROM Customers
ORDER BY Country>1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
I want to know when that compares the value of Country and 1000...,
1:what is the result after comparison?
2:what is the value of Country in this comparasion(askicode or....)?
(Country is string like usa uk and some thing like that)
Do this select:
SELECT *, Country>1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 as Comparision
FROM Customers
ORDER BY Country>1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
This will add a new column, with the name (=alias) Comparison. This will show the value of that expression.
I need to eliminate the result of the Select statement
if a certain amount of numbers appear at the end.
Example:
select name from table where registration = '1234'
if the data record is:
Joe Bin12345
I need the result to lose its registration number when printing:
Joe Bin
The result should loose its digits
only if it contains five numeric characters.
SELECT name,
REGEXP_REPLACE(name, '[0-9]{5}$', '') cleared
FROM test;
fiddle
Generate a report from the CUSTOMER table that displays the customer number (CUS_NUM), customer name (CUS_NAME), and the string "is X characters long" where X is the length of the customers name. (MySQL)
mysql> SELECT CUSTOMER_NUM, CUSTOMER_NAME, LENGTH(CUSTOMER_NAME)
-> FROM CUSTOMER;
You can do it like this:
SELECT CUS_NUM, CUS_NAME, CONCAT('is ',LENGTH(CUS_NAME), ' characters long') FROM CUSTOMER;
Hope this helps,
I am trying to integrate my WHMCS and PBX together, which i can do via mysql.
The problem is WHMCS now stores phone numbers as +44.000 000 0000 and my PBX creates the query as 07000000000 (without spaces)
I had the idea of the following, but unfortunately doesn't look at the new replaced numbers with no spaces
(SELECT REPLACE(phonenumber, ' ', '') FROM tblclients) UNION
(SELECT companyname AS name FROM tblclients WHERE phonenumber LIKE "%xxx xxx xxxx%") UNION
(SELECT companyname AS name FROM tblcontacts WHERE phonenumber LIKE "%xxx xxx xxxx%")
The actual SQL Query that goes into the the PBX is for example
(SELECT firstname AS name FROM tblclients WHERE phonenumber LIKE ‘%[NUMBER]%’) UNION
(SELECT firstname AS name FROM tblcontacts WHERE phonenumber LIKE ‘%[NUMBER]%’)
Apologies not the best at SQL queries, just looking how I can do this in a single query, as FreePBX only allows a single query, in its request.
The international phone number, for example, is +44.161 872 0248
I need it to be +44.1618720248 - I just need to remove the spaces and zero off the front of the incoming number on the PBX.
e.g. WHMCS database stored data is +44.161 872 0248
The PBX outputs the incoming number, [NUMBER] to 01618720248 - so a LIKE statement won't work As the LIKE statement would look like (LIKE "%01618720248%) not the same as whats in WHMCS database.
So my main question is how do we remove the 0 from the PBX [NUMBER] and then remove the spaces out of the data that is returned from the query?
You can create view and give pbx access to view.
You also can change sql in pbx to be any one.
Let's say I have a simple query like
SELECT ID, Name, SUM(qty * price) as Value
FROM Docs
WHERE Name like '%something%' OR Value like '%something%'
GROUP BY ID, Name
The table Docs has a record for each product that goes out of an inventory as such:
ID: the id of the document through which the product was released from the inventory (for example an invoice or a delivery note)
Name: the name of the document
qty: the number of units that were released
price: the unit price of the product in said inventory
(the actual table is a lot more complex than that but I simplified it a lot for clarity)
As you can see the query I've posted is a blanket search. I want to list all the documents with their ID, name and total value whose name or value is like some user input. However I can't actually use the Value column in the WHERE clause.
I could wrap it in another select * FROM () and do the search on that. BUT the query I have to work with is a lot more complex and changing it in that way would be a whole lot of trouble.
IS there any way to avoid wrapping the whole query if I want to do this kind of search?
Will HAVING do the same thing?
SELECT ID, Name, SUM(qty * price) as Value
FROM Docs
HAVING Value like '%something%' OR Name like '%something%'
If you dont want to make "select from select" UNION can help you:
(SELECT ID, Name, SUM(qty * price) as Value
FROM Docs
WHERE Name like '%something%')
UNION
(SELECT ID, Name, SUM(qty * price) as Value
FROM Docs
HAVING SUM(qty * price) like '%something%')
Let's try
SELECT ID, Name, SUM(qty * price) as Value
FROM Docs
having Value like '%something%' or Name like '%something%'
SELECT ID, Name, SUM(qty * price) as Value
FROM Docs
WHERE Name like '%something%' OR Value like '%something%'
GROUP BY ID, Name
Only problem with this query is that MySQL does not allow use of aliases in WHERE clause.
So you can simple repeat the calculation in the WHERE clause, and it should work:
WHERE Name like '%something%' OR SUM(qty * price) like '%something%'
Don't worry about having the same calculation twice in your query - the query optimizer should recognize that and still calculate the value only once.
(And btw., using LIKE on a numerical value seems kinda strange - other comparison operators such as =, <, > might be more appropriate.)