I am using Access Update Query to change a column to the first 5 digits, I got that part. But I ALSO need the last digit to go up one. So if its 12345 I need it to be 12346.
This is what I have so far:
Left([Num],5)
Try this:
CLng(Left([Num], 5)) + 1
The CLng is only necessary if the original column isn't already a number field.
Related
I created a table with a column containing numbers listed from 1 to 100. I want to delete numbers that divide by 3 without any remainder. Who can recommend me a way (script) to do that. Only logic I could make in this problem is that if the sum of digits of a number can divide by 3 that means any number which correspond to that case could be divisible.
If you are looking to delete the rows with number divisible completely by 3, you can use built-in modulus function
You could say something like this
delete
from myTable
where colNumber%3 = 0
This query should solve your problem
DELETE FROM table WHERE (id % 3) = 0;
I have a field to pull account numbers which have different lengths and I want to pass the last four digits of the account number. The dilemma I am having is that since they are different lengths I am having trouble in substringing the fields. The standard length is 11 digits but there are accounts with 9 digits and 7 digits.
How do I substring those values in multiple substrings to capture all the account last 4 digits in one query?
This currently what I have:
SELECT SUBSTRING(ACCT_NBR,7,4) AS BNK_ACCT_NBR
FROM NAMEOFTABLE;
I want to have additional substrings to capture the account numbers that don't have 11 digits similar to
SUBSTRING(ACCT_NBR,5,4)
SUBSTRING(ACCT_NBR,4,4)
The results should look like:
76587990891 - 0891
654378908 - 8908
45643456 - 3456
Can you please help me in figuring out how I can do that?
Thanks.
Is ACCT_NBR a VarChar or an INT?
VarChar:
Right (ACCT_NBR,4)
Substr(ACCT_NBR,Char_Length(x)-3)
INT:
ACCT_NBR MOD 10000
I am trying to do a query in SQLite3 to order a column by numerical value. Instead of getting the rows ordered by the numerical value of the column, the rows are ordered alphabetically by the first digit's numerical value.
For example in the query below 110 appears before 2 because the first digit (1) is less than two. However the entire number 110 is greater than 2 and I need that to appear after 2.
sqlite> SELECT digit,text FROM test ORDER BY digit;
1|one
110|One Hundred Ten
2|TWO
3|Three
sqlite>
Is there a way to make 110 appear after 2?
It seems like digit is a stored as a string, not as a number. You need to convert it to a number to get the proper ordering. A simple approach uses:
SELECT digit, text
FROM test
ORDER BY digit + 0
I have an requirement to reduce the column value to number(5) from number(6). For this i do not want to alter the column and instead just wanted to update the data using SQL query.
Example:
From to
123456 12345
135790 13579
i.e. i just wanted to remove the last digit.
If you are looking to remove the last digit of a number, you can use :
floor(original_value/10)
If you want to remove the last digits only from numbers that have exactly 6 digits, you want :
decode(length(original_value), 6, floor(original_value/10), original_value)
I apologize if this question was asked before I just couldn't correctly formalize it. I have a code column in a table and want to query it but remove some elements with some particular code. Say I want to take elements with code starting from 4 but not include the elements with code whose 6-th number is 9 (1121290).
The code column contains string of numbers with max-length of 8 char. and I want to take almost everything that starts with 4 except elements that start with 411, 427 and 428
Yes you can give query like this:--
I have column element with 6 digit codes.
I am fetching element whose 1st digit is 4 or 6th is 9.
we have to use % and _ for fetching..
SELECT element FROM "table" WHERE element LIKE '%4____9%';
try this it will work.
Everything that starts with 4 except elements that start with 411, 427 and 428 :-
SELECT element FROM "table" WHERE element LIKE '%4__';
1st digit is 4 and 6th is not 9: I tested this one it is working fine try this :-
SELECT element
FROM "table"
WHERE element NOT LIKE '%_____9' and element LIKE '%4_____'
It might be easiest to simply spell out each condition in the where clause:
WHERE code like '4____9%' AND code NOT LIKE '411%' AND code NOT LIKE '427%' AND code NOT LIKE '428%'
The extra conditions won't hurt the query's efficiency much; it's going to have to scan every single row starting with 4 anyway.
Assuming that your "CODE" field is varchar and you are using SQL Server,
you can use the below Query
select * from yourTable
where code like '4%'
AND CHARINDEX('9',code)<>6
Here is a more compact version.
`SELECT * FROM table_name WHERE code IN ('4%') and code NOT IN ('411%','427%', '428%','_____9%');`