+1 is in front of some cellular numbers how to remove +1 - arrays

I have cellular phone numbers I need to run query against another table with celluar phone numbers but specific cells in the phone number column have +1 before the phone number and specific cells do not have +1 in front of cellular phone numbers.
Where specific cells in a column have +1 in front of the cellular phone number how to modify by removing +1 if exists.

Usually the cellular phone numbers are 10 digits in length. So, You can select the Phone numbers which are greater than the length of 10 and overwrite those values with the last 10 digits (length_Of_Cell_Value-10 to length_Of_Cell_Value). So that the exact phone number without the country code is overwritten at the respective cell value..

Related

Best method for storing a decimal number with varying number of decimal places

We need to store decimal numbers (unit prices) in a database table. The problem is that we need to store and display the same number of decimal places the end-user has given as user input. The maximum number of decimal places is 6. So, for example:
1.00
9.9999
0.123456
To start with, for example, DECIMAL(10,6) seems to always store the maximum number of decimals (6).
MONEY stores a varying number of decimals (2-4), but not more than 4 (and has some other issues, why we do not want to use it).
We know that formatting should always be done on the client that uses the data, but it would be nice, if we could query the data so that the query result would have the correct number of decimals automatically.
We are prepared for adding another column that stores the number of decimal places given by the user, and then use that column to format the data for display, but that sounds a bit complex.
If we add another column, is it possible to format the decimal value directly in the query using that column?
Two soutions I can think of:
As you've already mentioned, store it in text
Store it in decimal(19,6)
Store the number of decimals in another field, i.e. 3
Use a calculated column to render the format, i.e. FORMAT()
You'd need to reverse engineer the number of decimals though.
This is more complicated but at least you can store the number in a numeric field and have SSMS render what you want.
CREATE TABLE MyTable (
NumericValue DECIMAL(19,6) NOT NULL,
Decimals TINYINT NOT NULL,
Formatted AS (FORMAT(NumericValue,'#.' + LEFT('00000000',Decimals)))
)
INSERT INTO MyTable (NumericValue, Decimals)
SELECT 10.2,3 UNION ALL
SELECT 1.2,1 UNION ALL
SELECT 1,3
SELECT * FROM MyTable
We can use decimal by Storage LAW :
decimal (1,9) Storage bytes is 5
decimal (10,19) Storage bytes is 9
decimal (20,28) Storage bytes is 13
decimal (29,38) Storage bytes is 17
About Money :
If you have a sensitive business do not use MONEY.
Money does not need to save us.
For example: We discount the whole invoice. If we want to divide this value for rows in the future, a third decimal place is likely to be created. And if you use Mani this value should be truncated, which will result in a Trending error.
The use of decimals allows the error coefficient to be reduced.
you can know about decimal in DocMicrosoft

how to write a query with constraint of 'phone number has 4 consecutive digits between 0 and 2 inclusive' in sql

So far i tried doing this, but it is wrong
Phone like '[0-2][0-2][0-2][0-2]'
Right now you check, if the phone number consists only of four digits between 0 and 2. You need to add wildcards if there can be more characters in the phone number.
If the four digits can appear anywhere in the string use:
CHECK (phone LIKE '%[0-2][0-2][0-2][0-2]%')
If they can only appear at the beginning use:
CHECK (phone LIKE '[0-2][0-2][0-2][0-2]%')
If they can only appear at the end use:
CHECK (phone LIKE '%[0-2][0-2][0-2][0-2]')

How to make Alexa speak phone number

I want Alexa to say phone number as digits not as its value.
Ex:
[Alexa] the contact number is 9 8 7 6 5 4 3 2 1 0.
But now Alexa says as
the contact number is nine billion eight hundred seventy six million
five hundred forty three thousand two hundred ten
Thanks
Use interpret-as="telephone" attribute of say-as tag of SSML to interpret the number as a telephone number.
Ex:
<speak>
the contact number is <say-as interpret-as="telephone"> 9876-543-210 </say-as>
</speak>
interpret-as="telephone" will interpret a value as a 7-digit or 10-digit telephone number. This can also handle extensions (for example, 2025551212x345).
It's always a good idea to include "-" in between phone number to give breaks while saying the digits.
More on SSML here

Database storing: pure or encoded?

A simple question. How should I store telephone numbers and e-mail adresses in a database ? Just pure text (or numbers) like email#email.com or is it better to encode it with a key (a bit like how passwords are saved in databases). In that case it becomes unreadable (and much longer) unless you know the key.
The only reason for that would be if someone hacks the databsae, and let's say they are many important e-mails and telephone numbers in the database.
How does, for example, linkedIn and facebook keep all this data?
Telephone numbers are semi-unique Id's. They are not numeric quantities or counts. They can be digits and in some cases alphanumeric, e g. 1-(800)-flowers.
Store the telephone numbers as text as you don't want to add, subtract, multiply or divide them. You can normalize the numbers into county code, and area code and number if there is a need to search by country or area code. An alternative is to provide a functions to access the a telephone number text string and derive the county code and area code.
Another important aspect do you store the format codes ( parens, spaces symbol, or dashes) for the numbers '(123) 456-7890' or do you strip these out and store only digits. If you want to have semi-uniqueness or be able to search for equality then just store the digits. Some numbers are
special codes like '*82' do want to allow these as number as well?
I you wish to derive any intelligence from the telephone number then you should base the number's structure on the text fields based on the North American Numbering Plan https://en.wikipedia.org/wiki/North_American_Numbering_Plan.

Uniquely identify a big number with a smaller one (for data base index)

I have a "fact" transaction table where a ticket has several transactions, each transaction is a registry.
To identify a ticket I have to group the table with 5 fields, (4 numbers and a date) that results in a 22 digit number, but to be able to use it effectively, it needs to be 19 digit max.
The total number of tickets that the table could store is a 10 digit number max.
How can I obtain a <= 19 unique number, from a 22 unique number composed by 5 numbers (including date transformed)?
It sounds like a hash to me, but I dont know much about them, and need it to be unique and numeric.
I think you'll struggle to find a hash function that can take arbitrary (unknown) input data and guarantee you a unique output.
The simplest solution would just be to add an autoincrement field to your table.

Resources