Query to get the details of Blocking and deadlock occurred for the Day
Hi,
I need a query to get the details of blocking and deadlock occurred for the day.
You havent specified which version of SQL you are using which makes it difficult to give a solution. Assuming its latest versions , by default SQL Server (in any versions) doesnt track blocking information.
You need to run some kind of queries/traces to capture blocking. The same goes with Deadlocks where majority of the DBA's enable trace flag 1222/1205 when they suspect deadlocks happening.
Check this link -
http://dba.stackexchange.com/questions/10644/deadlock-error-isnt-returning-the-deadlock-sql/10646#10646
This link gives code to get historic deadlock information. I havent used it , I just googled to get that.
That being said if you are looking for something to capture for the future check the below links.
Check these links on how to setup extended events to capture deadlock and blocking.
http://sqlblog.com/blogs/jonathan_kehayias/archive/2010/12/21/an-xevent-a-day-21-of-31-the-future-tracking-blocking-in-denali.aspx
http://blogs.msdn.com/b/sqlserverfaq/archive/2013/04/27/an-in-depth-look-at-sql-server-memory-part-2.aspx
http://blogs.technet.com/b/mspfe/archive/2012/06/28/how_2d00_to_2d00_monitor_2d00_deadlocks_2d00_in_2d00_sql_2d00_server.aspx
HTH
Regards, Ashwin Menon My Blog - http:\\sqllearnings.com
Similar Messages
-
Query to get the blocker and holder info
Hi All,
I have framed the following query to get the blocker and holder info.I intend to use this query in a auto-generated mail which executes every 15 mins
I have put an outer join on the holder because the holder query might have been executed at the time the auto mail configuration fires this query
I am not a dba and was apprehensive is there is some mistake in the logic of my query. I was also expecting to join v$sql_bind_capture using sql_hash_value and sql_address just the way in which I have joined v$sqlarea
Looking forward to your kind help in vetting the below query
Select distinct waiting_session,
dba_waiters.holding_session,
decode(to_char(session_waiting_info.STATE),'0','waiter is currently waiting','-2','duration of last wait by waiter is unknown','-1','waiter waited for a short time',' waiter waited long time') "waiters waiting state",
decode(session_waiting_info.WAIT_TIME,0,'waiter waiting') "waiters last wait time",
decode(to_char(session_holding_info.STATE),'0','holder is currently waiting','-2','duration of last wait by holder is unknown','-1','holder waited for a short time','holder waited long time') "holders waiting state",
decode(session_holding_info.WAIT_TIME,0,'waiter waiting') "holders last wait time",
sql_waiting_info.sql_text "query of the waiter",
sql_holding_info.sql_text "query of the holder",
session_waiting_info.STATUS "waiting STATUS",
session_holding_info.STATUS "holding STATUS",
session_waiting_info.process "waiting process",
session_waiting_info.PROGRAM "waiting PROGRAM",
session_holding_info.process "holding process",
session_holding_info.PROGRAM "holding PROGRAM",
session_waiting_info.ROW_WAIT_OBJ# "waiting object",
session_waiting_info.ROW_WAIT_ROW# "waiting row",
session_holding_info.ROW_WAIT_OBJ# "holding object",
session_holding_info.ROW_WAIT_ROW# "holding row",
session_waiting_info.BLOCKING_SESSION_STATUS "waiting session status",
session_holding_info.BLOCKING_SESSION_STATUS "holding session status",
session_waiting_info.username "holding os username",
session_holding_info.username "waiting os username",
session_waiting_info.MACHINE "waiting MACHINE",
session_waiting_info.TERMINAL "waiting TERMINAL",
session_holding_info.MACHINE "holding MACHINE",
session_holding_info.TERMINAL "holding TERMINAL",
session_waiting_info.TYPE "waiting TYPE",
session_holding_info.TYPE "holding TYPE"
from dba_waiters,
v$session session_holding_info,
v$session session_waiting_info,
v$sqlarea sql_waiting_info,
v$sqlarea sql_holding_info
Where dba_waiters.waiting_Session = session_waiting_info.sid
and dba_waiters.holding_Session = session_holding_info.sid
And session_waiting_info.sql_hash_value = sql_waiting_info.hash_value
And session_waiting_info.sql_address = sql_waiting_info.address
and session_holding_info.sql_hash_value = sql_holding_info.hash_value(+)
And session_holding_info.sql_address = sql_holding_info.address(+)
and dba_waiters.mode_held <> 'None'
Regards,
Vishal
Edited by: user11924113 on Feb 18, 2011 2:39 AMQuery to track the holder and waiter info
People who reach this place for a similar problem can use the above link to find their answer
Regards,
Vishal -
Query to get details of blocking and deadloack recorded in a table
Hi,
whenever any blocking or deadlock occur in the server i have to record that information in a table with the query which is causing the locks with the login name.. Any query for this?Blocking
For example, a 200-second blocked process threshold can
be configured in SQL Server Management Studio as follows:
1.
Execute Sp_configure ‘blocked process threshold’, 200
2.
RECONFIGURE WITH OVERRIDE;
Once the blocked process threshold is established, the next step is
to capture the trace event. The trace events of blocking events that
exceed the user configured threshold can be captured with SQL Trace or Profiler.
3.
If using SQL Trace, use sp_trace_setevent and event_id=137.
4.
If using SQL Server Profiler, select the Blocked Process Report event
class (under the Errors and Warnings object).
Blocking per object with sys.dm_db_index_operational_stats
The new SQL Server 2005 DMV Sys.dm_db_index_operational_stats
select top 10 *
from sys.dm_os_wait_stats
order by wait_time_ms desc
Deadlocks
Prerequisites : Please note that you must have Database Mail configured,
SQL Server Agent must have the correct Alert System Configurations set to utilize this method and
Traceflag 1222 must be on (DBCC TRACEON(1222, -1).
To make this work, first you will need to create the stored procedure that performs
several steps, which are outlined below. Run this script to create the stored procedure:
CREATE PROC dbo.usp_DeadlockNotification
AS
DECLARE @NumOfDeadLocks int
SELECT @NumOfDeadLocks = SUM(cntr_value)
FROM sys.dm_os_performance_counters
WHERE counter_name like '%dead%'
SET NOCOUNT ON
IF(@NumOfDeadLocks > 0)
BEGIN
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'SQLTestCluster',
@recipients = '[email protected]',
@subject = 'Deadlocks',
@body = 'Please check errorlog for Deadlocks'
END
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Query to get the customer's ship_to Phone# and Fax#
Gurus -
Can anyone of you please help me in getting a query to shows the phoen and fax# of the Customer's ship_to Phone# and fax#
customers--> on Address tab ( click open) On next screen click on contacts tabe for SHIP_TO row , there under the communications section, there are telephone and fax details , i want to get those details.
Please help me in getting the query to get the fax and phone#.
Infact I am using the below query and still having issues getting the correct fax# ( using teh same logic for phone#)
select DISTINCT DECODE(PHONE_AREA_CODE,NULL,'',PHONE_AREA_CODE||'-')||PHONE_NUMBER
FROM hz_cust_accounts_all hca,
hz_parties hzp1,
hz_cust_acct_sites_all hcas,
hz_cust_site_uses_all hcsu,
hz_relationships hzr,
hz_org_contacts hoc,
hz_contact_points hcp,
hz_parties hzp,
hz_cust_accounts_all hca1,
hr_locations hrl
WHERE 1 = 1
AND hca.party_id = hzr.object_id
AND hzr.relationship_id = hoc.party_relationship_id
AND hoc.party_site_id = hcas.party_site_id
AND hcas.cust_acct_site_id = hcsu.cust_acct_site_id
AND hzr.party_id = hcp.owner_table_id
--AND hcp.primary_flag = 'Y'
AND hzr.subject_id = hzp.party_id
AND hzp.party_id = hca1.party_id(+)
AND hzp1.party_id(+) = hca.party_id
AND hcsu.location = hrl.location_id(+)
and hcsu.site_use_id = hsu.site_use_id
AND hcp.OWNER_TABLE_NAME IN ('HZ_PARTIES')
AND hcp.CONTACT_POINT_TYPE IN ('PHONE')
AND hcp.PHONE_LINE_TYPE = 'FAX'
AND hcp.STATUS = 'A'
and nvl (hcsu.status, 'x') = 'A'
AND hcsu.SITE_USE_CODE = 'SHIP_TO'
--and hcsu.site_use_id = hsu.site_use_id
-- and hcsu.cust_acct_site_id = hsu.cust_acct_site_id
--and hca1.cust_account_id = hca.cust_account_idWhat is the responsibility name? Form name and navigation path?
You can determine the query from the form itself as follows:
- Query the record(s)
- Click on Help > Diagnostics > Examine
- Under 'Block' field, select 'SYSTEM'
- Under 'Field' field, select 'LAST_QUERY'
You may also review the following note:
Note: 259722.1 - HOWTO Determine Table and Column Name from a field in a form in 11i
https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=259722.1 -
Query to get the Excise amount and basic amount based on the cst or vat tax
Dear all,
I need a right query to get the basic amount ,excise amount and the tax amount based on the CST or VAT tax rate.The output should be like this,
VAT
goods excisabe at 1% - taxable amt(basic+excise for vat 1%) tax amt
goods excisable at 4%- txable amt tax amt
CST
goods excisabe at 1% - taxable amt(basic+excise for CST 1%) tax amt
My problem will also be solved..if i am able to get the basic value from base table OPCH itself............Since am using the PCH1 table to get the total basic amt...the values are duplicating.
Regards,
ShyamHi Sowjanya,
If you're simply trying to place a grand total, use the 'Insert Summary' option.
Choose the measure field as the 'Field to Summarize' > Choose 'Sum' as the summary operation > Under 'Summary Location' choose 'Grand Total Report Footer'.
-Abhilash -
SQL query to get the Datetime 06 hours prior to the table Datetime value
Hi Experts,
I'm just trying to create a SQL query to get the Datetime which should be 06 hours prior to my Table column value(Executiontime),
Eg: my Executiontime(column) value is 07:00AM means, this query should fetch the detail of first VMName from table at 01:00AM,
SQL Table Name: TestTable
Columns: VMName(varchar),status(varchar) Executiontime(Datetime)
SQL Query : Select Top 1 VMName from
TestTable where convert(date,Exeutiontime)=convert(date,getdate()) and
status='0' and ExecutionTime > dateadd(hour,6,getdate())
Request someone to alter this Query to my requirement or give me the new one.
Regards,
Sundar
SundarHi All,
Thanks for your Prompt response. I tried the below queries, but still I don't have any luck. Actually the queries are returning the value before the condition met (say when the time difference is more than 06 hours). I want the
query to return exactly @ 06 hour difference or less than 06 hours,
Query 01: Select Top 1 VMName from TestTable where
convert(date,Exeutiontime)=convert(date,getdate())
and status='0'
and ExecutionTime >
dateadd(hour,-6,getdate())
Query 02: Select
Top 1 VMName from TestTable where
status='0'
and ExecutionTime >
dateadd(hour,-6,getdate())
Query 03: Select
Top 1 VMName from TestTable where status='0'
and ExecutionTime >
dateadd(hour,-6,ExecutionTime)
Can someone point out the mistake please.
Regards,
Sundar
Sundar -
SQL query to get transaction detail from DEFERRED_TRAN_ID
Hi,
I'm using Oracle Advance Replication and get the transaction detail from Enterprise Manager Console.
So instead of using the console.
Is there a way any SQL query which get transaction details like SQL query fired, old and new column value etc from DEFERRED_TRAN_ID.
thanksquote:
Originally posted by:
lucapac
I have two tables: tblWorkers and tblSkills. tblWorkers has a
column, Skills, which is populated from a multiple-checkbox form
field with one or more skill_IDs from tblSkills, so each
tblWorkers.Skills consists of a list of one or more comma-delimited
values. For any Skill_ID, I need to generate a listing of all
Workers with the corresponding skill, so I have tried to do
something along the lines of SELECT WorkerName FROM tblWorkers
WHERE Skills IN (Skills, #FORM.Skill_ID#) ... or WHERE Skills IN
(ListFind(Skills, #FORM.Skill_ID#)) ... etc. ??? My results (once I
got data type mismatches out of the way) return all Workers, not
just those with the desired Skill. There must be an easy way to do
this ... How do people with a bit more CF/SQL experience than I
have do this???
As Kronin implied, we normalize our databases. If you don't
understand that answer, the book "Database Design for Mere Mortals"
is often mentioned on this forum. -
Query to get the data of all the columns in a table except any one column
Can anyone please tell how to write a query to get the data of all the columns in a table except one particular column..
For Example:
Let us consider the EMP table.,
From this table except the column comm all the remaining columns of the table should be listed
For this we can write a query like this..
Select empno, ename, job, mgr, sal, hiredate, deptno from emp;
Just to avoid only one column, I mentioned all the remaining ( 7 ) columns of the table in the query..
As the EMP table consists only 8 columns, it doesn't seem much difficult to mention all the columns in the query,
but if a table have 100 columns in the table, then do we have to mention all the columns in the query..?
Is there any other way of writing the query to get the required result..?
Thanks..Your best best it to just list all the columns. Any other method will just cause more headaches and complicated code.
If you really need to list all the columns for a table because you don't want to type them, just use something like...
SQL> ed
Wrote file afiedt.buf
1 select trim(',' from sys_connect_by_path(column_name,',')) as columns
2 from (select column_name, row_number() over (order by column_id) as column_id
3 from user_tab_cols
4 where column_name not in ('COMM')
5 and table_name = 'EMP'
6 )
7 where connect_by_isleaf = 1
8 connect by column_id = prior column_id + 1
9* start with column_id = 1
SQL> /
COLUMNS
EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO
SQL> -
How to modify the query to get the output in a single row
Hi All,
Below is the query i have written it works fine
select DISTINCT right(left(CTACCT,13),4) AS LocationNum,
tODS_GLBalance.FiscalYearId AS FiscalYearId,
tODS_GLBalance.FiscalMonthOfYearId AS FiscalMonthOfYearId,
--tods_GLMetadata.Metric,
Case when
tods_GLMetadata.Metric = 'Gross Margin'
Then SUM(Balance)
Else 0
END AS GrossMargin,
Case when
tods_GLMetadata.Metric = 'Occupancy'
Then SUM(Balance)
Else 0
END AS Occupancy,
Case when
tods_GLMetadata.Metric = 'Payroll Dollars'
Then SUM(Balance)
Else 0
END AS Payroll,
Case when
tods_GLMetadata.Metric = 'CF Sales'
Then SUM(Balance)
Else 0
END AS OperatingSales,
Case when
tods_GLMetadata.Metric = 'Operations'
Then SUM(Balance)
Else 0
END AS OperatingExpenses
-- 0 as payroll
from ods.[JJill].[tODS_GLBalance]
inner join ods.Staging.tODS_INF_GLPCT ON tODS_GLBalance.PageNum = tODS_INF_GLPCT.CTPAGE
inner join ods.JJill.tods_GLMetadata ON tods_GLMetadata.AcctDescription = tODS_INF_GLPCT.CTDESC
where
(tODS_GLBalance.FiscalYearId = 2012) and
(tODS_GLBalance.FiscalMonthOfYearId = 2) and
(right(left(CTACCT,13),4)= 3020)
group by
right(left(CTACCT,13),4),
tODS_GLBalance.FiscalYearId,
tODS_GLBalance.FiscalMonthOfYearId,
tods_GLMetadata.Metric
This is the sample output,
LocationNum FiscalYearId FiscalMonthOfYearId GrossMargin Occupancy Payroll OperatingSales OperatingExpenses
3020 2012 2 -112477.00 0.00 0.00 0.00 0.00
3020 2012 2 0.00 0.00 0.00 -158288.94 0.00
3020 2012 2 0.00 0.00 0.00 0.00 5625.44
3020 2012 2 0.00 0.00 24185.79 0.00 0.00
3020 2012 2 0.00 31075.53 0.00 0.00 0.00
But, i am expecting the output to be something like this
LocationNum FiscalYearId FiscalMonthOfYearId GrossMargin Occupancy Payroll OperatingSales OperatingExpenses
3020 2012 2 -112477.00 31075.53 24185.79 -158288.94 5625.44
Can someone please help me with changing my query to get the desired output?
Please let me know if you have any questions.
ThanksTry this:
SELECT DISTINCT
RIGHT(LEFT(CTACCT,13),4) AS LocationNum, tODS_GLBalance.FiscalYearId AS FiscalYearId, tODS_GLBalance.FiscalMonthOfYearId AS FiscalMonthOfYearId,
SUM(CASE WHEN tods_GLMetadata.Metric = 'Gross Margin' THEN Balance ELSE 0 END ) AS GrossMargin,
SUM(CASE WHEN tods_GLMetadata.Metric = 'Occupancy' THEN Balance ELSE 0 END ) AS Occupancy,
SUM(CASE WHEN tods_GLMetadata.Metric = 'Payroll Dollars' THEN Balance ELSE 0 END ) AS Payroll,
SUM(CASE WHEN tods_GLMetadata.Metric = 'CF Sales' THEN Balance ELSE 0 END ) AS OperatingSales,
SUM(CASE WHEN tods_GLMetadata.Metric = 'Operations' THEN Balance ELSE 0 END ) AS OperatingExpenses
FROM ods.[JJill].[tODS_GLBalance]
INNER JOIN ods.Staging.tODS_INF_GLPCT
ON tODS_GLBalance.PageNum = tODS_INF_GLPCT.CTPAGE
INNER JOIN ods.JJill.tods_GLMetadata
ON tods_GLMetadata.AcctDescription = tODS_INF_GLPCT.CTDESC
WHERE tODS_GLBalance.FiscalYearId = 2012
AND tODS_GLBalance.FiscalMonthOfYearId = 2
AND RIGHT(LEFT(CTACCT,13),4) = 3020
GROUP BY right(left(CTACCT,13),4), tODS_GLBalance.FiscalYearId, tODS_GLBalance.FiscalMonthOfYearId, tods_GLMetadata.Metric -
Query to get the hierarchical results
Hi,
Please help me in writing a Query to get the hierarchical results. I want a result like follows...
course-----groupname---TotalMembers---NotStarted---INProgress---Completed
Course1---country1--------12---------------6----------3-------------3
Course1-----state11-------12---------------6----------3-------------3
Course1------District111--10---------------5----------0-------------0
Course1--------City1111----0---------------0----------0-------------0
Course1--------City1112----1---------------0----------0-------------1
Course1--------City1113----6---------------3----------2-------------1
Course1---country2--------12---------------6----------3-------------3
Course1----state21--------12---------------6----------3-------------3
Course1------District211--10---------------5----------0-------------0
Course1--------City2111----0---------------0----------0-------------0
Course1--------City2112----1---------------0----------0-------------1
Course1--------City2113----6---------------3----------2-------------1
Course2---country1--------12---------------6----------2-------------3
Course2----state11--------12---------------6----------2-------------3
Course2------District111--10---------------5----------0-------------0
Course2--------City1111----0---------------0----------0-------------0
Course2--------City1112----1---------------0----------0-------------1
Course2--------City1113----6---------------3----------1-------------2
Course2---country2--------12---------------6----------3-------------3
Course2-----state21-------12---------------6----------3-------------3
Course2------District211--10---------------5----------0-------------0
Course2--------City2111----0---------------0----------0-------------0
Course2--------City2112----1---------------0----------0-------------1
Course2--------City2113----6---------------3----------2-------------1
These are the Tables available to me.
(I have just given some examle data in tables, to get the idea)
"Groups" Table (This table gives the information of the group)
GROUPID-----NAME-------PARENTID
1---------Universe--------1
2---------country1--------1
3---------state11---------2
4---------District111-----3
5---------City1111--------4
6---------City1112--------4
7---------City1113--------4
8---------country2--------1
9---------state21---------8
10--------District211-----9
11--------City2111--------10
12--------City2112--------10
13--------City2113--------10
"Users" Table (This table provides the user information)
userID----FIRSTNAME---LASTNAME
user1-----------Jim-------Carry
user2-----------Tom-------lee
user3-----------sunny-----boo
user4-----------mary------mall
"User-Group" Tables (This table provides the relation between the groups
and the members)
GROUPID---userID
3-------------user1
3-------------user2
3-------------user4
4-------------user5
5-------------user6
5-------------user7
user_score (This table provides the user scores of different courses)
USERID----course-----STATUS
user1------course1-----complete
user1------course2-----NotStarted
user2------course1-----NotStarted
user2------course2-----complete
user3------course1-----complete
user3------course2-----InProgress
user4------course2-----complete
user4------course1-----NotStarted
I will explain the first four lines of the above result.
Course1---country1--------12---------------6----------4-------------2
Course1-----state11-------12---------------6----------4-------------2
Course1------District111--10---------------5----------3-------------2
Course1--------City1111----0---------------0----------0-------------0
Course1--------City1112----1---------------0----------0-------------1
Course1--------City1113----6---------------3----------2-------------1
# "city1111" group has 0 members
# "city1112" group has 1 member (1 member completed the course1)
# "city1113" group has 6 members(3 members notStarted,2 members
InProgress,1 member completed the course1)
# "District111" is the parent group of above three groups, and has 3
members.(2 members NotStarted,1 member InProgress the course1). But this
group has child groups, so the scores of this group has to rollup the
child groups scores also. Thats why it has 2+3+0+0=6 members Not
Started,1+2+0+0=3 members InProgress,0+0+1+1=2 members completed.
# "state11" group also same as the above group.
I am able to get the group hierarchy by using "Connect By" like follows
"select name,groupid,parentid from groups_info start with groupid=1 connect by parentid = prior groupid;"
But i want to get the result as i have mentioned in the begining of this discussion.
I am using oracle 8i (oracle8.1.7).
Thank you for any help
Srinivas MThis may not be exactly what you want,
but it should be fairly close:
SET LINESIZE 100
SET PAGESIZE 24
COLUMN groupname FORMAT A20
SELECT INITCAP (user_score.course) "course",
groupnames.name "groupname",
COUNT (*) "TotalMembers",
SUM (NVL (DECODE (UPPER (user_score.status), 'NOTSTARTED', 1), 0)) "NotStarted",
SUM (NVL (DECODE (UPPER (user_score.status), 'INPROGRESS', 1), 0)) "InProgress",
SUM (NVL (DECODE (UPPER (user_score.status), 'COMPLETE', 1), 0)) "Completed"
FROM user_score,
user_group,
(SELECT ROWNUM rn,
name,
groupid
FROM (SELECT LPAD (' ', 2 * LEVEL - 2) || name AS name,
groupid
FROM groups
START WITH groupid = 1
CONNECT BY PRIOR groupid = parentid)) groupnames
WHERE user_score.userid = user_group.userid
AND user_group.groupid IN
(SELECT groupid
FROM groups
START WITH groupid = groupnames.groupid
CONNECT BY PRIOR groupid = parentid)
GROUP BY user_score.course, groupnames.name, groupnames.rn
ORDER BY user_score.course, groupnames.rn
I entered the minimal test data that you
provided and a bit more and got this result
(It was formatted as you requested,
but I don't know if it will display properly
on this post, or wrap around):
course groupname TotalMembers NotStarted InProgress Completed
Course1 Universe 6 2 0 4
Course1 country1 5 2 0 3
Course1 state11 5 2 0 3
Course1 District111 2 0 0 2
Course1 City1112 1 0 0 1
Course1 City1113 1 0 0 1
Course1 country2 1 0 0 1
Course1 state21 1 0 0 1
Course1 District211 1 0 0 1
Course1 City2113 1 0 0 1
Course2 Universe 5 1 1 3
Course2 country1 4 1 1 2
Course2 state11 4 1 1 2
Course2 District111 1 0 1 0
Course2 City1113 1 0 1 0
Course2 country2 1 0 0 1
Course2 state21 1 0 0 1
Course2 District211 1 0 0 1
Course2 City2113 1 0 0 1
Here is the test data that I used, in case
anyone else wants to play with it:
create table groups
(groupid number,
name varchar2(15),
parentid number)
insert into groups
values (1,'Universe',null)
insert into groups
values (2,'country1',1)
insert into groups
values (3,'state11',2)
insert into groups
values (4,'District111',3)
insert into groups
values (5,'City1111',4)
insert into groups
values (6,'City1112',4)
insert into groups
values (7,'City1113',4)
insert into groups
values (8,'country2',1)
insert into groups
values (9,'state21',8)
insert into groups
values (10,'District211',9)
insert into groups
values (11,'City2111',10)
insert into groups
values (12,'City2112',10)
insert into groups
values (13,'City2113',10)
create table user_group
(groupid number,
userid varchar2(5))
insert into user_group
values (3,'user1')
insert into user_group
values (3,'user2')
insert into user_group
values (3,'user4')
insert into user_group
values (4,'user5')
insert into user_group
values (5,'user6')
insert into user_group
values (5,'user7')
insert into user_group
values (7,'user8')
insert into user_group
values (13,'user9')
insert into user_group
values (11,'use11')
insert into user_group
values (6,'use6')
create table user_score
(userid varchar2(5),
course varchar2(7),
status varchar2(10))
insert into user_score
values ('use6','course1','complete')
insert into user_score
values ('user9','course1','complete')
insert into user_score
values ('user9','course2','complete')
insert into user_score
values ('user8','course1','complete')
insert into user_score
values ('user8','course2','InProgress')
insert into user_score
values ('user1','course1','complete')
insert into user_score
values ('user1','course2','NotStarted')
insert into user_score
values ('user2','course1','NotStarted')
insert into user_score
values ('user2','course2','complete')
insert into user_score
values ('user3','course1','complete')
insert into user_score
values ('user3','course2','InProgress')
insert into user_score
values ('user4','course2','complete')
insert into user_score
values ('user4','course1','NotStarted') -
Help in query to get the max(date)
Hi I have query like below and based on the query I get the following results,
SELECT a.UsageId,a.product,ProductDate
FROM dbo.table1 a
JOIN dbo.table2 b ON a.SID= b.SID
JOIN dbo.table3 c ON b.CID = c.CID
UsageId Product UsageDate
1 Yellow 2014-01-01
2 Yellow 2014-01-02
3 Yellow 2014-01-03
4 Yellow 2014-01-04
5 Red 2014-01-01
6 Red 2014-01-02
7 Blue 2014-01-03
8 Blue
2014-01-04
Now I want to add a new column which gives me the Max(UsageDate) of the column Prdouct last Usage.
UsageId Product UsageDate Max(UsageDate)
1 Yellow
2014-01-01 2014-01-04
2 Yellow
2014-01-02 2014-01-04
3 Yellow
2014-01-03 2014-01-04
4 Yellow
2014-01-04 2014-01-04
5 Red 2014-01-01 2014-01-02
6 Red 2014-01-02 2014-01-02
7 Blue
2014-01-03 2014-01-04
8 Blue
2014-01-04 2014-01-04Simply use:
SELECT a.UsageId,a.product,ProductDate, MAX(ProductDate) OVER (PARTITION BY a.ProductID) as [Latest Product Usage Date]
FROM dbo.table1 a
JOIN dbo.table2 b ON a.SID= b.SID
JOIN dbo.table3 c ON b.CID = c.CID
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
SQL query to get the list of approvals
Hi,
Could someone let me know the SQL query to get the list of all the pending approvals for a user in OIM 11g R2.
ThanksThere are a few ways to do this:
- The easiest would be to use a Relationship Query from the CMC. To do this, go to the Universes section on the CMC, right click on the relevant universe, select tools >> Check Relationships.
- Use Query Builder. You will need more than one query to pull the information you need. You could try something like the below (for Webi)
SELECT SI_NAME, SI_WEBI, SI_DATACONNECTION FROM CI_APPOBJECTS
WHERE SI_KIND = 'universe' and SI_NAME = 'Universe Name'
This will give you a list of Webi Reports by SI_ID.
You'll need another query to list Webi report names:
SELECT SI_NAME FROM CI_INFOOBJECTS WHERE SI_ID IN (SI_ID from query above)
- This is trivial via Auditing / the Activity universe. This of course will only return reports that have already run.
Best.
Srinivas -
Needs Query to get the cycle time automatically based on the value provided in the UDF on OWOR table
Dear all,
Need a query to get the Cycle time in hr based on the value provide in the udf on OWOR table.
Details of UDF:-
1.Start date =10/07/14 (Field Name U_EA_REST)
2.Start time =10:00 (Field Name U_EA_REASTARTTIME)
3.End date =11/07/14 (Field Name U_EA_REET)
4.End Time=14:00 (Field Name U_EA_REAENDTIME
Cycle Time=_______ (Field Name U_EA_REACYCLETIME)
Regards,
BanugopanRajendranDear all,
Need a query to get the Cycle time in hr based on the value provide in the udf on OWOR table.
Details of UDF:-
1.Start date =10/07/14 (Field Name U_EA_REST) - Date Type
2.Start time =10:00 (Field Name U_EA_REASTARTTIME) - Hour Type
3.End date =11/07/14 (Field Name U_EA_REET) - Date Type
4.End Time=14:00 (Field Name U_EA_REAENDTIME - Hour Type
Cycle Time=_______ (Field Name U_EA_REACYCLETIME) - Hour Type
Regards,
BanugopanRajendran -
RQL Query to get the specific range of product items from product catalog.
Hi All,
I need to do the batch wise query to product catalog.
For that i have use Query builder but that is giving me repeated items, now i wanted to use RQL using rqlStatement.
Please help me in solving the issue.
Query which i have used using QueryBuilder.
RepositoryView productView = productRepo.getView("product");
QueryBuilder productBuilder = productView.getQueryBuilder();
Query productQuery = productBuilder.createUnconstrainedQuery();
RepositoryItems[] productItems = productView.executeQuery(productQuery,startIndex,endIndex);
Can anybody help me in writing RQL Query to get the specific range of product items from product catalog.Hi Shakuntala,
There is no executeQuery method defined in RqlStatement Interface, which will accept index for output result.
So As far as I know, what u are trying to achieve is not possible with RQL statements OOTB way.U can consider range of results based on some condition from Repository items.
Please let me know if u find any way to implement it.
Above Query builder should always return different ids if range is not overlapping with previous range.
Please verify that repeated items ids are same or different,
Quoting from API docs:
RepositoryItem[] executeQuery(Query pQuery,
int pStartingIndex,
int pEndingIndex)
throws RepositoryException
Executes the given query and returns an array of matching RepositoryItems, which are contained within a total potential result set. For example used if one wanted to retrieve elements 50-60 from a query which could return 100 elements.
Regards,
Nitin. -
Query to get the windows-user(os)
Hallo,
I have a windows operating system and on this system is oracle database with the
spatial-option installed. Now I wanna create a trigger which writes in a table if
a geometry is updated. In this table I wanna write the new geometry, the time of
the update and the windows-user that logged on the windows operating system. I
don't wanna know the database user.
What is the sql-query to get the windows-user?
Thanks KatrinAs an alternative, use the SYS_CONTEXT function to get some of this info.
oracle@fuzzy:~> sqlplus test/test@XE
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Jan 2 16:32:53 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> select sys_context('USERENV', 'HOST') Host,
2 sys_context('USERENV', 'IP_ADDRESS') IP,
3 sys_context('USERENV', 'OS_USER') OS_User,
4 sys_context('USERENV', 'AUTHENTICATED_IDENTITY') Identity
5 from dual;
HOST IP OS_USER IDENTITY
fuzzy 127.0.0.2 oracle test
SQL> More info at http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/functions165.htm#i1038176
Maybe you are looking for
-
Change from windows 8 single language to windows 8.1
hello, i just bought a new laptop a Samsung laptop to be specific and it came with windows 8 single language activated but i cant see the update to windows 8.1 i need help! please
-
Hi, I have to move my data from my program to a flat file on the Application/ Presentation Server. Now i need to validate whether the path provided by user is a valid one or not. For eg. If the User enter \usr\sap\ in the presentation server path. Th
-
Mac mail not working after OS 10.9.5 update
I have the same problem as other users. Since last update of the OS to 10.9.5, the MAIL app does not send email. It just does a few times a day, on and off. I tried to take all accounts offline and then take all accounts online again, so many times,
-
How can i add subtitles on tv shows bought on itunes ?
thanks for your help !
-
Tab control Output value to be display in other pages
Hi guys I hava a VI using a tab control with multiple pages. The 1st page will have some calculation and give an ouput ,x. Then i will proceed to the 2nd page to perform other action, however i need the input automatically from what i have acquired i