Multiples of a number oracle SQL - sql

How do you check if the content of a field is a multiple of 2 in oracle sql
n_id | n_content
-------------------------
1 | Balloon
2 | Drill
3 | Cup
4 | Bottle
5 | Pencil
6 | Ball
I have tried:
select*from num_w where (n_id%2>0);
and also
select*from num_w where n_id%2=0;
Neither of these worked

Wasn't this multiple of 5 a few seconds ago? :)
Anyway, in Oracle I believe the query would be:
select * from num_w where MOD(n_id,2) = 0;

Related

SQL - Exclude four-digit-number

I have an SQL-Server with and simple table on it.
ID | Code
---+--------
1 | 1234
2 | TEST
3 | 12556
4 | TEST1
5 | 5678
6 | WART
I want to exclude all four-digit-number. In my case that would be 1234 and 5678.
I know I can use ISNUMERIC() tp check if code is numeric.
I also know I can use:
SELECT * FROM Codes WHERE code NOT LIKE '____';
to check if my value has four digits, but i dont get it how to combine them.
Any suggentions?
Thanks in advance!
Just use not like:
where code not like '[0-9][0-9][0-9][0-9]'

SQL Nested Case When with numeric check

I'm trying to create a "filter" with SQL.
I have a table named ARTICLE like this :
CODE | NAME | QUANTITY |
_______________|_________________|_______________
0020717270084 | MANGO FRUIT 1L | 3 |
0884394000774 | ALOE VERA 50CL | 4 |
16 | CHEWING GUM | 10 |
IGLOO | IGLOO ICE | 5 |
I want to do a SELECT with a verification on CODE.
If CODE is a number AND has a length of 8 OR 10 OR 13 digits, i display CODE ELSE i have to display * before CODE (simple concat).
I can do CASE WHEN but this one is a little bit tricky for me.
Thanks for your help.
You would do this with a case statement. Databases do the checks differently. The following is an approach using SQL Server:
select (case when len(code) in (8, 10, 13) and code not like '%[^0-9]%'
then code
else '*' + code
end)

parse multiline varchar field into rows (T-sql)

I am making a report in SSRS. Database contains table "Project" with a "Notes" field which is formated by users in this way:
#Completed
-line 1 description
-line 2 description
-line3 and so on
#Planned
-line 1 etc.
#Risks
- line1 ...etc
There are always only those 3 categories and in that order. Bullet points can be from 0 to unlimited (but i never seen more than 10)
I would like to get output(dataset) in format (so I can group them in tablix):
ProjectID, Maincategory, itemID, subcategories.
For example
1 | Completed | 1 | line1
1 | Completed | 2 | line2
1 | Completed | 3 | line3
...
1 | Planned | 1 | Line1
...
1 | Risks | 1 | line1
...
I cant change source DB so I cant create stored procedure, it should be regular query.
I looked at various solutions with CTE recursions but I just cant figure out how they work in oreder to change them for my case.
Thank you!

Returning all children with a recursive select

Good day everyone! I've got a graph. First, I know how to build simple recursive selections. I read some info on msdn.
In this image you can see that (for example) the top node of the graph, which is numbered 0, influences node number 1 (etc (2->4), (3->4), (4->5), (5->6), (1->5))
TASK: for every node show nodes which it influences. For example,
number 1 influences 5 and 6.
The result SQL must return something like this:
who_acts| on_whom_influence
0 | 1
0 | 5
0 | 6
1 | 5
1 | 6
2 | 4
2 | 5
2 | 6
3 | 4
3 | 5
3 | 6
4 | 5
4 | 6
5 | 6
Starting data that I can get using anchor member of CTE are:
who_acts| on_whom_influence
2 | 4
3 | 4
4 | 5
5 | 6
1 | 5
0 | 1
Can I make this selection using SQL syntax and a recursive select? How can I do it?
That sounds like a straightforward CTE. You can pass along the root of the influence in a separate column:
; with Influence as
(
select who_acts
, on_whom_influence
, who_acts as root
from dbo.YourTable
union all
select child.who_acts
, child.on_whom_influence
, parent.root
from Influence parent
join dbo.YourTable child
on parent.on_whom_influence = child.who_acts
)
select root
, on_whom_influence
from Influence
order by
root
, on_whom_influence
Example on SQL Fiddle.

Pairwise testing: How to create the table?

Hello I have doubt regarding how to create the table for the pairwise testing.
For example if I have three parameter which can each attain two different values. How do I create a table of input with all possible combination then? Would it look something like this?
| 1 2 3
-----------
1 | 1 1 1
2 | 1 2 2
3 | 1 1 2
4 | 1 2 1
Does each parameter corresponds to each column?
However since I have 3 parameter, which each can take 2 different value. The number of test cases should be 2^3 isn't it?
There's a good article with links to some useful tools here:
http://blog.josephwilk.net/ruby/pairwise-testing-with-cucumber.html
For the parameters: each column is a parameter, and each row is a possible combination. Here is the table:
| 1 2 3
-----------
1 | 1 1 1
2 | 2 1 1
3 | 1 2 1
4 | 1 1 2
5 | 2 2 1
6 | 2 1 2
7 | 1 2 2
8 | 2 2 2
so 2^3=8 possible combinations as you can see :)
For the values: each column is a value, and each row is a possible combination:
| 1 2
--------
1 | 1 1
2 | 2 1
3 | 1 2
4 | 2 2
They are 2^2=4 possible combinations. Hope it helps.
1) Please note that pair-wise testing is not about scanning exhaustively all possible combination of values of all parameters. Firstly, such a scanning would give you an enormous amount of test cases that almost no existing system could be able to run all of them.
Secondly, pair-wise testing for a software system is based on the hope that the two parameters having the highest number of possible values are the culprit for the highest percentage of faults of that system.
This is of course only a hope and almost no rigorous scientific research has existed so far to prove that.
2) What I often see in the documentations discussing pair wise testing, like this is that the list of all possible values (aka the pair-wise test table) is not constructed in a well thought way. This creates confusions.
In your case, all the parameters have the same number of possible values (2 values), therefore you could choose any two parameters of those three to build the table. What you could pay attention is the ordering of the combination: you iterate first the top-right parameter, then the next parameter to the left, and so on, ...
Say if you have two parameters p1 and p2, p1 has two possible values apple and orange; and p2 has two possible values red and blue, then your pair-wise test table would be:
index| p1 p2
------------------
1 | apple red
2 | apple blue
3 | orange red
4 | orange blue