SQL query to correct the corrupted data
Hi All,
I got strucked up with a query correcting the corrupted records.
CREATE TABLE EX1
EMPID INTEGER,
DW_EFF_DT DATE,
DW_EXPR_DT DATE
INSERT INTO EX1 VALUES(1,'04-MAR-1998','13-MAR-1999');
INSERT INTO EX1 VALUES(1,'14-MAR-1999','02-MAY-2000');
INSERT INTO EX1 VALUES(1,'03-MAY-2000','01-MAY-2013');
INSERT INTO EX1 VALUES(1,'02-MAY-2013','31-DEC-9999');
I have empid with other attributes,we are maintaing history.There is some data which is corrupted and we need to correct it.
DW_EFF_DT which is less than '01-FEB-2005' should be made by default '31-JAN-2005'
Again the data should be corrected and my output should be like the below
EMPNO DW_EFF_DT DW_EXPR_DT
1 2005-01-27 2005-01-28
1 2005-01-29 2005-01-30
1 2005-01-31 2013-05-01
1 2013-05-02 9999-12-31
I used the lead and lag function,but it is applied sequentially.
How I can get the dates subtratcing by 1 for each and every alternative row.
I tried the below query and able to achive half of it.
SELECT A.* ,COALESCE(LEAD(NEW_DW_EFF,1) OVER(ORDER BY NEW_DW_EFF) -1,TO_DATE('31-DEC-9999','DD-MON-YYYY')) AS NEW_DW_EXPR_DT
FROM
SELECT ID,
DW_EFF_DT,
DW_EXPR_DT,
CASE WHEN DW_EFF_DT<TO_DATE('01-FEB-2005','DD-MON-YYYY') THEN TO_DATE('31-JAN-2005','DD-MON-YYYY') ELSE DW_EFF_DT END AS NEW_DW_EFF
FROM EX1
)A
ID DW_EFF_DT DW_EXPR_DT NEW_DW_EFF NEW_DW_EXPR_DT
1 04-MAR-98 13-MAR-99 31-JAN-05 30-JAN-05
1 14-MAR-99 02-MAY-00 31-JAN-05 30-JAN-05
1 03-MAY-00 01-MAY-13 31-JAN-05 01-MAY-13
1 02-MAY-13 31-DEC-99 02-MAY-13 31-DEC-99
Please help me in this regard.i am still trying it.
Thanks in advance,
KVB
KVB wrote:
EMPNO DW_EFF_DT DW_EXPR_DT
1 2005-01-27 2005-01-28
1 2005-01-29 2005-01-30
1 2005-01-31 2013-05-01
1 2013-05-02 9999-12-31
Actually the last record is the active record.
Th 3rd record effectiuve date is adjusted because the dateis less than 2005-02-01. So that we adjusted to 2005-01-31,
The 2nd record expiry date will be adjusted to 3rd record effective date-1,
Now the 2nd record effective will be adjusted to 2nd record expiry date-1 and so on..until the first record.
Actually I could not explain much better in business point of view like why they do this.Technically we need to achive this through SQL.
CheersOkay, that makes more sense, thanks :)
Probably not the prettiest ... but should work (you may need to tweak it a bit)
ME_TUBBZ? select
2 empid
3 , to_date('2005-02-01','yyyy-mm-dd') - ( 2* rn) + 1 as new_eff_date
4 , case
5 when rn = 1
6 then
7 dw_expr_dt
8 else
9 to_date('2005-02-01','yyyy-mm-dd') - (2 * (rn - 1))
10 end
11 as new_exp_date
12 , dw_eff_dt
13 , dw_expr_dt
14 from
15 (
16 select
17 empid
18 , dw_eff_dt
19 , dw_expr_dt
20 , row_number() over (partition by empid order by dw_eff_dt desc) as rn
21 from ex1
22 where dw_eff_dt < to_date('2005-02-01','yyyy-mm-dd')
23 )
24 order by dw_eff_dt asc
25 /
EMPID NEW_EFF_DATE NEW_EXP_DATE DW_EFF_DT DW_EXPR_DT
1 27-JAN-2005 00 00:00 28-JAN-2005 00 00:00 04-MAR-1998 00 00:00 13-MAR-1999 00 00:00
1 29-JAN-2005 00 00:00 30-JAN-2005 00 00:00 14-MAR-1999 00 00:00 02-MAY-2000 00 00:00
1 31-JAN-2005 00 00:00 01-MAY-2013 00 00:00 03-MAY-2000 00 00:00 01-MAY-2013 00 00:00
3 rows selected.
Elapsed: 00:00:00.01
ME_TUBBZ? Cheers,
Similar Messages
-
Sql query to indetify the identical data
Hi
I would like to know the query to identify the identical data in same table.
Example: I have table called 'AA" having same data for load_ctry i.e. 'MY' and 'HK' ,I need sql query to indetify the identical data for above countries in that table.
Thanks
MRHi,
Table called "AA" with columns col1,col2,col3,load_ctry with following sample date
col1 col2 col3 load_ctry
3 bg xx TH
4 op xc TH
3 bg xx MY
4 op xc MY
3 vb nb MY
When query ,if data is identical for both countries ,no data to fecth or data identical .If data is differ ,it will return the mismatching data becuase we are using same table for both countries .
Thanks
MR -
Sql query to find the scheduled date
I schedule a job for last Thursday of every month. Based on my current date and time I need the date of my next scheduled run of the job...
(i.e) If today is 28-march-2012 (Wednesday) my query should return 3/29/12(which is the last thursday of the month)
If today is 30-march-2012 (Friday) my query should return 4/26/12 (which is the last thursday of next month)
If today is 29-march-2012 and time is 11:00 AM and i have scheduled a job to run at 12:00 PM of last thursday of every month then my query should return 3/29/12
If today is 29-march-2012 and time is 1:00 PM then my query should return 4/26/12924163 wrote:
I schedule a job for last Thursday of every month. Based on my current date and time I need the date of my next scheduled run of the job...
(i.e) If today is 28-march-2012 (Wednesday) my query should return 3/29/12(which is the last thursday of the month)
If today is 30-march-2012 (Friday) my query should return 4/26/12 (which is the last thursday of next month)
If today is 29-march-2012 and time is 11:00 AM and i have scheduled a job to run at 12:00 PM of last thursday of every month then my query should return 3/29/12
If today is 29-march-2012 and time is 1:00 PM then my query should return 4/26/12may be
SQL> ed
Wrote file afiedt.buf
1 with tmp as
2 (
3 select to_date('28-march-2012','DD-month-YYYY') dt from dual union all
4 select to_date('29-march-2012 11:00:00 AM','DD-month-YYYY HH:MI:SS AM') dt from dual union all
5 select to_date('29-march-2012 1:00:00 PM','DD-month-YYYY HH:MI:SS AM') dt from dual union all
6 select to_date('29-march-2012 12:00:00 PM','DD-month-YYYY HH:MI:SS AM') dt from dual union all
7 select to_date('29-march-2012 11:59:00 AM','DD-month-YYYY HH:MI:SS AM') dt from dual union all
8 select to_date('30-march,2012','DD-month-YYYY') dt from dual
9 )
10 select dt,
11 case
12 when Next_day(Add_months(Trunc(dt, 'MM'), 1) - 7, 'thursday') + ( 12 /
13 24 ) >
14 dt then Next_day(Add_months(Trunc(dt, 'MM'), 1) - 7, 'thursday')
15 else Next_day(Add_months(Trunc(dt, 'MM'), 2) - 7, 'thursday')
16 end new_dat
17 from tmp
18* order by dt
SQL> /
DT NEW_DAT
28-Mar-2012 12:00:00 AM 29-Mar-2012 12:00:00 AM
29-Mar-2012 11:00:00 AM 29-Mar-2012 12:00:00 AM
29-Mar-2012 11:59:00 AM 29-Mar-2012 12:00:00 AM
29-Mar-2012 12:00:00 PM 26-Apr-2012 12:00:00 AM
29-Mar-2012 01:00:00 PM 26-Apr-2012 12:00:00 AM
30-Mar-2012 12:00:00 AM 26-Apr-2012 12:00:00 AM
6 rows selected.
SQL> -
Give me the sql query which calculte the table size in oracle 10g ecc 6.0
Hi expert,
Please give me the sql query which calculte the table size in oracle 10g ecc 6.0.
RegardsOrkun Gedik wrote:
select segment_name, sum(bytes)/(1024*1024) from dba_segments where segment_name = '<TABLE_NAME>' group by segment_name;
Hi,
This delivers possibly wrong data in MCOD installations.
Depending on Oracle Version and Patchlevel dba_segments does not always have the correct data,
at any time esp. for indexes right after being rebuild parallel (Even in DB02 because it is using USER_SEGMENTS).
Takes a day to get the data back in line (never found out, who did the correction at night, could be RSCOLL00 ?).
Use above statement with "OWNER = " in WHERE for MCOD or connect as schema owner and use USER_SEGMENTS.
Use with
segment_name LIKE '<TABLE_NAME>%'
if you like to see the related indexes as well.
For partitioned objects, a join from dba_tables / dba_indexes to dba_tab_partitions/dba_ind_partitions to dba_segments
might be needed, esp. for hash partitioned tables, depending on how they have been created ( partition names SYS_xxxx).
Volker -
How to use Add Query Criteria for the MySQL data Base in Netbeans ?
How to use Add Query Criteria for the MySQL data Base in Netbeans Visual web pack.
When the Query Criteria is add like
SELECT ALL counselors.counselors_id, counselors.first_name, counselors.telephone,counselors.email
FROM counselors WHERE counselors.counselors_id = ?
when i run this Query in the Query Window
i get a error message Box saying
Query Processing Error Parameter metadata not available for the given statement
if i run the Query with out Query Criteria its working fine.*I am glad I am not the only one who have this problem. Part of issue has been described as above, there are something more in my case.
Whenever I try to call ****_tabRowSet.setObject(1, userDropList.getSeleted()); I got error message as shown below:*
The Java codes are:
public void dropDown1_processValueChange(ValueChangeEvent event) {
Object s = this.dropDown1.getSelected();
try {
this.User_tabDataProvider1.setCursorRow(this.User_tabDataProvider1.findFirst("User_Tab.User_ID", s));
this.getSessionBean1().getTrip_tabRowSet1().setObject(1, s);
this.Trip_tabDataProvider1.refresh();
} catch (Exception e) {
this.log("Error: ", e);
this.error("Error: Cannot select user"+e.getMessage());
SQL statement for Trip_tabRowSet:
SELECT ALL Trip_Tab.Trip_Date,
Trip_Tab.User_ID,
Trip_Tab.Destination
FROM Trip_Tab
WHERE Trip_Tab.User_ID = ?
Error messages are shown below:
phase(RENDER_RESPONSE 6,com.sun.faces.context.FacesContextImpl@5abf3f) threw exception: com.sun.rave.web.ui.appbase.ApplicationException: java.sql.SQLException: No value specified for parameter 1 java.sql.SQLException: No value specified for parameter 1
com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.cleanup(ViewHandlerImpl.java:559)
com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.afterPhase(ViewHandlerImpl.java:435)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:274)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
com.sun.webui.jsf.util.UploadFilter.doFilter(UploadFilter.java:240)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:216)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:216)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:276)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)
com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
tandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
java.sql.SQLException: No value specified for parameter 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:1674)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:1622)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1332)
at com.sun.sql.rowset.internal.CachedRowSetXReader.readData(CachedRowSetXReader.java:193)
at com.sun.sql.rowset.CachedRowSetXImpl.execute(CachedRowSetXImpl.java:979)
at com.sun.sql.rowset.CachedRowSetXImpl.execute(CachedRowSetXImpl.java:1439)
at com.sun.data.provider.impl.CachedRowSetDataProvider.checkExecute(CachedRowSetDataProvider.java:1274)
at com.sun.data.provider.impl.CachedRowSetDataProvider.setCursorRow(CachedRowSetDataProvider.java:335)
at com.sun.data.provider.impl.CachedRowSetDataProvider.setCursorIndex(CachedRowSetDataProvider.java:306)
at com.sun.data.provider.impl.CachedRowSetDataProvider.getRowCount(CachedRowSetDataProvider.java:639)
at com.sun.webui.jsf.component.TableRowGroup.getRowKeys(TableRowGroup.java:1236)
at com.sun.webui.jsf.component.TableRowGroup.getFilteredRowKeys(TableRowGroup.java:820)
at com.sun.webui.jsf.component.TableRowGroup.getRowCount(TableRowGroup.java:1179)
at com.sun.webui.jsf.component.Table.getRowCount(Table.java:831)
at com.sun.webui.jsf.renderkit.html.TableRenderer.renderTitle(TableRenderer.java:420)
at com.sun.webui.jsf.renderkit.html.TableRenderer.encodeBegin(TableRenderer.java:143)
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:810)
at com.sun.webui.jsf.component.Table.encodeBegin(Table.java:1280)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:881)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:889)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:889)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:889)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:889)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:889)
at com.sun.faces.application.ViewHandlerImpl.doRenderView(ViewHandlerImpl.java:271)
at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:182)
at com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.renderView(ViewHandlerImpl.java:285)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:133)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:244)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
at com.sun.webui.jsf.util.UploadFilter.doFilter(UploadFilter.java:240)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:216)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:216)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:276)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
Also when I tried to update my MYSQL connector / J driver to version 5.1.5 from 5.0.5 (NB 5.5.1) and 5.0.7 (NB 6.1), I could not get it work (looooong time to search some JDBC classes and with no response in the end) on both of my Netbean 5.5.1(on PC) and Netbean 6.1(on laptop) IDEs.
Could anybody look into this issue.
Many thanks
Edited by: linqing on Nov 22, 2007 4:48 AM -
SQL Query to get the # of files in folders in a library
Anyone has the SQL query to list the number of files in each folders in a SharePoint library?
Technically it's a grey area of support as MS don't mind you doing it but won't help you if you encounter problems, the script is much better though.
Scratch that, the script isn't that good. It's using .items which won't work on large lists and is slow. The version below is untested but should be significantly faster and work on large lists.
$starttime = Get-Date
#Creating new site object
$siteurl = Read-Host "Enter the name of your site and press enter"
$site = New-Object Microsoft.SharePoint.SPSite($siteurl)
#Assigning all webs (sites) to $webs
$webs = $site.Allwebs
#System Libraries defined so they won't be touched##
$systemlibs =@("Converted Forms", "Customized Reports", "Documents", "Form Templates",
"Images", "List Template Gallery", "Master Page Gallery", "Pages",
"Reporting Templates", "Site Assets", "Site Collection Documents",
"Site Collection Images", "Site Pages", "Solution Gallery",
"Style Library", "Theme Gallery", "Web Part Gallery", "wfpub")
Write-Host "Total number of webs that will be traversed: " $webs.count
$DocLibsCount = 0
$DocLibwItems = 0
$totalitems = 0
$subfolderitems = 0
foreach($web in $webs)
$listcoll = $web.lists
foreach($list in $listcoll)
if($list -eq $null)
Write-Host
else
$base = $list.GetType()
if($base.name -eq "SPDocumentLibrary")
if ($systemlibs -contains $list)
{ continue}
else
$DocLibsCount += 1
$totalitems += $List.itemcount
$name = $list.Title
$folders = $web.GetFolder($name).SubFolders
for($etr = 0;$etr -lt $folders.count; $etr++)
if($folders[$etr].Name -ne "Forms")
Write-Host "Processing SubFolder ItemCount" -ForegroundColor Red
$tempcount = $folders[$etr].ItemCount
$subfolderitems += $tempcount
Write-Host
Write-Host
Write-Host "Total # of Document Libraries: " $DocLibsCount -ForegroundColor Green
Write-Host "Total # of Document Libraries that contain items: " $DocLibwItems -ForegroundColor Green
Write-Host "Total # of items: " $totalitems -ForegroundColor Green
Write-Host "Total # of items in DocLib\Subfolders: " $subfolderitems -ForegroundColor Green
$finishtime = Get-Date
Write-Host
Write-Host “Script Duration” –ForegroundColor Yellow
Write-Host “Started: “ $starttime –ForegroundColor Yellow
Write-Host “Finished: “ $finishtime –ForegroundColor Yellow
Stop-SPAssignment -Global -
Can I get a query to get the output data like 4th column instead of 3rd col
Can I get a query to get the output data like 4th column instead of 3rd column ?
SQL> select emp.deptno, empno, rownum from emp, dept where emp.deptno=dept.deptno;
DEPTNO EMPNO ROWNUM
10 7782 *1* *1*
10 7839 *2* *2*
10 7934 *3* *3*
20 7369 *4* *1*
20 7876 *5* *2*
20 7902 *6* *3*
20 7788 *7* *4*
20 7566 *8* *5*
30 7499 *9* *1*
30 7698 *10* *2*
30 7654 *11* *3*
30 7900 *12* *4*
30 7844 *13* *5*
30 7521 *14* *6*
14 rows selected.SQL> select emp.deptno, emp.empno,
2 row_number() over(order by emp.deptno, emp.empno) rn,
3 row_number() over(partition by emp.deptno order by emp.empno) dept_rn
4 from emp, dept
5 where emp.deptno=dept.deptno
6 order by emp.deptno, emp.empno;
DEPTNO EMPNO RN DEPT_RN
10 7782 1 1
10 7839 2 2
10 7934 3 3
20 7369 4 1
20 7566 5 2
20 7788 6 3
20 7876 7 4
20 7902 8 5
30 7499 9 1
30 7521 10 2
30 7654 11 3
30 7698 12 4
30 7844 13 5
30 7900 14 6
14 rows selected.Regards,
Dima -
Dear All,
I have a requirement, to write a SQL query to populate the records which are inserted less than 10 no of records.
The tables has the cretaed_date column and along with other key column which will have unique values.
Ex1: The user might have inserted records from application, per week basis, between the date range '01-jun-2013' - 08-jun-2013 , the no of records created by the user during this week may be less than 10 records or more.
But I want to populate the records by giving date range that too, it should pick the records the count which fall with in 10 records.
I dont want the query to populate the records if the user has inserted more than 10 records in a week.
Ex2:
User 1 has created 15 records during the week 1 ( the query should not populate this ).
User 2: has cretaed less than 10 records from the UI during the week 2. ( This details should get populated ).
ThanksUse COUNT to find how many rows where inserted in a week.
If this does not answer your question then please read Re: 2. How do I ask a question on the forums? And provide necessary details. -
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 Select The 5th Element
In the report I am currently working on, I am using an Add Command custom SQL query to pull the data that I need. The structure is a Call and a list of associated Activities. In this particular scenario, there are 8 activity notes for a type of call and I want to return the 5th one. The activity notes are a specific sequence of captured actions and I need the note from the 5th step in the sequence.
This is what I have come up with:
SELECT CALL.call_id,
(select top 1 from (select top 5 CONVERT(char(8000),ACTIVITY.activity_note) from ACTIVITY
where CALL.call_id = ACTIVITY.call_id
order by ACTIVITY.creat_date desc))
as activity_tx
FROM CALL
The intent of the Top 5 was to get the first 5 activity notes, of which the 5th note would be the last, then reverse sort them so I could take the Top 1 (which would be the 5th of 8). But I am getting a vague syntax error between "from" and "order by". Any suggestions would be appreciated.
Thanks!
Fuskie
Who thought he had a solution but is flummoxed he can't bring it home...Hello,
Let me explain that Crystal assumes the user knows how to write SQL. We only report on the data provided by the SQL you write.
I did a quick search using Microsofts new search engine - www.bing.com and it returned this as well as lots more:
http://forums.devshed.com/php-development-5/how-to-access-a-certain-element-in-the-results-of-606217.html
Try searching in MSSQL's site also for more info on how to get the results you are looking for.
Thank you
Don -
Can we change/Modify BI server generated Sql query and run to fetch data
Hi,
My client is saying that there is an option to modify bi server generated sql query to fetch data from source.
question:As a request is made in presentation services, A dynamic sql query is generated and fetches data from source. all this is loggedin Nqlquery log..well can we change/modify the sql query generated and run modified sql query to fetch data from source. ., if so how? if not why?
Thanks in advance
Edited by: user10794468 on Jun 16, 2009 6:29 PM
Edited by: user10794468 on Aug 12, 2009 6:58 PMThank you so much for your reply..
..Can we also modify sql query generated by bi server to fetech data. the query's which we see in query log file.. -
I purchased iPhone 5S and opened new Apple account with preffered language English and location UAE. I was directed to enter my birth date with only Arabic language option. There was no way to change the language or skip the step. I had to enter an arbitrary birth date to go to the next step. How to correct the birth date now and change the numerals to English?
Solution!!
I was finally able to get the installer build to work, even though it takes about ten minutes!! The network and CPU activity is minimal, so I don't know what LV is waiting on during all this time?
For this installation it appears to be related to the directory structure created by the Volume License Manager 2.1 software. There are two sets of users at my company, LabVIEW Professional and Developer Suite, which have different license numbers and installers. The errors were related to source files located in the Products folder of the network distribution. My installation expected the Products folder to be in a different location that it was actually placed by the VLM software. I copied the entire Products folder from _SourceFiles up to the LabVIEW 8.5.1 folder and now it works, although very slowly.
LabVIEW 8.5.1
-->_SourceFiles
-->Bin
-->Device Drivers
-->Licenses
-->Products (original location)
-->Signal Express
-->Dev Suite
-->LV Pro
-->Products (manual copy)
I hope this information may be of use to NI or other users.
Message Edited by jrjones on 08-12-2008 03:21 PM
Message Edited by jrjones on 08-12-2008 03:23 PM -
SQL query to list the "Administrative category" field for all applications
yesterday i started a thread to list the "Optional reference" field for all cm applications in a SSRS report. I've got the query with the help of Torsten.
https://social.technet.microsoft.com/Forums/en-US/00419e6e-e3c2-4b80-b6af-2a24ced1032d/sql-query-to-list-the-optional-reference-field-of-all-packages-in-cm-2012?forum=configmanagersdk
But again today, i'm looking for a way to get "Administrative category" field in a SSRS report. Could someone point me to the right direction ?
Kindly mark as answer/Vote as helpful if a reply from anybody helped you in this forum. DelphinHi,
You could monitor the SMSProv.log when you check the category of an application. It shows that SQL query the SCCM provider used is related to function fn_ListCategoryInstances.
Best Regards,
Joyce -
Sql query to achive the running division
Hi all, plz help me out with the sql query to achive the below output
create table emp_a (empno number, deptno number, sal number)
insert into emp_a values(901, 10,100);
insert into emp_a values(902, 10,400);
insert into emp_a values(901, 20,300);
insert into emp_a values(902, 20,2100);
i want the ouput in below format
empno deptno sal div_sal
901 10 100 (300/100)
901 20 300 (300/100)
902 10 400 (2100/400)
902 20 2100 (2100/400)
the div_sal column should have the output of greatest sal/second smallest sal for each empnoHi,
781649 wrote:
Hi all, plz help me out with the sql query to achive the below output
create table emp_a (empno number, deptno number, sal number)
insert into emp_a values(901, 10,100);
insert into emp_a values(902, 10,400);
insert into emp_a values(901, 20,300);
insert into emp_a values(902, 20,2100);
i want the ouput in below format
empno deptno sal div_sal
901 10 100 (300/100)
901 20 300 (300/100)
902 10 400 (2100/400)
902 20 2100 (2100/400)
the div_sal column should have the output of greatest sal/second smallest sal for each empnofor empno=901, then second smallest sal is 300. For empno=902, the second smallest sal is 2100.
Instead of "second *smallest* ", do you mean "second *greatest* "?
What if there's a tie (e.g.
INSERT INTO emp_a (empno, deptno, sal) VALUES (903, 10, 300);
INSERT INTO emp_a (empno, deptno, sal) VALUES (903, 20, 300);
INSERT INTO emp_a (empno, deptno, sal) VALUES (903, 30, 200);) Would you count 200 or 300 as the second greatest?
Here's one way:
WITH got_r_num AS
SELECT empno, deptno, sal
, ROW_NUMBER () OVER ( PARTITION BY empno
ORDER BY sal DESC
) AS r_num
FROM emp_a
SELECT e.empno
, e.deptno
, e.sal
, '(' || TO_CHAR (r1.sal)
|| '/'
|| TO_CHAR (r2.sal)
|| ')' AS div_sal
FROM emp_a e
JOIN got_r_num r1 ON e.empno = r1.empno
JOIN got_r_num r2 ON e.empno = r2.empno
WHERE r1.r_num = 1
AND r2.r_num = 2
; -
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
Maybe you are looking for
-
Hi - I am the proud new owner of a 80GB ipod and i have also purchased the AV connection kit so that i can use the ipod with my tv and home sound system. In the kit are several docks stations but none say that they are compatable with the 80GB model
-
Powerbook G4 12 " display is low res and faint
Dear Gurus of such things, My Powerbook G4 12" display goes into some kind of low res and faint display after restarting. After days of this, it will suddenly become high res and clear again, for no reason that I can tell. It also recovers after my P
-
Download list of payment terms
All SAP Gurus, We want to Download list of payment terms. From SPRO path it gives the payment terms, one after another, but not the list. From where we can get the list of all payment terms. Regards,
-
Error Transporting Transformation
SDNer's I have trouble transporting the transformations of my Master data attributes in BI 7.0.I get the following: Start of the after-import method RS_TRFN_AFTER_IMPORT for object type(s) TRFN (Activation Mode) Transformation 03EUQA9DYRRUIO54K5
-
Hello. The company website I use has moved to a new server. The new server required some changes apparently, and now I am receiving the message CompanyXYZ.net:987 uses an invalid security certificate. The certificate is not trusted because it is self