SQL Parentheses use in an OR clause

Take a look at the Operator Precedence in SQL Server (You’ve not specified that, but I’d imagine it’s the same for all RDBMS). What this means is that ANDs (without parenthesis) are evaluated before1 bind more tightly than ORs. So in your specific case, without the parenthesis, the conditions are: employe.service=service.code_serv AND employe.nom LIKE ‘A%’ OR employe.nom LIKE ‘B%’ … Read more

How do I reset a sequence in Oracle?

Here is a good procedure for resetting any sequence to 0 from Oracle guru Tom Kyte. Great discussion on the pros and cons in the links below too. From this page: Dynamic SQL to reset sequence valueAnother good discussion is also here: How to reset sequences?

How to divide two columns?

Presumably, those columns are integer columns – which will be the reason as the result of the calculation will be of the same type. e.g. if you do this: you will get 0, which is obviously not the real answer. So, convert the values to e.g. decimal and do the calculation based on that datatype … Read more

Comparing Dates in Oracle SQL

31-DEC-95 isn’t a string, nor is 20-JUN-94. They’re numbers with some extra stuff added on the end. This should be ’31-DEC-95′ or ’20-JUN-94′ – note the single quote, ‘. This will enable you to do a string comparison. However, you’re not doing a string comparison; you’re doing a date comparison. You should transform your string into a date. Either by using the built-in TO_DATE() function, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)