SQL function PIVOT with 2 column

select order_number, line_number, isnull(max(case when linenum=1 then name else null end),”) name1 , isnull(max(case when linenum=1 then value else null end),”) value1, isnull(max(case when linenum=2 then name else null end),”) name2, isnull(max(case when linenum=2 then value else null end),”) value2, isnull(max(case when linenum=3 then name else null end),”) name3, isnull(max(case when linenum=3 then value else … Read more

query about check constraint [closed]

Since you are using Oracle you can use CHECK constraint saying CONSTRAINT check_dates CHECK (my_date_column BETWEEN date ‘1994-10-25’ AND date ‘2016-05-10’) Your query (as in comment) should be like below create table dob5 ( birthdate date not null, CONSTRAINT check_dates CHECK (birthdate BETWEEN date ‘1994-10-25’ AND date ‘2016-05-10’) ); See this demo fiddle http://sqlfiddle.com/#!4/779f9

Query to Change Quarter Timestamp Format

First of all (and as usual), you should not store DATE values as VARCHAR, even if you need only the quarter. You can do following. First convert the string into a DATE, e.g. SELECT TO_DATE(REGEXP_SUBSTR(‘Q2 FY07’, ‘\d{2}$’)||’-‘||REGEXP_SUBSTR(‘Q2 FY07′,’\d’)*3, ‘RR-MM’) FROM … Then you can change the output format according to your needs, i.e. TO_CHAR( TO_DATE(REGEXP_SUBSTR(‘Q2 … Read more

Nested SQL statements for Oracle [closed]

You don’t need to nest. You need to join. You’ll probably need something like this, although I would need the exact table structure to be sure. But you’ll get the general idea. select b.TITLE, a.LASTNAME, i.UNITSONHAND from BOOK b inner join AUTHOR a on a.AUTHORID = b.AUTHORID inner join INVENTORY i on i.BOOKID = b.BOOKID … Read more