Select querry for hr records.
hi all,
i was writing a hr report to to get the employee no's based on the employment status given in the selection screen. i was using the standard screen from PNP databse.
but when i was giving the from and to date and the employment status . and i am using GET PERNR to fetch the records. but it is not considering the status.
so i wrote a select querry to check the records fetched after GET PERNR matches with the employment status given in the selection screen. but the select querry is not working.
SELECT SINGLE STAT2 INTO PERNR-STAT2 FROM PA0000
WHERE PERNR = PERNR-PERNR
AND BEGDA GE PN-BEGDA
AND ENDDA LE PN-ENDDA
AND STAT2 IN PNPSTAT2.
CHECK PERNR-STAT2 IN PNPSTAT2.
IF SY-SUBRC NE 0.
REJECT.
ENDIF.
so please some one give the select querry to get the records from pa0000 tables based on the date range given and the employment status given.
Hi Praveen,
welcome to SDN.
Please check that did you pass
<b>Infotypes: 0000.</b>
in the declaration part of the statement.
Get Pernr will consider the status then.
Regards,
Amit
P.S. Please close the issue and reward points to helpful answer once Query is solved.
Message was edited by: Amit Khare
Similar Messages
-
Need help to solve update querry for multiple records.
Could any of you please provide update querry for the following scenario.
Requiremnt:
1. Update the UNIQUE_ID of record ( same Identifier and Identifier_code
where END_Date is not null) with the UNIQUE_ID of the record (( same Identifier and Identifier_code
where END_Date is null).
2. If More than one NULL in END_date then update UNIQUE_ID with max(EFFective_Date) of UNIQUE_ID
Source data
UNIQUE_ID
Identifier
Identifier_code
EFFective_Date
END_Date
1
777
abc
2/14/2014 11:15
2/28/2014 9:00
1
777
abc
2/21/2014 9:00
3/7/2014 9:02
2
777
abc
2/28/2014 9:00
3/14/2014 9:02
2
777
abc
3/7/2014 9:02
3/14/2014 9:02
2
777
abc
3/14/2014 9:02
NULL
5
888
xyz
2/14/2014 11:15
2/28/2014 9:00
5
888
xyz
2/21/2014 9:00
3/7/2014 9:02
5
888
xyz
2/28/2014 9:00
3/14/2014 9:02
6
888
xyz
3/7/2014 9:02
NULL
7
888
xyz
3/14/2014 9:02
NULL
OutPUT .
UNIQUE_ID
Identifier
Identifier_code
EFFective_Date
END_Date
2
777
abc
2/14/2014 11:15
2/28/2014 9:00
2
777
abc
2/21/2014 9:00
3/7/2014 9:02
2
777
abc
2/28/2014 9:00
3/14/2014 9:02
2
777
abc
3/7/2014 9:02
3/14/2014 9:02
2
777
abc
3/14/2014 9:02
NULL
7
888
xyz
2/14/2014 11:15
2/28/2014 9:00
7
888
xyz
2/21/2014 9:00
3/7/2014 9:02
7
888
xyz
2/28/2014 9:00
3/14/2014 9:02
7
888
xyz
3/7/2014 9:02
NULL
7
888
xyz
3/14/2014 9:02
NULL
Thanks in advance.Hi Vikash,
This query will not produce results as per requirement:
Try it with following data
Insert into @TempTABLE values (1,777,'abc','2/14/2014 11:15','3/14/2014 9:02')
Insert into @TempTABLE values (1,777,'abc','2/21/2014 9:00','3/14/2014 9:02')
Insert into @TempTABLE values (2,777,'abc','2/28/2014 9:00','3/14/2014 9:02')
Insert into @TempTABLE values (2,777,'abc','3/7/2014 9:02','3/14/2014 9:02')
Insert into @TempTABLE values (2,777,'abc','3/14/2014 9:02',NULL)
Insert into @TempTABLE values (5,888,'xyz','2/14/2014 11:15','3/14/2014 9:02')
Insert into @TempTABLE values (5,888,'xyz','2/21/2014 9:00','3/14/2014 9:02')
Insert into @TempTABLE values (5,888,'xyz','2/28/2014 9:00','3/14/2014 9:02')
Insert into @TempTABLE values (7,888,'xyz','3/7/2014 9:02',NULL)
Insert into @TempTABLE values (6,888,'xyz','3/14/2014 9:02',NULL)
as per the problem statement, all records having 888,'xyz' should be updated with 6 not 7 as max effective date is associated with 6 not 7.
Ashutosh
Nope.
can you check the original post first. It clearly states output as having 7 as id for all the records with 888,xyz
also your above posted sample data is different from original sample data as you've dates jumpled up for the records with ids 6 and 7
Please see the illustration for original sample data
--sample table for illustration
declare @t table
(UNIQUE_ID int,Identifier int,Identifier_code varchar(100),EFFective_Date datetime ,END_Date datetime)
--populate original sample data
INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (1, 777, N'abc', CAST(0x0000A2D200B964F0 AS DateTime), CAST(0x0000A2E0009450C0 AS DateTime))
INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (1, 777, N'abc', CAST(0x0000A2D9009450C0 AS DateTime), CAST(0x0000A2E70094DD60 AS DateTime))
INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (2, 777, N'abc', CAST(0x0000A2E0009450C0 AS DateTime), CAST(0x0000A2EE0094DD60 AS DateTime))
INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (2, 777, N'abc', CAST(0x0000A2E70094DD60 AS DateTime), CAST(0x0000A2EE0094DD60 AS DateTime))
INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (2, 777, N'abc', CAST(0x0000A2EE0094DD60 AS DateTime), NULL)
INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (5, 888, N'xyz', CAST(0x0000A2D200B964F0 AS DateTime), CAST(0x0000A2E0009450C0 AS DateTime))
INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (5, 888, N'xyz', CAST(0x0000A2D9009450C0 AS DateTime), CAST(0x0000A2E70094DD60 AS DateTime))
INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (5, 888, N'xyz', CAST(0x0000A2E0009450C0 AS DateTime), CAST(0x0000A2EE0094DD60 AS DateTime))
INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (6, 888, N'xyz', CAST(0x0000A2E70094DD60 AS DateTime), NULL)
INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (7, 888, N'xyz', CAST(0x0000A2EE0094DD60 AS DateTime), NULL)
--do the update
UPDATE t
SET UNIQUE_ID = MaxID
FROM
SELECT MAX(CASE WHEN END_DATE IS NULL THEN UNIQUE_ID END) OVER (PARTITION BY Identifier,Identifier_code) AS MaxID,UNIQUE_ID
FROM @t
)t
WHERE UNIQUE_ID <> MaxID
AND MaxID IS NOT NULL
--now check the output
SELECT * FROM @t
The output is as below
UNIQUE_ID Identifier Identifier_code EFFective_Date END_Date
2 777 abc 2014-02-14 11:15:00.000 2014-02-28 09:00:00.000
2 777 abc 2014-02-21 09:00:00.000 2014-03-07 09:02:00.000
2 777 abc 2014-02-28 09:00:00.000 2014-03-14 09:02:00.000
2 777 abc 2014-03-07 09:02:00.000 2014-03-14 09:02:00.000
2 777 abc 2014-03-14 09:02:00.000 NULL
7 888 xyz 2014-02-14 11:15:00.000 2014-02-28 09:00:00.000
7 888 xyz 2014-02-21 09:00:00.000 2014-03-07 09:02:00.000
7 888 xyz 2014-02-28 09:00:00.000 2014-03-14 09:02:00.000
7 888 xyz 2014-03-07 09:02:00.000 NULL
7 888 xyz 2014-03-14 09:02:00.000 NULL
Now compare it with original output and you'll find they're the same
UNIQUE_ID Identifier Identifier_code EFFective_Date END_Date
2 777 abc 2/14/2014 11:15 2/28/2014 9:00
2 777 abc 2/21/2014 9:00 3/7/2014 9:02
2 777 abc 2/28/2014 9:00 3/14/2014 9:02
2 777 abc 3/7/2014 9:02 3/14/2014 9:02
2 777 abc 3/14/2014 9:02 NULL
7 888 xyz 2/14/2014 11:15 2/28/2014 9:00
7 888 xyz 2/21/2014 9:00 3/7/2014 9:02
7 888 xyz 2/28/2014 9:00 3/14/2014 9:02
7 888 xyz 3/7/2014 9:02 NULL
7 888 xyz 3/14/2014 9:02 NULL
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Select querry for maximum value
Hi,
I want to select fields A B C D from a database table TAB using some selection criteria from selection screen, but the greatest value of A has to be selected for all unique entries of B C and D. Please suggest an appropriate select querry.
PS: I cannot use SELECT and then DELETE ADJACENT DUPLICATES as it will effect performance in some cases.
Regards.Try using aggregate function MAX with SELECT statement.
MAX Returns the greatest value in the column determined by the database field f for the selected lines. Specifying DISTINCT does not change the result. NULL values are ignored unless all values in a column are NULL values. In this case, the result is NULL .
Have a look at below link:
[Select Clause|http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/select_c.htm]
I hope it helps.
Best Regards,
Vibha
Please mark all the helpful answers -
Select query for single record
hi all,
i am working for script which is letter.
i had to extract the fields as shown in the code. from two tables i had to extract single record. and pass this values to script.i developed the code. wen i execute the code its going to dump. can any body help me.
TABLES : VBAK, KNA1.
PARAMETERS : p_vbeln LIKE vbak-vbeln.
Data : name like kna1-name1.
Data: begin of wa_vbak ,
vbeln(10),
netwr(15),
bstdk(8),
kunnr(10),
smenr(8),
end of wa_vbak.
Data: begin of wa_final,
vbeln(10),
netwr(15),
bstdk(8),
kunnr(10),
smenr(8),
name1(35),
end of wa_final.
Select single vbeln
netwr
bstdk
kunnr
smenr from vbak
into wa_vbak where vbeln = p_vbeln.
If sy-subrc = 0.
Select single name1 from kna1 into name where kunnr = wa_vbak-kunnr.
If sy-subrc = 0.
Move wa_vbak-vbeln to wa_final-vbeln.
Move wa_vbak-netwr to wa_final-netwr.
Move wa_vbak-bstdk to wa_final-bstdk.
Move wa_vbak-kunnr to wa_final-kunnr.
Move wa_vbak-smenr to wa_final-smenr.
Move name to wa_final-name1.
endif.
endif.
write:/10 wa_final-vbeln, 20 wa_final-netwr.
thanks
venkatHai,
Make sure that field names(itab) are same as database tables.
And also INTO CORRESPONDING FIELDS OF TABLE .
The modified code is as below:
TABLES : VBAK, KNA1.
PARAMETERS : p_vbeln LIKE vbak-vbeln.
Data : name like kna1-name1.
Data: begin of wa_vbak ,
vbeln(10),
netwr(15),
bstdk(8),
kunnr(10),
smenr(8),
end of wa_vbak.
Data: begin of wa_final,
vbeln(10),
netwr(15),
bstdk(8),
kunnr(10),
smenr(8),
name1(35),
end of wa_final.
Data:
T_wa_vbak like standard table of wa_vbak.
Select single vbeln
netwr
bstdk
kunnr
smenr from vbak
into <b>CORRESPONDING FIELDS OF TABLE T_</b>wa_vbak where vbeln = p_vbeln.
If sy-subrc = 0.
Select single name1 from kna1 into name where kunnr = wa_vbak-kunnr.
If sy-subrc = 0.
Move wa_vbak-vbeln to wa_final-vbeln.
Move wa_vbak-netwr to wa_final-netwr.
Move wa_vbak-bstdk to wa_final-bstdk.
Move wa_vbak-kunnr to wa_final-kunnr.
Move wa_vbak-smenr to wa_final-smenr.
Move name to wa_final-name1.
endif.
endif.
write:/10 wa_final-vbeln, 20 wa_final-netwr.
Regards,
Rama chary.Pammi -
Use of LIKE in where clause of select statement for multiple records
Hi Experts,
I have a account number field which is uploaded from a file. Now this account numbers uploaded does not match fully with sap table account numbers but it contains all of the numbers provided in the file mostly in the upright positions.
For example in file we have account number as 2ARS1 while in sap table the value is 002ARS1.
And i want to fetch data from sap table based on account number uploaded. So, i am trying to use LIKE with for all entries but its not working as mentioned below but LIKE is not working with FOR ALL ENTRIES.
data : begin of t_dda occurs 0,
dda(19) type c,
end of t_dda.
data : begin of t_bukrs occurs 0,
bukrs type t012k-bukrs,
end of t_bukrs.
data : dda type t012k-bankn,
w_dda type t012k-bankn.
CONCATENATE '%'
'2ARS1'
INTO W_DDA.
MOVE W_DDA TO T_DDA-DDA.
APPEND T_DDA.
CLEAR T_DDA.
free t_bukrs.
SELECT BUKRS
FROM T012K
into TABLE t_bukrs
for all entries in t_dda
WHERE BANKN like t_dda-dda.
Can anybody suggest what should i use to get the data for multiple account numbers using one select statement only instead on using SELECT UP TO 1 ROWS in LOOP....ENDLOOP ?
Thanks in advance,
AkashHi,
yes, For All entries won't work for LIKE with '% '.
I think the other alternative is go for Native SQL by writing sub-query
sample code is here:
data: begin of i_mara occurs 0,
matnr like mara-matnr,
matkl like mara-matkl,
end of i_mara.
exec sql.
select matnr, matkl from mara where matnr in (select matnr from marc) and matnr like '%ma' into :i_mara
endexec.
loop at i_mara.
write:/ i_mara-matnr, i_mara-matkl.
endloop.
hope u got it.
regards
Mahesh
Edited by: Mahesh Reddy on Jan 21, 2009 2:32 PM -
Hi,
i wont to do select just for 500 Records what is the best way to do that.
RegardsHi Ric,
use ' UP TO 500 ROWS ' in ur querry..
syntax:- select <fieldname> from <table name> into table <internal table name> up to 500 rows.
plz reward points if it finds helpful 2 u..
Edited by: sreejith gn on May 13, 2008 9:36 AM
Edited by: sreejith gn on May 13, 2008 9:53 AM -
How to make SELECT querry to work for CONVERSION EXIT
Dear All,
I want to select some data from from table J_1IEXCTAX , and to limit that retrieval I have WHERE clause for fields VALIDFROM and VALIDTO
My select querry is like
SELECT SINGLE RATE ECSRATE
FROM J_1IEXCTAX
INTO (J_1IEXCTAX-RATE,J_1IEXCTAX-ECSRATE)
WHERE J_1ICHID = J_1IMTCHID-J_1ICHID and
( VALIDFROM LE T_GRREC-BUDAT and
VALIDTO GE T_GRREC-BUDAT ).
But the field VALIDFROM and VALIDTO have data (i.e. dates) in different format
So my selection doesnt happen..
these formats can be converted to desired format using CONVERSION EXITs at their domain level...
But that increases coding and worsens performance.....
Could anybody give me some other solution?
Thanks in advance................
Code Formatted by: Alvaro Tejada Galindo on Jan 8, 2009 10:58 AMHi,
write T_GRREC-BUDAT to gv_date as <specify the format>
now use gv_date in ur seelct query.
Regards,
Nagaraj -
Record selector dont work for specific record selection
Hi,
I have a issue with the record selector in a spotlight.
I want to select specific record, but when I select the check the record don't go in the selected record tab!
the files dataservice.json and endecaBrowserService.json are correctly configure I think. I did compare with the Discover app. but I don't see want would be the issue! not that the dynamic record selection work correctly
endecaBrowserService.json
"host": "W177",
"port": "15101",
"recSpecProp": "Product_SKU",
"recAggregationKey": "Endeca_Rollup_Id",
"recFilter": "",
"recImgUrlProp" : "URL_Thumbnail1",
"recDisplayProps": [ "Brand","Category_EN","Product_SKU"],
"textSearchKey": "interface_EN",
"textSearchMatchMode" : "ALLPARTIAL"
dataservice.json
"jcr:primaryType": "endeca:unstructured",
"host": "W177",
"port": "15101",
"recordSpecName": "Product_SKU",
"aggregationKey": "Endeca_Rollup_Id",
"recordFilter": "",
"wildcardSearchEnabled": false,
"recordNameField": "product_name_en",
"fields": {"Brand" : "", "Category_EN":"","Product_SKU":""}
any Idea
thanksHi TimK,
actualy I dont have space in the record spec, but it look like this 8-474F9138-409-2. I assume that '-' wore bad character like your space.
when I transfore the record spec to 8_474F9138_409_2. the record selector work perfectly
thanks TimK for leading me to the solution
good day -
I need a query that selects the amount of records for each day in a table.
I need a query that selects the amount of records for each
day in a table.
Eg the result would be:
date 1 14
date 2 3
etc
Any ideas?sorted:
SELECT count([commentID]),convert(varchar, dateAdded, 112)
FROM COMMENTSgroup by convert(varchar, dateAdded,
112) -
I downloaded the OEHR Sample Objects application and followed the steps in Oracle® Application Express Advanced Tutorials
Release 3.2.
The parameters and report seem to be working correctly except when I enter "all" for department or manager I get no matching hits.
What's the most efficient way to retrieve "all" if the users selects all for dept and mgr - thus we'd want to return all records in the table.
Region snipprt
Enter Search
Search Employee
Dept
- ALL -
Administration
Marketing
Purchasing
Human Resources
Shipping
IT
Public Relations
Sales
Executive
Finance
Accounting
Treasury
Corporate Tax
Control And Credit
Shareholder Services
Benefits
Manufacturing
Construction
Contracting
Operations
IT Support
NOC
IT Helpdesk
Government Sales
Retail Sales
Recruiting
Payroll
Mgr
- ALL -
Steven King
Neena Kochhar
Lex De Haan
Alexander Hunold
Nancy Greenberg
Den Raphaely
Matthew Weiss
Adam Fripp
Payam Kaufling
Shanta Vollman
Kevin Mourgos
John Russell
Karen Partners
Alberto Errazuriz
Gerald Cambrault
Eleni Zlotkey
Michael Hartstein
Shelley Higgins
The following is the sql that was provided as part of the turitoral.
SELECT
"OEHR_EMPLOYEES"."EMPLOYEE_ID" "EMPLOYEE_ID",
"OEHR_EMPLOYEES"."FIRST_NAME" "FIRST_NAME",
"OEHR_EMPLOYEES"."LAST_NAME" "LAST_NAME",
"OEHR_EMPLOYEES"."EMAIL" "EMAIL",
"OEHR_EMPLOYEES"."PHONE_NUMBER" "PHONE_NUMBER",
"OEHR_EMPLOYEES"."HIRE_DATE" "HIRE_DATE",
"OEHR_EMPLOYEES"."JOB_ID" "JOB_ID",
"OEHR_EMPLOYEES"."SALARY" "SALARY",
"OEHR_EMPLOYEES"."COMMISSION_PCT" "COMMISSION_PCT",
"OEHR_EMPLOYEES"."MANAGER_ID" "MANAGER_ID",
"OEHR_EMPLOYEES"."DEPARTMENT_ID" "DEPARTMENT_ID"
FROM
"#OWNER#"."OEHR_EMPLOYEES" "OEHR_EMPLOYEES"
WHERE
(lower(first_name) like '%' || lower(:P1_NAME) || '%' OR
lower(last_name) like '%' || lower(:P1_NAME) || '%')
AND department_id = decode(:P1_DEPT,'%null%',department_id,:P1_DEPT)
AND manager_id = decode(:P1_MGR,'%null%',manager_id,:P1_MGR)Hi,
Use this..
SELECT
"OEHR_EMPLOYEES"."EMPLOYEE_ID" "EMPLOYEE_ID",
"OEHR_EMPLOYEES"."FIRST_NAME" "FIRST_NAME",
"OEHR_EMPLOYEES"."LAST_NAME" "LAST_NAME",
"OEHR_EMPLOYEES"."EMAIL" "EMAIL",
"OEHR_EMPLOYEES"."PHONE_NUMBER" "PHONE_NUMBER",
"OEHR_EMPLOYEES"."HIRE_DATE" "HIRE_DATE",
"OEHR_EMPLOYEES"."JOB_ID" "JOB_ID",
"OEHR_EMPLOYEES"."SALARY" "SALARY",
"OEHR_EMPLOYEES"."COMMISSION_PCT" "COMMISSION_PCT",
"OEHR_EMPLOYEES"."MANAGER_ID" "MANAGER_ID",
"OEHR_EMPLOYEES"."DEPARTMENT_ID" "DEPARTMENT_ID"
FROM
"#OWNER#"."OEHR_EMPLOYEES" "OEHR_EMPLOYEES"
WHERE
(:P1_NAME IS NULL OR
(:P1_NAME IS NOT NULL AND
(lower(first_name) like '%' || lower(:P1_NAME) || '%') OR
(lower(last_name) like '%' || lower(:P1_NAME) || '%')
) AND
(:P1_DEPT IS NULL OR department_id = :P1_DEPT) AND
(:P1_MGR IS NULL OR manager_id = :P1_MGR) -
How to show multiple values for Unique records in Report
Here's my question/problem:
I've joined two tables, one table (TBL1) contains an object id (OBJ_ID) that repeats and the other table (TBL2) contains a date (DT), object type id (OBJ_TYP_ID), and object type description (OBJ_TYP_DES). The tables are joined by an inventory id (INV_ID).
The OBJ_ID repeats and has a Date value for each record. I want to report an unique OBJ_ID and show each Date for a particular OBJ_ID in multiple Columns.
An example of the current resultset looks like this:
OBJ_ID OBJ_TYP_ID OBJ_TYP_DES DATE
1 1 TYPE1 4/1/2009
2 1 TYPE1 4/1/2009
3 1 TYPE1 4/10/2009
1 2 TYPE2 5/3/2009
3 1 TYPE1 3/30/2005
4 1 TYPE1 4/1/2009
5 1 TYPE1 4/1/2009
5 2 TYPE2 5/1/2009
1 1 TYPE1 4/3/2007
1 1 TYPE1 3/30/2005
I want to express the resultset like this:
OBJ_ID OBJ_TYP_ID OBJ_TYPE_DES DATE1 DATE2 DATE3
1 1 TYPE1 4/1/2009 4/3/2007 3/30/2005
1 2 TYPE2 5/3/2009
2 1 TYPE1 4/1/2009
3 1 TYPE1 4/10/2009 3/30/2005
4 1 TYPE1 4/1/2009
5 1 TYPE1 4/1/2009
5 2 TYPE2 5/1/2009
What technique is best to use to do this? I know I could create another table and populate the rows/columns by reading data from this query, but is there a better way?Hi,
cclemmons wrote:
I want to express the resultset like this:
OBJ_ID OBJ_TYP_ID OBJ_TYPE_DES DATE1 DATE2 DATE3
1 1 TYPE1 4/1/2009 4/3/2007 3/30/2005
1 2 TYPE2 5/3/2009
2 1 TYPE1 4/1/2009
3 1 TYPE1 4/10/2009 3/30/2005
4 1 TYPE1 4/1/2009
5 1 TYPE1 4/1/2009
5 2 TYPE2 5/1/2009
What technique is best to use to do this? I know I could create another table and populate the rows/columns by reading data from this query, but is there a better way?Absolutely! You seem to have an instictive feeling that creating a separate table just for a query is inefficient. You instinct is 100% correct. Maybe in Oracle 7 there was a reason to do that, but today you can query results of other queries as if they were tables, so temporary tables like you describe are very rarely necessary, let alone convenient.
What you want to do is pivot the date columns. Here's one way
WITH original_query AS
SELECT obj_id
, obj_typ_id
, obj_typ_des
, dt -- date is not a good column name
FROM ... -- the rest of your original query goes here
, got_rnum AS
SELECT oq.*
, ROW_NUMBER () OVER ( PARTITION BY obj_id
, obj_typ_id
, obj_typ_des
ORDER BY dt DESC
) AS rnum
FROM original_query oq
SELECT obj_id
, obj_typ_id
, obj_typ_des
, MAX (CASE WHEN rnum = 1 THEN dt END) AS dt1
, MAX (CASE WHEN rnum = 2 THEN dt END) AS dt2
, MAX (CASE WHEN rnum = 3 THEN dt END) AS dt3
, MAX (CASE WHEN rnum = 4 THEN dt END) AS dt4
, MAX (CASE WHEN rnum = 5 THEN dt END) AS dt5
FROM got_rnum
GROUP BY obj_id
, obj_typ_id
, obj_typ_des
;As you can see, this adds two layers of queries on top of your original query. One of those layers is probably not needed; depending on what you're doing in your original main query, you can probably compute rnum there, and omit the got_rnum sub-query.
Also, depending on the relationship of obj_id, obj_typ_id and obj_typ_des, some of what I posted above may not be needed but including it won't really hurt.
If you want to know more about this technique, search for "pivot" or "rows to columns". A <tt>SELECT ... PIVOT ...</tt> keyword was introduced in Oracle 11, but most of what you'll find when you search for "pivot" doesn't assume you have Oracle 11 (nor does the query above require Oracle 11).
This assumes you know an upper limit (5 in the example above) of dts that can appear in any line of output.
See [this thread|http://forums.oracle.com/forums/thread.jspa?messageID=3527823�] for a discussion of some alternatives. -
Number for every record that is retrieved from (query)
Hello
I wish to put a number for every record that is retrieved
from the record that is output by this query
For example
For the first recored/row
Generated number, ksnumber, date
1, gg111 11/05/05
2, oo235 12/06/05
the query returned 2 records 1 and 2 are the number that is
generated with this code.
In addition if there is a built in function, where in the
code do I put it???
<cfquery name="gelov datasource="kl90">
SELECT
FROM
WHERE
ORDER BY
<cfswitch expression="#Form.orderBy#">
<cfks value="KSNUMBER">
KS.KS_NBR
</cfks>
<cfks value="CREATIONDATE">
KS.KREATDAT
</cfks>
</cfswitch>
</cfquery>
<!---html report--->
<cfswitch expression="#Form.outputFormat#">
<cfks value="HTML">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Ctwye Kss Report</title>
</head>
<style type="text/css">
table{
font-family:Arial, Helvetica, sans-serif;
font-size:10px;
td{
font-family:Arial, Helvetica, sans-serif;
font-size:10px;
th{
font-family:Arial, Helvetica, sans-serif;
font-size:10px;
h2{
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
h3{
font-family:Arial, Helvetica, sans-serif;
font-size:13px;
</style>
<body>
<cfoutput>
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<td align="center">
<h3>Ctwye Kss
Report</h3><br><br></td>
</tr>
<tr>
<td align="center">
</h2>report returned #getCtwyeKss.RecordCount#
records</h2></td>
</tr>
<tr>
<td>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td width="160">Ks Number</td>
<td>Creation Date</td>
<!--- <td class="dataField">Address</td>
<td class="dataField">Type</td>
<td class="dataField">Description</td>--->
</tr>
<cfloop query="getCtwyeKss">
<tr bgcolor="<cfif currentrow mod
2>GHOSTWHITE<cfelse>WHITE</cfif>">
<td>#KS_NBR#</td>
<td>#dateformat(KREATDAT,"mm/dd/yyyy")#</td>
</tr>
</cfloop>
</table>
</td>
</tr>
</table>
</BODY>
</HTML>
</cfoutput>
</cfks>
<cfks value="CSV">
<CFHEADER NAME="Content-Disposition" VALUE="attachment;
filename=ctwye.csv">
<cfcontent type="application/msexcel">"Ks
Number","Creation Date"
<cfoutput
query="getCtwyeKss">#ltrim(KS_NBR)#,"#dateformat(KREATDAT,"mm/dd/yyyy")#"
<tr #IIF(getCtwyeKss.CurrentRow MOD
2,DE(''),DE('backgroundColor="##999"'))#>
<!---<tr bgcolor="<cfif currentrow mod
2>##808080<cfelse>##ffffff</cfif>"> --->
</cfoutput>
</cfks>
</cfswitch><cfks> is not a Coldfusion tag. Use <cfcase>
instead.
The following code will print the row numbers
<cfquery name="gelov" datasource="kl90">
select ksnumber, date
from yourTable
</cfquery>
<cfoutput query="gelov">
#currentrow#, #ksnumber#, #date#<br>
</cfoutput> -
Check for duplicate record in SQL database before doing INSERT
Hey guys,
This is part powershell app doing a SQL insert. BUt my question really relates to the SQL insert. I need to do a check of the database PRIOR to doing the insert to check for duplicate records and if it exists then that record needs
to be overwritten. I'm not sure how to accomplish this task. My back end is a SQL 2000 Server. I'm piping the data into my insert statement from a powershell FileSystemWatcher app. In my scenario here if the file dumped into a directory starts with I it gets
written to a SQL database otherwise it gets written to an Access Table. I know silly, but thats the environment im in. haha.
Any help is appreciated.
Thanks in Advance
Rich T.
#### DEFINE WATCH FOLDERS AND DEFAULT FILE EXTENSION TO WATCH FOR ####
$cofa_folder = '\\cpsfs001\Data_pvs\TestCofA'
$bulk_folder = '\\cpsfs001\PVS\Subsidiary\Nolwood\McWood\POD'
$filter = '*.tif'
$cofa = New-Object IO.FileSystemWatcher $cofa_folder, $filter -Property @{ IncludeSubdirectories = $false; EnableRaisingEvents= $true; NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite' }
$bulk = New-Object IO.FileSystemWatcher $bulk_folder, $filter -Property @{ IncludeSubdirectories = $false; EnableRaisingEvents= $true; NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite' }
#### CERTIFICATE OF ANALYSIS AND PACKAGE SHIPPER PROCESSING ####
Register-ObjectEvent $cofa Created -SourceIdentifier COFA/PACKAGE -Action {
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
#### CERTIFICATE OF ANALYSIS PROCESS BEGINS ####
$test=$name.StartsWith("I")
if ($test -eq $true) {
$pos = $name.IndexOf(".")
$left=$name.substring(0,$pos)
$pos = $left.IndexOf("L")
$tempItem=$left.substring(0,$pos)
$lot = $left.Substring($pos + 1)
$item=$tempItem.Substring(1)
Write-Host "in_item_key $item in_lot_key $lot imgfilename $name in_cofa_crtdt $timestamp" -fore green
Out-File -FilePath c:\OutputLogs\CofA.csv -Append -InputObject "in_item_key $item in_lot_key $lot imgfilename $name in_cofa_crtdt $timestamp"
start-sleep -s 5
$conn = New-Object System.Data.SqlClient.SqlConnection("Data Source=PVSNTDB33; Initial Catalog=adagecopy_daily; Integrated Security=TRUE")
$conn.Open()
$insert_stmt = "INSERT INTO in_cofa_pvs (in_item_key, in_lot_key, imgfileName, in_cofa_crtdt) VALUES ('$item','$lot','$name','$timestamp')"
$cmd = $conn.CreateCommand()
$cmd.CommandText = $insert_stmt
$cmd.ExecuteNonQuery()
$conn.Close()
#### PACKAGE SHIPPER PROCESS BEGINS ####
elseif ($test -eq $false) {
$pos = $name.IndexOf(".")
$left=$name.substring(0,$pos)
$pos = $left.IndexOf("O")
$tempItem=$left.substring(0,$pos)
$order = $left.Substring($pos + 1)
$shipid=$tempItem.Substring(1)
Write-Host "so_hdr_key $order so_ship_key $shipid imgfilename $name in_cofa_crtdt $timestamp" -fore green
Out-File -FilePath c:\OutputLogs\PackageShipper.csv -Append -InputObject "so_hdr_key $order so_ship_key $shipid imgfilename $name in_cofa_crtdt $timestamp"
Rich ThompsonHi
Since SQL Server 2000 has been out of support, I recommend you to upgrade the SQL Server 2000 to a higher version, such as SQL Server 2005 or SQL Server 2008.
According to your description, you can try the following methods to check duplicate record in SQL Server.
1. You can use
RAISERROR to check the duplicate record, if exists then RAISERROR unless insert accordingly, code block is given below:
IF EXISTS (SELECT 1 FROM TableName AS t
WHERE t.Column1 = @ Column1
AND t.Column2 = @ Column2)
BEGIN
RAISERROR(‘Duplicate records’,18,1)
END
ELSE
BEGIN
INSERT INTO TableName (Column1, Column2, Column3)
SELECT @ Column1, @ Column2, @ Column3
END
2. Also you can create UNIQUE INDEX or UNIQUE CONSTRAINT on the column of a table, when you try to INSERT a value that conflicts with the INDEX/CONSTRAINT, an exception will be thrown.
Add the unique index:
CREATE UNIQUE INDEX Unique_Index_name ON TableName(ColumnName)
Add the unique constraint:
ALTER TABLE TableName
ADD CONSTRAINT Unique_Contraint_Name
UNIQUE (ColumnName)
Thanks
Lydia Zhang -
JBO-26080: Error while selecting entity for SampleEO
Hi,
I have a VO based on Entity Object. While I am going to update a record using this VO, its getting updated in the DB table.
But after that while I am going to execute the VO for displaying the data its giving the below error.
"oracle.jbo.DMLException: JBO-26080: Error while selecting entity for SampleEO
Can anyone suggest what could be the reason for this error?
--AbhijitHi Timo,
I am using jdev 10.1.3.4 (jsf-ADF BC). I googled the error but didn't find any solution.
Is there anyhing to do with the EO configuration or property?
Any help will be appreciated.
--Abhijit -
Table cntrol field to be display/Change only For each record
Hi all,
How to set a particular Field in table control either as display only or
change only for <b>each row</b> based on certain condition.I need to set this property for each record in table control not for the entire coloumn?.I know the procedure for setting up an entire coloumn in table control either as diplay or change only using <b>Loop at screen</b> statement.
Conditions:
If Material is batch managed:
itab-batch field has to be <b>Display only</b> mode.
if material is not batch managed:
itab-batch field has to be <b>change mode</b>.
<b>O/p of Table Control :</b>
Material Batch
1000 Display only
2000 Change only
8000 Change only
3500 Display only
3600 Display onlyHi Ravi,
Thanks for your reply.I have put the code as u said. It is modifying the whole coloumn insted of modifying Current row of the coloumn.
I have tried to modify the screen property using Table control attributes (TC-COLS).The following commented code is that logic.Even that also doing the same thing.Can yoy please tell me how to do it.
MODULE tc_get_lines OUTPUT.
LOOP AT SCREEN.
IF screen-name = 'X_ZPINV-CHARG'.
IF fg_batch = ' '.
screen-input = 0.
ELSE.
screen-input = 1.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
LOOP AT tc-cols INTO tc_wa
WHERE screen-name = 'X_ZPINV-CHARG'.
IF x_zpinv-matnr IS NOT INITIAL.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = x_zpinv-matnr
IMPORTING
output = v_matnr.
SELECT SINGLE * FROM marc WHERE matnr = v_matnr
AND werks = w_plant.
IF marc-xchar IS INITIAL.
tc_wa-screen-input = 0.
ELSE.
tc_wa-screen-input = 1.
ENDIF.
MODIFY tc-cols FROM tc_wa INDEX sy-tabix." transporting screen-input
ENDIF.
ENDLOOP.
ENDMODULE. "TC_GET_LINES OUTPUT
Maybe you are looking for
-
Server Problem, thanks for your help
Hi there, We have 2 informix database instabce running on same machine. Call devdb and systestdb. The structure are same. The question is, when I run application on systestdb, it works. But if i run same app on devdb, seems nothing happen. I do belie
-
On my Mac book pro, a grey progress bar will appear for a Little bit and the computer will shut down. What do I do?
-
hi everybody , i have a page wich content a menu , i want when i clic on a menu only the content of the page change (from table to form in my case) . how to achieve this with adf i think i can use ppr but how ? thanks
-
How can I read st22 dump in ABAP
hello, i would like to know if st22 dump info could be read via FMs or Classes. I found a class CL_DUMP_INFO_MANAGER, btu well could not find documentation on it usage. Will be glad if someone can tell me how to retrieve St22 info. - Harish
-
Hi All, This one's got me. I have the following requirement in my app: - Ability to browse for, and save files to the database. - View (and modify if required) saved files using the default external application. - When the default external applicatio