This question already has answers here:
SQL Server, division returns zero
(6 answers)
Why does SQL Server round off results of dividing two integers?
(6 answers)
Database calculations are wrong
(1 answer)
Closed 9 years ago.
Ok I have A SQL Procedure I calculate some Payroll Stuff. The Problem here one of my equation '30/360 = 0' return 'zero' and try it on Sql Server Like this :
Select 30/360 --This Return Zero And Should Return '0.08333333'
This is not my real function, just example, Is this normal behavior?
Dividing two integers returns an integer. Use the following instead:
select 30/360.0
Related
This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 2 years ago.
I hope you all have a good day.
Actually I'm deploying a query to get a complete array of data. But the fact is that I need an Id, first of all, I guess, I must get the last Id first, then I can apply a mathematic operation to get its value + 1. The fact is that I've been trying different sentences and queries with no result.
This is my code:
function obtener_Id(){
global $mysqli;
$resultado_oId = $mysqli ->query("SELECT TOP 1 'id' FROM 'pacient' ORDER BY RowID DESC ")
$id_sacada = mysqli_fetch_assoc($resultado_oId);
$id_enLaMano = $id_sacada['id'];
return $id_enLaMano;
//$id_dinamica = $id_enLaMano + 1;
//return $id_dinamica;
}
As you can see guys, I've commented on the last two lines, cause I´m looking to get at least a value (The result from a query) But Idk if that is correct. Looking on the Internet I've seen relative posts which are solved just to apply the query that we can view under global declarations...
I've tried that on phpMyAdmin with no results and a bunch of errors...
You guys know the correct way to get the max value in the Id column? Or even if I'm doing badly correct me.
A lot of hugs and Luck!
Mizar ^^
I would suggest putting the serial number in a table. Read the serial no before insert, (lock the table, if required) insert the data, then increase the serial no by 1 and update the serial no table with increased value.
This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 4 years ago.
I get am empty set when I enter this SQL statement, could someone please tell me why?
select ayr,mods.mid,mtitle,credits
from mods,comp
where mods,mid = comp.mid and ayr = 2001/02;
It displays the right thing when omitting 'ayr = 2001/02'.
You need quotes around the date
select ayr,mods.mid,mtitle,credits
from mods,comp
where mods,mid = comp.mid and ayr = '2001/02';
Are you sure that after the where clause it should be mods,mid instead of mods.mid, table name is not entered in the correct way after SELECT statement
As per my suggestion you should enter mods.mid
Try this Syntax:-
select ayr,mods,mtitle,credits from mods,comp where mods.mid = comp.mid and ayr = 2001/02;
Post the output
This question already has answers here:
How to pass a variable to a IN clause?
(4 answers)
Closed 5 years ago.
I need to define a list of variables to use in multiple MySQL queries.
The variable will be a list of mails. I have tried to define it in different ways but it always gives me error in the construction.
SET #listamails='mail1#gmail.com,mail2#gmail.com';
Select * from user WHERE mail IN (#listamails);
Any ideas?
Thank you
You cannot pass in a list to IN using a single variable. The simplest solution in MySQL is find_in_set():
Select u.*
from user u
where find_in_set(mail, #listamails) > 0;
However, this cannot take advantage of an index. For that, you might want to use dynamic SQL.
Try this
SET #listamails='mail1#gmail.com','mail2#gmail.com';
Select * from user WHERE mail IN (#listamails);
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Is there a combination of “LIKE” and “IN” in SQL?
The first where clause below runs fine for me but it does not pick up contacts that might have 45211-1234 or 45213-4321
SELECT * FROM contacts
WHERE zipcode IN ('45211','45213')
I thought I could change the where clause to the below to fix, but it fails.
SELECT * FROM contacts
WHERE zipcode IN ('45211%','45213%')
How might I change this so it brings back anything that has proper zip + dash + any zip4? For example, 45211-1234 or 45213-4321.
Note I have whole bunch of zipcodes to enter, not just these two.
How about this:
SELECT * FROM contacts
WHERE Left(zipcode,5) IN ('45211','45213')
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Is the SQL WHERE clause short-circuit evaluated?
If we do
SELECT * FROM Business WHERE Latitude < 9 AND Latitude > 10
for example, will Latitude > 10 ever be called if Latitude is 8 for example?
What about in mysql?
What about in core data?
Is it dependent on SQL implementation or is there a definite standard that in where clause if one of the AND statement is false than the rest won't be executed.
I asked this to know whether I can save some computational power. Say the expression after the first AND is expensive to compute such as computing distance.
WARNING: down-to-earth answer
You have probably mistaken AND with OR (in fact condition Latitude < 9 AND Latitude > 10 makes no sense..).
OR conjunction AFAIK in most languages this is implemented as follows: every condition is checked until one is true (i believe this is also true with SQL - EDIT: this answer suggests that the actual behaviour is implementation-dependant, i.e. you can't take that for sure in any RDBMS)
AND conjunction every condition is checked until one is false
So you probably wanted to write this condition:
Latitude < 9 OR Latitude > 10
which is equivalent to:
NOT(Latitude >= 9 AND Latitude <= 10)