I want to be able to do a SQL Query that gets all numbers that end in .005
Select * from amount where (numbers end in X.XX5)
I don't care what the numbers are for X
I am assuming you don't care what the first and second digit after the decimal is.Try this:
select * from MyTable where MyField like '%.__5'
The % specifies a substitution for 0 or more characters, and the underscores are a substitute for a single character.
If there are digits after the 5, use
select * from MyTable where MyField like '%.__5%'
SELECT * FROM amount WHERE numbers LIKE '%.005';
Try this:-
Select * from amount where number like '%.005'
or
Select * from amount where number like '%.005%'
Considering the data type of number as string
Related
How can I select records where in the column Value the 5th character is letter A?
For example the following records:
ID Value
-------------------------
1 1234A5636A6363
2 1234A4343B6363
3 1234B5353A6363
if I run
select * from table
where Value like '%A%'
this will return all records
but all I want is the first 2 where the 5th character is A, regardless if there are more A characters in the text or not
select *
from your_table
where substring(Value, 5, 1) = 'A'
The LIKE operator, in addition to %, which matches any number of any character, can use _, which matches any one single character. You may try:
SELECT *
FROM yourTable
WHERE Value LIKE '____A%'; -- 4 underscores here
use like below by using _(underscore)
LIKE '____A%'
SQL Server
select *
from YourTableName
where CHARINDEX('A', ColumnName) = 5
Note:- This finds where string 'A' starts at position 5
AND specify Your ColumnName
How do I do a like search on a number column in SQL?
I want numbers which are like '0.0000%'.
I tried with
select * from emp where emp_id & '' like '123%'
select * from emp where CONVERT(varchar(20), emp_id) like '123%'
but in vain.
Please help me
Regardless of which DBMS you are using AND assuming you have a valid reason to do this, you have several ways to solve problems like these. I can think of three right now:
Convert the number to a string and use a LIKE operator on this:
select *
from emp
where to_char(emp_id) like '123%';
Use mathematical operators directly (like Andrey suggests), for example:
select *
from table
where num between 0 and 0.0001;
Construct a mathematical expression (actually, this is just another case of method 2), for example:
select *
from table
where abs(num - round(num, 5)) < 0.00001;
Use comparison operators (> and <):
select * from table where num > 0 and num < 0.00001
select 0.0001*1000 from dual if it is <1 means the 0.0001 has 3 or more zeros.
so i did like
select * from emp where emp_id*10000<1
I have field called CallingParty in My CDR table it contains data like this:
CallingParty
------------
267672668788
I want to select the first 3 number of each of those numbers like
CallingParty
------------
267
if CallingParty is of type int:
SELECT CAST(LEFT(CallingParty, 3) AS INT)
From CDR
SQL Server has a Left() function, but it works best on strings. (varchar/char in SQL)
Select left(cast(267672668788 as varchar), 3)
Use this query:
SELECT SUBSTRING(CAST(CallingParty AS VARCHAR(50)), 1, 3) FROM [CDR]
If the data length does not change then you can always divide by 10 * the digits you have
SELECT FLOOR(267672668788 / 1000000000)
=267
Try this:
SELECT Substring(callingparty, 1, Length(callingparty) - 9)
FROM cdr;
Is it possible to get the size in bytes of the results of an sql query in MySQL?
For example:
select * from sometable;
ths returns 10000 rows. I don't want the rows but the size of the resultset in bytes. Is it possible?
select sum(row_size)
from (
select
char_length(column1)+
char_length(column2)+
char_length(column3)+
char_length(column4) ... <-- repeat for all columns
as row_size
from your_table
) as tbl1;
char_length for enum, set might not accurate, please take note
To build on Angelin's solution, if your data contains nulls, you'll want to add IFNULL to each column:
select sum(
ifnull(char_length(column1), 0) +
ifnull(char_length(column2), 0) +
ifnull(char_length(column3), 0) +
ifnull(char_length(column4), 0) ... <-- repeat for all columns
)
from your_table
simplify :
select sum(char_length(column1)+
char_length(column2)+
char_length(column3)+
char_length(column4) ... )<-- repeat for all columns
from your_table
You need to add IFNULL() to each column as #futilerebel has mentioned
CHAR_LENGTH() gets number of characters if unicode will be more bytes - use LENGTH() for number of bytes:https://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_length
I want to truncate a column to a max of 100 characters. How do you do this in SQL Server?
Try this:
SELECT LEFT (your_column, 100) FROM your_table
Edit:
you can also try something like this:
SELECT LEFT (your_column, LEN(your_column)-5) FROM your_table
for say if you want to trim the last 5 characters from a record.
You can also use the LEFT() function.
LEFT(col, 100)
SUBSTRING(myColumn, 1, 100)
See the docs: http://msdn.microsoft.com/en-us/library/ms187748.aspx
substring is the method:
SUBSTRING ( value_expression ,start_expression , length_expression )
from the help.
SELECT SUBSTR(COLUMN_NAME, 1, LENGTH) FROM TABLENAME where LENGTH(COLUMN_NAME) > LENGTH
Ex:
SELECT SUBSTR(DESCRIPTION,1,100) FROM STOREDETAILS where LENGTH(DESCRIPTION)>100
For those records, with length less than 100, the actual value would be shown.
Otherwise, some databases induce blank characters in the resultant records.