Query for output in this format
Hi,
I have data in following format:
CLIENT REVNO QTY1 RATE1 QTY2 RATE2 QTY3 RATE3
cln1 1 50 120 60 130 70 140
cln1 3 10 100 20 50 30 25
cln1 4 40 50 30 25 40 15
cln1 2 20 120 10 60 20 30
cln1 5 25 70 15 35 30 18
I require o/p in following format:
cln1 25 70 40 50 10 100 20 120 50 120
cln1 15 35 30 25 20 50 10 60 60 130
cln1 30 18 40 15 30 25 20 30 70 140
In the first record of above result "25" is qty1 of revno=5 & "70" is rate1 of revno=5
similarly, "40" is qty1 of revno=4 and "50" is rate of revno=4 and so on ..
In the second record, "15" is qty2 of revno=5 and "35" rate2 of revno=5 and so on.
So basically,
it should be qty1 & rate1 of revno 1through 5 in 1st records then
qty2 & rate2 of revno 1 through 5 in 2nd record
and qty3 &rate3 of revno 1to5 in 3rd record
Any Suggestions
Hi Mohan,There is some problem with your query . It does not function properly.can you check it again?
Also, one client can have at the most 10 revno and at least 1 revno.
So for a client the query would execute for his last 5 revno.
client revno qty1 rate1 qty2 rate2 qty3 rate3
cln1 1 120 10 130 5 110 20
cln1 2 105 20 122 7 150 5
cln1 3 115 25 140 50 110 10
cln1 4 124 10 145 5 80 40
cln1 5 50 100 100 50 25 200
cln1 6 35 40 40 50 25 60
cln2 1 15 5 18 9 21 11
cln2 2 16 7 9 9 11 5
cln2 3 7 7 9 9 11 11
cln3 1 12 20 15 25 20 30
The output at the bottom is in the format given below:
Format:
rev5 rev4 rev3 rev2 rev1
cln1 qty1 rate1 qty1 rate1 qty1 rate1 qty1 rate1 qty1 rate1
cln1 qty2 rate2 qty2 rate2 qty2 rate2 qty2 rate2 qty2 rate2
cln1 qty3 rate3 qty3 rate3 qty3 rate3 qty3 rate3 qty3 rate3
cln2 qty1 rate1 qty1 rate1 qty1 rate1 qty1 rate1 qty1 rate1
cln2 qty2 rate2 qty2 rate2 qty2 rate2 qty2 rate2 qty2 rate2
cln2 qty3 rate3 qty3 rate3 qty3 rate3 qty3 rate3 qty3 rate3
cln3 qty1 rate1 qty1 rate1 qty1 rate1 qty1 rate1 qty1 rate1
cln3 qty2 rate2 qty2 rate2 qty2 rate2 qty2 rate2 qty2 rate2
cln3 qty3 rate3 qty3 rate3 qty3 rate3 qty3 rate3 qty3 rate3
Required Output:
cln1 35 40 50 100 124 10 115 25 105 20
cln1 40 50 100 50 145 5 140 50 122 7
cln1 25 60 25 200 80 40 110 10 150 5
cln2 7 7 16 7 15 5
cln2 9 9 9 9 18 9
cln2 11 11 11 5 21 11
cln3 12 20
cln3 15 25
cln3 20 30
Similar Messages
-
Cropping 16:9 video in Compressor for output in 3GPP format
Hi all,
We need to regularly batch convert video for a client, from a 16:9 original to 3GPP's 176x144 ratio by cropping and resizing in Compressor. However, when setting up the encoding settings for 3GPP output, the Geometry fields are greyed out, meaning I can't crop the edges from the original.
The current workaround is to output the file first as an M-Peg (cropping it at this stage), and then re-encode that file in the 4 different 3GPP versions we need.
The question is, is there a better way to do this? Can I force the crop to take place at the same time as it's encoded to 3GPP, or, if we're stuck with a 2-stage encoding process, can I make Compressor automatically begin the re-encoding of the M-Peg file to 3GPP, as soon as the initial transcoding is complete (AppleScript, Automator?)
ThanksSo, if I drop in my source, add an MPEG-2 preset (120 minute video) and then modify the aspect ratio drop down to 16:9, is there anything else I need to do to get the same result as the 16:9 preset in Compressor 2?
There shouldn't be anything else you need to do.
By the way, it should automatically detect aspect ratio (via the anamorphic flag in DV/SD QT files) but I suppose setting it manually couldn't hurt. -
Querying a datasource using this format - {call displayLocation()}?
I've inherited a CF app and surprisingly I've never encountered calling a function or stored prodcedure like this before. I'm having trouble locating the datasource, I'm guessing it may be an Access db?
<cfquery datasource="mydsn" name="myvariable">
{call displayLocation()}
</cfquery>Bah, figures. A half hour later I find what I'm looking for. It's just another MSSQL Server SP.
-
Display Report output in Matrix format
Hi
I want to display normal report output in somewhat this manner.
I will have one change requrest number and many transport requests will be assigned to that change request number, and to the transport requests many objects will be assigned.
I have to display the output in this format:
Change Request 1 | Tr No.1 | Tr No.2 | Tr No.1 | and so on....
Obj1
Obj2
Obj3
Change Request 1 | Tr No.1 | Tr No.2 | Tr No.1 | and so on....
Obj1
Obj2
Obj3
Like this it should go on.
I have done the coding part, how to display the data in the above format i am not getting any idea, please help me out if you have any ideas.
Thanks & Regards
Haritha.Hi Vijay,
First of all thank you for the response.
I am retrieving the data from different tables and putting all the data in one internal table called i_final. Below is the declaration of that internal table and how i have populated the data to that. I am using control break statements to display the data but the data is coming in the next line.
Please see the final internal table:
1. Declaration:
Data:Begin of i_final occurs 0,
ccsnr like ysts-ccsnr,
trkorr like ysts-trkorr,
obj_name like e071-obj_name,
check_box(1),
status LIKE YSCS-STATUS,
End of i_final.
2. Populating different internal tables data to this table:
loop at i_ccno.
i_final-ccsnr = i_ccno-ccsnr.
i_final-trkorr = i_ccno-trkorr.
read table i_status with key trkorr = i_ccno-trkorr.
if sy-subrc = 0.
i_final-status = i_status-status.
endif.
read table i_obj_name with key trkorr = i_ccno-trkorr.
if sy-subrc = 0.
i_final-obj_name = i_obj_name-obj_name.
endif.
append i_final.
clear i_final.
endloop.
3. Using Control break statements to display the data.
sort i_final by ccsnr.
loop at i_final.
at new ccsnr.
write:/2 i_final-ccsnr.
endat.
write:20 i_final-trkorr.
uline.
endloop.
But the output is coming like this:
CHG0003785 HSDK933109
HSDK933111
HSDK933113
HSDK933143
HSDK933268
But i want the output like this:
CHG0003785 | HSDK933109 | HSDK933111 | HSDK933113
Thanks & Regards
Haritha. -
Improving a query for a report in b1
Dear All,
We have a query for a report. this report display all invoices with it´s Dscription in the system just have 3 descriptions so i need the the report display the this description in column not in row and then have the sum by description. i dont know how can i put a picture for showing the example.
Some one knows how can i do? down the code.
Regards
NANCY
SELECT distinct T1.visorder as 'No. Linea',
T0.DocNum as 'No. Factura',
T0.DocDate as 'Fecha',
T0.CardName as 'Cliente',
T1.U_CANTIDAD as 'Tonelaje',
T0.U_OPERACION as 'No. Operación',
T0.DocCur as 'Moneda',
T0.GrosProfit as 'Ingreso total de factura',
T1.ItemCode as 'Código',
T1.Dscription,
T1.Quantity*T1.Price as 'Importe por Servicio',
T1.LineVat as 'IVA por servicio',
T0.VatSum as 'IVA por factura',
T2.PlngGroup as 'Cuenta SUN'
FROM OINV T0 LEFT JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
inner join OCRD T2 ON T0.CardCode = T2.CardCode
WHERE T0.Series = 49 and
T0.DocDate BETWEEN [%0] AND [%1]Hi Nancy,
I'm not sure that I understand your requirement 100% but assuming you only have 3 descriptions then the following would give you totals for your different descriptions...
Simply replace the text ' etc in the code below with the descriptions values.
SELECT distinct
T1.visorder as 'No. Linea',
T0.DocNum as 'No. Factura',
T0.DocDate as 'Fecha',
T0.CardName as 'Cliente',
T1.U_CANTIDAD as 'Tonelaje',
T0.U_OPERACION as 'No. Operación',
T0.DocCur as 'Moneda',
T0.GrosProfit as 'Ingreso total de factura',
T1.ItemCode as 'Código',
CASE
WHEN T1.Dscription = '<description1>'
THEN T1.Quantity*T1.Price
ELSE 0
END as '<description1>',
CASE
WHEN T1.Dscription = '<description2>'
THEN T1.Quantity*T1.Price
ELSE 0
END as '<description2>',
CASE
WHEN T1.Dscription = '<description3>'
THEN T1.Quantity*T1.Price
ELSE 0
END as '<description3>',
T1.LineVat as 'IVA por servicio',
T0.VatSum as 'IVA por factura',
T2.PlngGroup as 'Cuenta SUN'
FROM OINV T0 LEFT JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
inner join OCRD T2 ON T0.CardCode = T2.CardCode
WHERE T0.Series = 49 and
T0.DocDate BETWEEN [%0] AND [%1]
Hope this helps.
Regards,
Sean -
Help to rewirte query for best performance
Hi All,
can you kindly help me to rewirte the below mentioned query for best performance. this is taking more than 20 min in our production server.
SELECT cp.name,mis.secondary_type U_NAME,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-161,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-154,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-154,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-147,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-147,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-140,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-140,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-133,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-133,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-126,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-126,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-119,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-119,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-112,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-112,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-105,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-105,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-98,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-98,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-91,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-91,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-84,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-84,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-77,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-77,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-70,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-70,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-63,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-63,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-56,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-56,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-49,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-49,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-42,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-42,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-35,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-35,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-28,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-28,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-21,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-21,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-14,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage,
count(CASE WHEN (mis.start_time between To_DATE(to_char(next_day (sysdate-14,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-7,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))THEN mis.event_audit_id END) Usage
FROM mis_event_audit mis,USER u,com_pros cp where
mis.user_id=u.email_address and u.cp_id=cp.cp_id
and (mis.start_time between To_DATE(to_char(next_day (sysdate-161,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy') and To_DATE(to_char(next_day (sysdate-7,'monday'),'MM/DD/YYYY'),'mm/dd/yyyy'))
GROUP BY cp.name, mis.secondary_type;
Thanks,
krishHi, Krish,
Something like this will probably be faster, because it cuts out most of the function calls:
WITH got_cnt AS
SELECT cp.name
, mis.secondary_type AS u_name
, COUNT (mis.event_audit_id) AS cnt
, ( TRUNC (mis.start_time, 'IW')
- TRUNC (SYSDATE, 'IW')
) / 7 AS week_num
FROM mis_event_audit mis
JOIN user_table u ON mis.user_id = u.email_address -- USER is not a good table name
JOIN com_pros cp ON u.cp_id = cp.cp_id
WHERE mis.start_time >= TRUNC (SYSDATE, 'IW') - 161
AND mis.start_time < TRUNC (SYSDATE, 'IW')
GROUP BY cp.name
, mis.secondary_type
, TRUNC (mis.start_time, 'IW')
SELECT name
, secondary_type
, SUM (CASE WHEN week_num = 22 THEN cnt END) AS week_23
, SUM (CASE WHEN week_num = 21 THEN cnt END) AS week_22
, SUM (CASE WHEN week_num = 20 THEN cnt END) AS week_21
, SUM (CASE WHEN week_num = 0 THEN cnt END) AS week_1
FROM got_cnt
GROUP BY name
, secondary_type
;TRUNC (d, 'IW') is midnight on the last Monday before or equal to the DATE d. It does not depend on you NLS settings.
Whenever you're tempted to write an exprssion as complicated as
, COUNT ( CASE
WHEN ( mis.start_time BETWEEN TO_DATE ( TO_CHAR ( NEXT_DAY ( SYSDATE - 161
, 'monday'
, 'MM/DD/YYYY'
, 'MM/DD/YYYY'
AND TO_DATE ( TO_CHAR ( NEXT_DAY ( SYSDATE - 154
,'monday'
, 'MM/DD/YYYY'
, 'MM/DD/YYYY'
THEN mis.event_audit_id
END
) AS usageseek alternate ways. Oracle provides several handy functions, especially for manipulating DATEs. In particular "TO_DATE (TO_CHAR ...)" is almost never needed; think very carefully before doing a round-trip conversion like that.
Besides being more efficient, this will be easier to debug and maintain.
If you're using Oracle 11.1 (or higher), then you can also use SELECT ... PIVOT in the main query, but I doubt that will be any faster, and it might not be any simpler.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Simplify the problem as much as possible. For example, instead of posting a problem that covers the last 23 weeks, pretend that you're only interested in the last 3 weeks. You'll get a solution that's easy to adapt to any number of weeks.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002}
For performance problems, there's another page of the forum FAQ {message:id=9360003}, but, before you start that process, let's get a cleaner query, without so many functions.
Edited by: Frank Kulash on Oct 2, 2012 11:50 AM
Changed week_num to be non-negative -
I want sql query for this output
hi guys
could u tell how can i write sql query for this out put
i have one table like this
ID ACCOUTID TAX
1 1 A
2 1 B
3 2 C
4 2 D
5 3 E
7 NULL F
8 NULL G
MY OUT PUT MUST BE LIKE THIS
ID AID TAX
2 1 A
4 2 D
7 NULL F
8 NULL G
HERE IN THIS OUTPUT I SHOULD HAVE
MAXIMAM ID VALUE FOR A REPEATED AID VALUES
AND
THE ROWS AID VALUES IS NULL ALSO MUST PAPULATED IN THE OUTPUT.
I KNOW ONE SOLUTION LIKE THIS
SELECT MAX(ID),AID,TAX
FROM TABLE T
GROUP BY AID,TAX
UNION ALL
SELECT ID, AIC,TAX
FROM TABLE T
WHERE AID IS NULL;
BUT I WANT SAME RESULT WITH OUT USING LOGICAL OPERATORS.
COULD U PLZ TELL A SOL.Will this help:
SQL> with t as
2 (
3 select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
4 select 2, 1, 'B' from dual union all
5 select 3, 2, 'C' from dual union all
6 select 4, 2, 'D' from dual union all
7 select 5, 3, 'E' from dual union all
8 select 7, NULL, 'F' from dual union all
9 select 8, NULL, 'G' from dual
10 )
11 --
12 select id, ACCOUTID AID, Tax
13 from
14 (
15 select t.*
16 ,count(1) over (partition by t.ACCOUTID) cn
17 ,row_number() over (partition by t.ACCOUTID order by id desc) rn
18 from t
19 )
20 where cn > 1
21 and (rn = 1 or ACCOUTID is null)
22 /
ID AID T
2 1 B
4 2 D
8 G
7 F
-- If I leave out the OR condition then you'll get this:
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (
3 select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
4 select 2, 1, 'B' from dual union all
5 select 3, 2, 'C' from dual union all
6 select 4, 2, 'D' from dual union all
7 select 5, 3, 'E' from dual union all
8 select 7, NULL, 'F' from dual union all
9 select 8, NULL, 'G' from dual
10 )
11 --
12 select id, ACCOUTID AID, Tax
13 from
14 (
15 select t.*
16 ,count(1) over (partition by t.ACCOUTID) cn
17 ,row_number() over (partition by t.ACCOUTID order by id desc) rn
18 from t
19 )
20 where cn > 1
21* and rn = 1
SQL> /
ID AID T
2 1 B
4 2 D
8 G
--which follows the description you've given, but not the output -
Formatted Search Query for BatchNo
Dear All,
I am using the following query as formated search for Identifying the batches availble during the creation of Delivary document
in a user defined column at row level. When i click on this field it's showing the Batches for the Item with Zero Qty also.
I need to display only the batches where the QTY >0. This query displaying even the Zero Qty Batches also. Please help me to modify the below query for getting the above. Below is the query .
SELECT distinct T4.[BatchNum] FROM [dbo].[OIBT] T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode INNER JOIN DLN1 T2 ON T1.ItemCode = T2.ItemCode INNER JOIN ODLN T3 ON T2.DocEntry = T3.DocEntry INNER JOIN IBT1 T4 ON T0.BatchNum = T4.BatchNum AND T3.DocNum = T4.BaseNum INNER JOIN OWHS T5 ON T0.WhsCode = T5.WhsCode WHERE T0.[ItemCode] = $[$38.1] AND T4.[WhsCode] = $[$38.24] AND T0.[Quantity]>=$[$38.11]
Regards
Srinii removed that T5, But It's showing the Batches where the qty in the main warehouse for that batch is Zero.That batch was actually present in another warehouse. And also when i am working on other warehouses it's showing the batches in the main warehouse where the qty is present.
Regards
Srini
Edited by: Srini on May 11, 2010 10:24 PM -
Formatted Search query for Vacation Accrued
Hi Experts,
I have a Client who needs to keep tract on the Vacation Accrued on the Employee Master Data. I have created this UDF on the Master Data, but I could not get the query for the Formatted Search right.
This Formatted search on the UDF ( must look at the OHEM.startDate field and populate the following:
If it is a still within year of the system date, it must populate 0,
If it is > 1 year and < 3 years, it must populate 5,
etc.
Any help would be greatly appreciated.
MarliHi Experts,
Here is what I did for the query mentioned above:
{SELECT
CASE
WHEN (T0.startDate > GETDATE() -356)
THEN 0
WHEN (T0.startDate > GETDATE() - 712)
THEN 5
END
As 'Vacation Accrued'
FROM OHEM T0}
The issue is that if I link this query to the UDF on the EMD, I get a list of 0 and 5 to choose from. I need to populate automatically.
Thanks.
Marli -
Formatted search query for displaying invoice items details
hi all,
i need to display all the items in AP invoice.kindly suggest me a query for that.
in AP invoice
Ex. row items
code--descqtyprice--
total
I0001--XXXXXXX5--
100 -
500
query should display this row as
code--desc--
price
I0001--XXXXXXX--
100
I0001--XXXXXXX--
100
I0001--XXXXXXX--
100
I0001--XXXXXXX--
100
I0001--XXXXXXX--
100
=================================
the query should display as the qty is 5 so it will display the same item 5 times
kindly suggest me some query for formatted search
its very urgent
regards
sandipHi Sandip,
DoQuery("Select b.ItemCode from OINV a,INV1 b Where a.DocEntry=b.DocEntry")
Hope its help for you
Give me reward points,
Regards,
G.Suresh. -
Can anyone create a Query for this?
Can anyone help me to create a query for the followinf table info?
I have tried to use joins but no success.
Table Name: Org
ID Severity Status
1 Red New
2 Yellow New
3 Green Closed
4 Green Open
5 Yellow Closed
6 Red Closed
7 Red Closed
8 Red Open
9 Yellow New
10 Yellow Closed
The result of the query should look like this. The most important thing is that I want this result set in a single query and in this format.
Severity Total_Status Total_Closed
Red 4 2
Green 2 1
Yellow 4 2select severity,count(*) tot,sum(decode(status,'closed',1,0)) tot_closed
from org
group by severity;
Not tested.. -
Need a Query for the following Output
I have a table name Table1. some of the data are like the following
EmpCode ProductCode Quantity
20006 IMPLSA 5
20006 LACJDT 10
20006 LIVLSU 15
20006 PEPPSU 11
20006 SAFMTA 12
20006 SUCFTA 17
21475 IMPLSA 2
21475 LACJDT 7
21475 LIVLSU 4
21475 PEPPSU 8
21475 SUCFTA 12
20409 IMPLSA 11
20409 LACJDT 13
20409 LIVLSU 9
20409 SAFMTA 7
20409 SUCFTA 5
21112 IMPLSA 2
21112 LIVLSU 18
21112 PEPPSU 20
21112 SAFMTA 22
21112 SUCFTA 15
Here no of EmpCode and ProductCode are not fixed.
And i need the output like this
ProductCode 20006 21475 20409 21112
IMPLSA 5 2 11
2
LACJDT 10 7 13 0
LIVLSU 15 4 9 18
PEPPSU 11 8 0 20
SAFMTA 12 0 7 22
SUCFTA 17 12 5 15
I know that it may be solved by dynamic pivot. but i never write any dynamic pivot query.
So Please Help me.DECLARE @EmpList varchar(max),@SQL varchar(max)
SELECT @EmpList = STUFF((SELECT DISTINCT ',[' + CAST(EmpCode AS varchar(15)) + ']'
FROM Table1
ORDER BY ',[' + CAST(EmpCode AS varchar(15)) + ']'
FOR XML PATH('')),1,1,'')
SET @SQL='SELECT ProductCode,' + @EmpList +
' FROM table1 t
PIVOT(SUM(Quantity) FOR EmpCode IN (' + @EmpList + '))p'
EXEC (@SQL)
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
How to form a query for this requirment
Hi Friends,
I have a database table in which I store the employee data along with his phone number. Now this row of data can repeat for different phone number depending on if it is office phone or home phone or cell phone.
But in the output of query, I need name of empoyee and other three columns namely "Home Phone", "Office Phone" and "Cell Phone".
If employee has three rows for each kind of phone, then in the result of query all three columns for phone numbers should be filled, otherwise as many columns should be filled with data as different phone numbers employee has.
Can any one please post SQL query for this scenario ?
Thanks in AdavanceI cannot imagine, that second and third query are
under any circumstances faster as first one, but i
can imagine that they are slower You stated that query without the inline view can only be faster. Did you check on optimizer plans or use tkprof to verify your claim?
A quick check on those two selects
SELECT object_id, object_type, object_name
FROM user_objects;
SELECT object_id, object_type, object_name
FROM (SELECT object_id, object_type, object_name
FROM user_objects)
;didn't show any changes in the explain plan unter 10g1.
C. -
How to write a query for this data??
In this table i have column dob which is DATE type,for example 12-jan-89 I want output like this
Year Day
12-jan-89 Thusrs_day
12-jan-90 Friday
upto
12-jan-14 sundaykrishnagopi wrote:
No not like that ,I want up to 2014 year
Ok, so lets say you have table like this
SQL> create table my_table(dob date);
Table created.
SQL> insert into my_table (dob) values( to_date('12-jan-1989', 'dd-mon-yyyy'));
1 row created.
SQL> commit;
Commit complete.
SQL> select * from my_table;
DOB
12-JAN-89
You can write a query like this
select dob + (level -1) dob
, to_char(dob + (level -1), 'fmDay') day_
from my_table
connect
by level <= (dob + interval '25' year) - dob + 1; -
How to write query for this in TopLink ?
I am doing a simple search in jsp where the search will the based on the choices chosen by user.
I had given 3 check boxes for those choices.
The problem is, query will be based on the choice or choices chosed by the user.
How to write query for this in TopLink ?
Thanks in Advance..
JayaganeshTry below solution, it is NOT best solution but might work:
Declare @Questions TABLE (QuestionID INT, QuestionText Varchar(100))
INSERT INTO @Questions
VALUES (1, 'Comment'), (2, 'Score')
DECLARE @Answers TABLE (authkey INT, QuestionID INT, questiontext VARCHAR(100), answertext VARCHAR(100))
INSERT INTO @Answers
VALUES (101, 1, 'comment', 'hi!!'), (101, 2, 'score', '4'), (102, 1, 'comment', 'excellent'), (102, 2, 'score', '5'), (103, 2, 'score', '6'), (104, 2, 'score', '8')
SELECT
A.AuthKey
,Q.QuestionID
,Q.QuestionText
,A.AnswerText
FROM
@Questions Q
INNER JOIN @Answers A ON Q.QuestionID = A.QuestionID
UNION
SELECT
A.AuthKey
,Q.QuestionID
,Q.QuestionText
,Null
FROM
@Questions Q
CROSS JOIN @Answers A
WHERE
NOT EXISTS (SELECT 1 FROM @Answers SubQry WHERE SubQry.AuthKey = A.AuthKey AND SubQry.QuestionID = Q.QuestionID)
Output
AuthKey | QuestionID
| QuestionText
| AnswerText
101 | 1 | Comment | hi!!
101 | 2 | Score | 4
102 | 1 | Comment | excellent
102 | 2 | Score | 5
103 | 1 | Comment | NULL
103 | 2 | Score | 6
104 | 1 | Comment | NULL
104 | 2 | Score | 8
Best Wishes, Arbi; Please vote if you find this posting was helpful or Mark it as answered.
Maybe you are looking for
-
Recover from dropped SYSAUX datafile
Trying to recover a DEV database without rebuilding it, but not hopeful at this point. Basically, someone dropped the SYSAUX (and a few other) datafiles, so now they are showing up in the database as MISSING0003 instead of the actual filename. There
-
Dear all, I have to do back dated revaluation of material. What will happen to the transactions which are partially complete? For Ex PO Is created GR pending etc,,, any thoughts on it? Regards Shrinivas
-
Binding Mac to a Windows 2000 server (Active Directory)
I have been trying to connect various mac machines on my campus to the active directory on a windows 2000 server.and i've been getting various errors.in one lab i have some IMac10,1- mac osx ver 10.6.2 and in the other labs i have lower versions on t
-
Fell In Love With My N97, Until...
The On/Off button and touch screen are both very unreactive, and it has begun to run incredibly slowly and now crashes EVERY time I manage to get it switched on!! I also had the USB issues, and trying to factory reset it with it running so slowly and
-
Crackling Noises w/ SoundBlaster Audigy 2
Well, im having a problem with the audigy 2 NX external sound card. I am using a toshiba satellite 45 (.6ghz, 52 mb ram) series laptop which includes more than meets the requirements for this card. I tried the ultimate suggestions of disabling the on