Merge two query results
Is it possible to merge 2 query results?
I have a function that returns a querey result.
< CFSET temp = query1>
<CFSET FNCTransfers = temp>
Now I want to change the query to return a merged query
result
< CFSET temp = query1>
<CFSET temp2 = query2>
Is it possible to merge the two results?
Some thing like this (I know that it cannot be done like
this)
<CFSET FNCTransfers = temp1 & temp2>
Maby it should be a union and query of query?
UNION could be the way to go. the query results will have to
match up
between the 2 queries (field data types need to match for
both queries)
<cfquery name="qryMergedQueries" dbtype="query">
SELECT * FROM query1
UNION
SELECT * FROM query2
</cfquery>
kruse wrote:
> Is it possible to merge 2 query results?
>
> I have a function that returns a querey result.
>
> < CFSET temp = query1>
> <CFSET FNCTransfers = temp>
>
> Now I want to change the query to return a merged query
result
>
> < CFSET temp = query1>
> <CFSET temp2 = query2>
>
> Is it possible to merge the two results?
>
> Some thing like this (I know that it cannot be done like
this)
> <CFSET FNCTransfers = temp1 & temp2>
>
> Maby it should be a union and query of query?
>
Similar Messages
-
Merging two Queires result into one.
I have to get two different result on the same table.First Result will be get first then added by Second result
SELECT distinct cust.custid,cust.firstnm,cust.nextactiondt,cust.priorityscr,cust.lastacssts FROM Customer cust, Custqueue custqueue
WHERE cust.custid=custqueue.custid AND custqueue.qcd = 'A'
AND trunc(cust.nextactiondt)>=trunc(current_date) AND trunc(cust.lastacssts)<trunc(current_date)
ORDER BY cust.nextactiondt,cust.priorityscr desc
Custid Name Nextactiondt priorityscr lastacssts
*65 A 16-JUN-11 11.52 14-MAR-11*
*84 B 16-JUN-11 1.38 14-MAR-11*
*93 C 17-JUN-11 0 18-APR-11*
SELECT distinct cust.custid,cust.firstnm,cust.nextactiondt,cust.priorityscr,cust.lastacssts FROM Customer cust, Custqueue custqueue
WHERE cust.custid=custqueue.custid AND custqueue.qcd = 'A'
AND trunc(cust.nextactiondt)>=trunc(current_date) AND trunc(cust.lastacssts)=trunc(current_date)
ORDER BY cust.lastacssts,cust.nextactiondt,cust.priorityscr desc
Custid Name Nextactiondt priorityscr lastacssts
*59 S 16-JUN-11 1212 16-JUN-11*
I want to club the result of the two query into 1 as follows.
Custid Name Nextactiondt priorityscr lastacssts
*65 A 16-JUN-11 11.52 14-MAR-11*
*84 B 16-JUN-11 1.38 14-MAR-11*
*93 C 17-JUN-11 0 18-APR-11*
*59 S 16-JUN-11 1212 16-JUN-11*
but when i am using UNION
SELECT distinct cust.custid,cust.firstnm,cust.nextactiondt,cust.priorityscr,cust.lastacssts FROM Customer cust, Custqueue custqueue
WHERE cust.custid=custqueue.custid AND custqueue.qcd = 'A'
AND trunc(cust.nextactiondt)>=trunc(current_date) AND trunc(cust.lastacssts)<trunc(current_date)
UNION
SELECT distinct cust.custid,cust.firstnm,cust.nextactiondt,cust.priorityscr,cust.lastacssts FROM Customer cust, Custqueue custqueue
WHERE cust.custid=custqueue.custid AND custqueue.qcd = 'A'
AND trunc(cust.nextactiondt)>=trunc(current_date) AND trunc(cust.lastacssts)=trunc(current_date)
ORDER by 3,4 desc,5
I am getting
Custid Name Nextactiondt priorityscr lastacssts
*59 S 16-JUN-11 1212 16-JUN-11*
*65 A 16-JUN-11 11.52 14-MAR-11*
*84 B 16-JUN-11 1.38 14-MAR-11*
*93 C 17-JUN-11 0 18-APR-11*
but that is different from what i expect
Custid Name Nextactiondt priorityscr lastacssts
*65 A 16-JUN-11 11.52 14-MAR-11*
*84 B 16-JUN-11 1.38 14-MAR-11*
*93 C 17-JUN-11 0 18-APR-11*
*59 S 16-JUN-11 1212 16-JUN-11*
so any one know how can i append the results of two queries into one since i have order by clause in both queries and i can club them together.
Any help regarding this would be appreciatedLook at the following example:
SQL> select * from emp
2 where deptno=10
3 order by job;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7934 MILLER CLERK 7782 23-JAN-82 1300 10
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7839 KING PRESIDENT 17-NOV-81 5000 10
SQL> select * from emp
2 where deptno=20
3 order by ename;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7566 JONES MANAGER 7839 02-APR-81 2975 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7369 SMITH CLERK 7902 17-DEC-80 800 20
SQL> with q1 as (
2 select * from emp
3 where deptno=10
4 order by job),
5 q2 as (
6 select * from emp
7 where deptno=20
8 order by ename
9 )
10 select * from q1
11 union all
12 select * from q2;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7934 MILLER CLERK 7782 23-JAN-82 1300 10
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7839 KING PRESIDENT 17-NOV-81 5000 10
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7566 JONES MANAGER 7839 02-APR-81 2975 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7369 SMITH CLERK 7902 17-DEC-80 800 20
8 rows selected.Max -
Combine two Query Results with Rank
Dear All,
I am business analyst working DB for first time:
I have two queries:
1)
select * from (select "CAFNo","ActionDate","ActionDetail", rank() over (partition by "CAFNo" order by "ActionDate") rnk,
from "ABC"
where "ActionDetail"
like 'CRF successfully submitted and routed to Fulfillment Team%')
where rnk=1
Results in
CAFNo","ActionDate1","ActionDetail"
2)
select * from (select "CAFNo","ActionDate","ActionDetail", rank() over (partition by "CAFNo" order by "ActionDate") rnk
from "ABC"
where "ActionDetail"
like '%Customer ID%')
where rnk=1
Results in
CAFNo","ActionDate2","ActionDetail"
I would like to combine results of two as:
CAF no, Actiondate1, actiondate2,ActionDetail
I tried full outer join and other options but with no success. Please help
Please share concept of joining the two results not the actual query.Actually, my query is not equivalent to original. I missed ActionDetail can be something like:
'CRF successfully submitted and routed to Fulfillment Team A by Customer ID X'Then it fits both LIKE conditions. If such case of ActionDetail is possible then:
with t as (
select *
from (
select 1 weight,
"CAFNo",
"ActionDate",
"ActionDetail",
rank() over (partition by "CAFNo" order by "ActionDate") rnk
from "ABC"
where "ActionDetail" like 'CRF successfully submitted and routed to Fulfillment Team%'
where rnk=1
union all
select *
from (
select 2 weight,
"CAFNo",
"ActionDate",
"ActionDetail",
rank() over(partition by "CAFNo" order by "ActionDate") rnk
from "ABC"
where "ActionDetail" like '%Customer ID%'
where rnk=1
select "CAFNo",
max(
case weight
when 1 then "ActionDate"
end
) "ActionDate1",
max(
case weight
when 2 then "ActionDate"
end
) "ActionDate2",
max(
case weight
when 1 then "ActionDetail"
end
) "ActionDetail1",
max(
case weight
when 2 then "ActionDetail"
end
) "ActionDetail2"
from t
group by "CAFNo"
/SY. -
How to remove duplicates while joining two query results ?
Hi all,
Please, anyone suggest me how to do below one.. i am using oracle version 11.2.0.3.0
Col_1 Col_2
111 AAA
AAA 111
222 BBB
333 CCC
As, oracle point of view the above table contains distinct rows. But i need the logic result like below,
Col_1 Col_2
111 AAA
222 BBB
333 CCCAnd if columns are NULLable:
with sample_table as (
select '111' col1,'AAA' col2 from dual union all
select 'AAA','111' from dual union all
select '222','BBB' from dual union all
select '333','CCC' from dual union all
select '444',to_char(null) from dual union all
select to_char(null),'444' from dual union all
select to_char(null),to_char(null) from dual union all
select to_char(null),to_char(null) from dual
select least(col1,col2) col1,
case
when col1 is null then col2
when col2 is null then col1
else greatest(col1,col2)
end
from sample_table s
group by least(col1,col2),
case
when col1 is null then col2
when col2 is null then col1
else greatest(col1,col2)
end
order by least(s.col1,s.col2),
case
when s.col1 is null then s.col2
when s.col2 is null then s.col1
else greatest(s.col1,s.col2)
end
COL CAS
111 AAA
222 BBB
333 CCC
444
SQL> SY. -
Merging two complemental result sets... or OUTER JOINs not working?
Dear experts!
Again I have a very difficult problem for which I ask Your help, but this time I am better prepared than last time and can deliver sample data of my (hopefully not too much) simplified example:
create table Subjects(
pk_id number not null primary key,
title varchar2(128)
create table People(
pk_id number not null primary key,
name varchar2(128)
create table Results(
pk_id number not null primary key,
fk_subjects_id number,
fk_people_id number,
result number
insert into Subjects(pk_id, title) values (1, 'Choosing a recipe')
insert into Subjects(pk_id, title) values (2, 'Shopping ingredients')
insert into Subjects(pk_id, title) values (3, 'Preparations')
insert into Subjects(pk_id, title) values (4, 'Cooking for beginners')
insert into Subjects(pk_id, title) values (5, 'Eating for pros')
insert into Subjects(pk_id, title) values (6, 'Dishwashing for everyone')
insert into Subjects(pk_id, title) values (7, 'Digesting for experts')
insert into Subjects(pk_id, title) values (8, 'Becoming hungry again...')
insert into Subjects(pk_id, title) values (9, 'Redo from start')
insert into People(pk_id, name) values (1, 'Hank')
insert into People(pk_id, name) values (2, 'Cloe')
insert into People(pk_id, name) values (3, 'Mary')
insert into Results(pk_id, fk_subjects_id, fk_people_id, result) values (1, 1, 1, 2)
insert into Results(pk_id, fk_subjects_id, fk_people_id, result) values (2, 2, 1, 4)
insert into Results(pk_id, fk_subjects_id, fk_people_id, result) values (3, 3, 1, 3)
insert into Results(pk_id, fk_subjects_id, fk_people_id, result) values (4, 9, 1, 5)
insert into Results(pk_id, fk_subjects_id, fk_people_id, result) values (5, 1, 2, 4)
insert into Results(pk_id, fk_subjects_id, fk_people_id, result) values (6, 2, 2, 1)
insert into Results(pk_id, fk_subjects_id, fk_people_id, result) values (7, 3, 2, 5)
insert into Results(pk_id, fk_subjects_id, fk_people_id, result) values (8, 4, 2, 2)
insert into Results(pk_id, fk_subjects_id, fk_people_id, result) values (9, 5, 2, 3)
insert into Results(pk_id, fk_subjects_id, fk_people_id, result) values (10, 6, 2, 2)
insert into Results(pk_id, fk_subjects_id, fk_people_id, result) values (11, 7, 2, 1)
insert into Results(pk_id, fk_subjects_id, fk_people_id, result) values (12, 4, 3, 3)
insert into Results(pk_id, fk_subjects_id, fk_people_id, result) values (13, 5, 3, 5)
insert into Results(pk_id, fk_subjects_id, fk_people_id, result) values (14, 7, 3, 1)
insert into Results(pk_id, fk_subjects_id, fk_people_id, result) values (15, 8, 3, 5)
insert into Results(pk_id, fk_subjects_id, fk_people_id, result) values (16, 9, 3, 1)
Please imagine this as an university for amateur cooks. Now I want to present them their performance record/"scorecard", for every student, only with her or his marks. On this performance record there should be a list of all 9 subjects possible to pass, and where students got a result, that result should be filled in. I thought that should be possible to achieve with something like this:
SELECT PEOPLE.NAME, SUBJECTS.TITLE, RESULTS.RESULT FROM RESULTS
JOIN PEOPLE ON PEOPLE.PK_ID = RESULTS.FK_PEOPLE_ID
JOIN SUBJECTS ON SUBJECTS.PK_ID = RESULTS.FK_SUBJECTS_ID
WHERE RESULTS.FK_PEOPLE_ID = 2
But also using (LEFT|RIGHT|FULL) OUTER JOINs here does not help me to get what I want, I always only get
NAME TITLE RESULT
Cloe Choosing a recipe 4
Cloe Shopping ingredients 1
Cloe Preparations 5
Cloe Cooking for beginners 2
Cloe Eating for pros 3
Cloe Dishwashing for everyone 2
Cloe Digesting for experts 1
But I want:
NAME TITLE RESULT
Cloe Choosing a recipe 4
Cloe Shopping ingredients 1
Cloe Preparations 5
Cloe Cooking for beginners 2
Cloe Eating for pros 3
Cloe Dishwashing for everyone 2
Cloe Digesting for experts 1
Cloe Becoming hungry again...
Cloe Redo from start
Without having to fill in empty rows for all students which did not take all exams yet.
Is it possible? If so, how?
Thank You very much in advance and Happy Easter to everyone! :-)
With kind regards,
Chriss
Edited by: user9355711 on 01.04.2010 07:01
Edited by: user9355711 on 01.04.2010 07:28
Edited by: user9355711 on 01.04.2010 07:29Also;
var n number
exec :n := 2;
PL/SQL procedure successfully completed
n
2
select ppl.name, sub.title, res.result
from subjects sub, people ppl, results res
where sub.pk_id = res.fk_subjects_id(+)
and ppl.pk_id = :n
and res.fk_people_id(+) = :n
order by sub.title;
NAME TITLE RESULT
Cloe Becoming hungry again...
Cloe Choosing a recipe 4
Cloe Cooking for beginners 2
Cloe Digesting for experts 1
Cloe Dishwashing for everyone 2
Cloe Eating for pros 3
Cloe Preparations 5
Cloe Redo from start
Cloe Shopping ingredients 1 -
Two query result rows in single report according to condition
Is it possible to have a report where the first rwo of the report will display the result of query1 and second row will display the result of query2.
The query1 and Query2 are as follows:
SELECT BNO, DATA1 FROM TABLE1 ;
SELECT RNO, DATA2 FROM TABLE2
The matching condition is BNO = RNO(+)
Kindly suggest ?
Sanjay
CREATE TABLE TABLE1
BNO NUMBER,
DATA1 VARCHAR2(20)
CREATE TABLE TABLE2
RPNO NUMBER,
RNO NUMBER,
DATA2 VARCHAR2(20)
INSERT INTO TABLE1(BNO, DATA1) VALUES(111,'200');
INSERT INTO TABLE1(BNO, DATA1) VALUES(112,'400');
INSERT INTO TABLE1(BNO, DATA1) VALUES(113,'500');
INSERT INTO TABLE2(RPNO,RNO,DATA2) VALUES(10,111,'100');
INSERT INTO TABLE2(RPNO,RNO,DATA2) VALUES(11,111,'100');
INSERT INTO TABLE2(RPNO,RNO,DATA2) VALUES(12,111,'100');
INSERT INTO TABLE2(RPNO,RNO,DATA2) VALUES(13,112,'400');
INSERT INTO TABLE2(RPNO,RNO,DATA2) VALUES(14,113,'500');One option can be UNION ALL
SELECT
BNO,
DATA1
FROM
SELECT
BNO, DATA1,rownum as rn
FROM
TABLE1
UNION ALL
SELECT
t2.RNO as BNO, t2.DATA2 as DATA1, rownum as rn
FROM
TABLE2 t2
WHERE
EXISTS
SELECT
1
FROM
table1 t1
WHERE
t1.bno = t2.RNO
ORDER BY
1,3
BNO DATA1
111 200
111 100
111 100
111 100
112 400
112 400
113 500
113 500
8 rows selected -
SQL Query results to CSV as two worksheets
I'm trying to take two SQL queries and get the results sent to a CSV file on two worksheets. Looking online I have not found a solid example of using the Excel ComObject to create a CSV then add a new worksheet to the CSV file. An added bonus
would be using AutoFit on the columns so everything is easily visible.
Code found online got me the following script which does work, however it takes 12 minutes to pipe the SQL queries to Excel. Switching to a CSV and the script executes in 5 seconds.
This is another nice to have, I was also looking the best way to look at the results (only 1 column) and depending on the length of the data, insert what Excel would call a Cell thereby shifting cells RIGHT but so far have found no clear examples of how
to accomplish that. My guess would be modifying my SQL queries but I've posted a question on StackOverFlow and someone suggested modifying the PowerShell Table created from the SQL dataset.Tables
Code:
$docs = "C:\Scripts\Output.xlsx"
If (Test-Path $docs){Remove-Item $docs}
Function Run-Query {
param([string[]]$queries,[string[]]$sheetnames)
## - Create an Excel Application instance:
$xlsObj = New-Object -ComObject Excel.Application
$xlsObj.DisplayAlerts = $false
$xlsWb = $xlsobj.Workbooks.Add(1)
## - Create new Workbook and Sheet (Visible = 1 / 0 not visible)
$xlsObj.Visible = 0
$time = 2
for ($i = 0; $i -lt $queries.Count; $i++){
$percentage = $i / $time
$remaining = New-TimeSpan -Seconds ($time - $i)
$message = "{0:p0} complete" -f $percentage, $remaining
Write-Progress -Activity "Creating Daily Reboot Spreadsheet" -status $message -PercentComplete ($percentage * 100)
$query = $queries[$i]
$sheetname = $sheetnames[$i]
$xlsSh = $xlsWb.Worksheets.Add([System.Reflection.Missing]::Value, $xlsWb.Worksheets.Item($xlsWb.Worksheets.Count))
$xlsSh.Name = $sheetname
### SQL query results sent to Excel
$SQLServer = 'ServerName'
$Database = 'DataBase'
## - Connect to SQL Server using non-SMO class 'System.Data':
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $Database; Integrated Security = True"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $query
$SqlCmd.Connection = $SqlConnection
## - Extract and build the SQL data object '$Table2':
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$SqlConnection.Close()
$Table1 = $DataSet.Tables["Table"]
## - Build the Excel column heading:
[Array] $getColumnNames = $Table1.Columns | SELECT ColumnName
## - Build column header:
[Int] $RowHeader = 1
foreach ($ColH in $getColumnNames)
$xlsSh.Cells.item(1, $RowHeader).font.bold = $true
$xlsSh.Cells.item(1, $RowHeader) = $ColH.ColumnName
$RowHeader++
## - Adding the data start in row 2 column 1:
[Int] $rowData = 2
[Int] $colData = 1
foreach ($rec in $Table1.Rows)
foreach ($Coln in $getColumnNames)
## - Next line convert cell to be text only:
$xlsSh.Cells.NumberFormat = "@"
## - Populating columns:
$xlsSh.Cells.Item($rowData, $colData) = $rec.$($Coln.ColumnName).ToString()
$ColData++
$rowData++; $ColData = 1
## - Adjusting columns in the Excel sheet:
$xlsRng = $xlsSH.usedRange
[void] $xlsRng.EntireColumn.AutoFit()
}#End For loop.
#Delete unwanted Sheet1.
$xlsWb.Sheets.Item('Sheet1').Delete()
#Set Monday to Active Sheet upon opening Workbook.
$xlsWb.Sheets.Item('Cert').Activate()
## ---------- Saving file and Terminating Excel Application ---------- ##
$xlsFile = "C:\Scripts\Output.xlsx"
[void] $xlsObj.ActiveWorkbook.SaveAs($xlsFile)
$xlsObj.Quit()
## - End of Script - ##
start-sleep 2
While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($xlsRng)) {'cleanup xlsRng'}
While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($xlsSh)) {'cleanup xlsSh'}
While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($xlsWb)) {'cleanup xlsWb'}
While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($xlsObj)) {'cleanup xlsObj'}
[gc]::collect() | Out-Null
[gc]::WaitForPendingFinalizers() | Out-Null
}#End Function
$queries = @()
$queries += "Query1"
$queries += "Query2"
$sheetnames = @('Cert','Prod')
Run-Query -queries $queries -sheetnames $sheetnamesHere's what I ended up with that accomplishes my goal. I learned it's not possible to create a CSV with two worksheets since Excel will allow this but the CSV cannot be saved with the second worksheet. Instead, I create two CSV files then merge
them into one Excel workbook, one CSV per worksheet. In my case, this happens in 5 seconds. There is one thing which must be mentioned, I've seen this script fail the first time it is run but will successfully run the second time.
Also note, after much trial and error, this code correctly cleans up the Excel ComObject!! -Thanks go to JRV.
$docs = "D:\Scripts\MonthlyReboots.xlsx"
IF (Test-Path $docs){Remove-Item $docs}
$csv1 = "D:\Scripts\Cert.csv"
IF (Test-Path $csv1){Remove-Item $csv1}
$csv2 = "D:\Scripts\Prod.csv"
IF (Test-Path $csv2){Remove-Item $csv2}
Function Run-Query {
param([string[]]$queries,[string[]]$sheetnames,[string[]]$filenames)
Begin{
$SQLServer = 'ServerName'
$Database = 'DataBase'
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $Database; Integrated Security = True"
$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = 0
$dest = $Excel.Workbooks.Add(1)
}#End Begin
Process{
For($i = 0; $i -lt $queries.Count; $i++){
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $queries[$i]
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$DataSet.Tables[0] | Export-Csv -NoTypeInformation -Path "D:\Scripts\$($sheetnames[$i]).csv" -Force
}#end for loop.
}#End Process
End{
$SqlConnection.Close()
#Excel magic test!
For($i = 0; $i -lt $queries.Count; $i++){
$loopy = (Resolve-Path -Path $filenames[$i]).ProviderPath
$Book = $Excel.Workbooks.Open($loopy)
$next = $Excel.workbooks.Open($loopy)
$next.ActiveSheet.Move($dest.ActiveSheet)
$xlsRng = $dest.ActiveSheet.UsedRange
$xlsRng.EntireColumn.AutoFit() | Out-Null
$dest.sheets.item('Sheet1').Delete()
$xlsFile = "D:\Scripts\MonthlyReboots.xlsx"
[void] $Excel.ActiveWorkbook.SaveAs($xlsFile)
$Excel.Quit()
While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($xlsRng)) {'cleanup xlsRng'}
While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($next)) {'cleanup xlsSh'}
While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($Book)) {'cleanup xlsWb'}
While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel)) {'cleanup xlsObj'}
[gc]::collect() | Out-Null
[gc]::WaitForPendingFinalizers() | Out-Null
}#End end block.
}#End function run-query.
$queries = @()
$queries += @'
Select * from table1
$queries += @'
Select * from table2
$sheetnames = @("Cert","Prod")
$filenames = @("D:\Scripts\Prod.csv","D:\Scripts\Cert.csv")
Run-Query -queries $queries -sheetnames $sheetnames -filenames $filenames
Start-Sleep -Milliseconds 50
Invoke-Item D:\Scripts\MonthlyReboots.xlsx -
User defined func: Unavble to merge two arrays in result list
Hi
I am trying to merge two arrays on the basis of "FEE" element in the input file;
Actually there is an Attribute Name and Value pair array coming in the input file which has 5 pairs already(Notification + 100 , oversize + 8 etc.) see example below;
<m0:Fees>ZB9</m0:Fees>
<m:Attribute>
<m0:Attributename>NOTIFICATION</m0:Attributename>
<m0:Attributevalue>100</m0:Attributevalue>
</m:Attribute>
<m:Attribute>
<m0:Attributename>OVERSIZE</m0:Attributename>
<m0:Attributevalue>8</m0:Attributevalue>
</m:Attribute>
<m:Attribute>
<m0:Attributename>OVERWEIGHT</m0:Attributename>
<m0:Attributevalue>108</m0:Attributevalue>
</m:Attribute>
<m:Attribute>
<m0:Attributename>SIGNATURE</m0:Attributename>
<m0:Attributevalue>294</m0:Attributevalue>
</m:Attribute>
<m:Attribute>
<m0:Attributename>RTS</m0:Attributename>
<m0:Attributevalue>8</m0:Attributevalue>
</m:Attribute>
The condition is:
CASE 1. If the FEE doesn't exist in the file then only the Atrribute Name and Value in added to the Array
CASE 2 If FEE exist then add all the Atrribute Name and Value pairs as well as in the last index of Array add String "Fee" in Attributename and String "ZB9" in Attributevalue.
CASE 1 is working fine.
but in CASE 2 even if i m taking an output array of length Attributename +1 and Attributevalue +1 and trying to add "Fee" and "ZB9" respectively, it never happens.
Please have a look at the code below;
//write your code here
public void ud_Attributename(String[] Fees,String[] Attributename,ResultList result,Container container){
String attribute_copy[]=new String[Attributename.length+1];
String attribute_name[]=new String[Attributename.length];
String array_copy1[]=new String[Attributename.length+1];
//int len =Attributename.length;
if(Fees[0]!=null)
if(Fees[0].equals("ZB0"))
Fees[0]="01";
else if(Fees[0].equals("ZB5"))
Fees[0]="02";
else if(Fees[0].equals("ZB6"))
Fees[0]="03";
else if(Fees[0].equals("ZB9"))
Fees[0]="04";
try{
if((Fees[0]=="01")||(Fees[0]=="02")||(Fees[0]=="03")||(Fees[0]=="04"))
for(int x=0;x<=Attributename.length;x++)
if(x==Attributename.length)
array_copy1[x]="Fee";
else{
array_copy1[x]=Attributename[x];
result.addValue(array_copy1[x]);
else
for(int i=0;i<=len;i++)
attribute_name<i>=Attributename[i+1];
result.addValue(attribute_name<i>);
}catch(Exception e)
{e.printStackTrace();}
Same way i've used for Attributevalue.
But the result is
<ATTRIBUTEPAIR>
<PAIR>
<NAME>NOTIFICATION</NAME>
<VALUE>04</VALUE>
</PAIR>
<PAIR>
<NAME>OVERSIZE</NAME>
<VALUE>8</VALUE>
</PAIR>
<PAIR>
<NAME>OVERWEIGHT</NAME>
<VALUE>108</VALUE>
</PAIR>
<PAIR>
<NAME>SIGNATURE</NAME>
<VALUE>294</VALUE>
</PAIR>
<PAIR>
<NAME>RTS</NAME>
<VALUE>8</VALUE>
</PAIR>
</ATTRIBUTEPAIR>
Please suggest where i am wrong. ur help is very much appreciated.
Thnks in advancethis is i am doing now
//write your code here
String attribute_copy[]=new String[Attributename.length+1];
String attribute_name[]=new String[Attributename.length];
String attribute_name1[]={"Fee"};
//String[] Attributename.copyTo(attribute_name1,0);
//String[] attribute_name1 = (String[]) Attributename.Clone();
//String fees;
String array_copy1[]=new String[Attributename.length];
int len =Attributename.length;
for(int y=0;y<len;y++){
array_copy1[y]=Attributename[y];
if(Fees[0]!=null)
if(Fees[0].equals("ZB0"))
Fees[0]="01";
else if(Fees[0].equals("ZB5"))
Fees[0]="02";
else if(Fees[0].equals("ZB6"))
Fees[0]="03";
else if(Fees[0].equals("ZB9"))
Fees[0]="04";
else if(Fees[0].equals("ZA1"))
Fees[0]="05";
else if(Fees[0].equals("ZA2"))
Fees[0]="06";
try{
if((Fees[0]=="01")||(Fees[0]=="02")||(Fees[0]=="03")||(Fees[0]=="04")||(Fees[0]=="05")||(Fees[0]=="06"))
int j=0;
for(int a=0;a<=len;a++)
if(j==0&&attribute_copy[j]==null)
attribute_copy[j]="Fee";
else
//int b=-1;
for(int i=0;i<=len;i++)
if(i==j)
//i=i-1;
attribute_copy[j]=array_copy1[i-1];
break;
else{
continue;}
result.addValue(attribute_copy[j]);
j+=1;
else
for(int i=0;i<=len;i++)
attribute_name<i>=Attributename[i+1];
result.addValue(attribute_name<i>);
}catch(Exception e)
{e.printStackTrace();}
and the result in queue is
SUPPRESS
[FEE]
[NOTIFICATION]
[NOTIFICATION]
[OVERSIZE]
[OVERSIZE]
[OVERWEIGHT]
[OVERWEIGHT]
[SIGNATURE]
[SIGNATURE]
[RTS]
[RTS]
but in the output i m getting
<ATTRIBUTEPAIR>
<REF_HANDLE>0001</REF_HANDLE>
<PAIR>
<NAME>Fee</NAME>
<VALUE>04</VALUE>
</PAIR>
<PAIR>
<NAME>OVERSIZE</NAME>
<VALUE>8</VALUE>
</PAIR>
<PAIR>
<NAME>OVERWEIGHT</NAME>
<VALUE>108</VALUE>
</PAIR>
<PAIR>
<NAME>SIGNATURE</NAME>
<VALUE>294</VALUE>
</PAIR>
<PAIR>
<NAME>RTS</NAME>
<VALUE>8</VALUE>
</PAIR>
</ATTRIBUTEPAIR>
Notification is missing. -
Execute the same query twice, get two different results
I have a query that returns two different results:
Oracle Version : 10.2.0.1.0
I am running the following query on the Oracle server in SQL*Plus Worksheet.
SELECT COUNT(*)
FROM AEJOURNAL_S1
WHERE CHAR_TIME BETWEEN TO_DATE('12-AUG-10 01:17:39 PM','DD-MON-YY HH:MI:SS AM') AND
TO_DATE('13-AUG-10 14:17:34','DD-MON-YY HH24:MI:SS')
AND DESC2 LIKE '%'
AND DESC1 LIKE '%'
AND DESC2 LIKE '%'
AND ETYPE LIKE '%'
AND MODULE LIKE '%'
AND LEVELL = '11-WARNING'
ORDER BY ORDD DESC;
The very first time the query is run, it will return a count of 259. The next time the query is run, lets say, 10 seconds later, it will return a count of 260. The above query is exemplary of the kind of thing I'm trying to do. It seems like the more fields filtered against '%', the more random the count return becomes. Sometime you have to execute the query three or four times before it levels out to a consistent number.
I'm using '%' as the default for various fields, because this was the easiest thing to do to support a data-driven Web interface. Maybe I have to 'dynamically' build the entire where clause, instead of just parameterizing the elements and having default '%'. Anyway, to eliminate the web interface for the purpose of troubleshooting the above query was run directly on the Oracle server.
This query runs against a view. The view does a transpose of data from a table.
Below is the view AEJOURNAL_S1
SELECT
CHAR_TIME,
CHAR_INST,
BATCH_ID,
MIN(DECODE(CHAR_ID,6543,CHAR_VALUE)) AS ORDD,
MIN(DECODE(CHAR_ID,6528,CHAR_VALUE)) AS AREAA,
MIN(DECODE(CHAR_ID,6529,CHAR_VALUE)) AS ATT,
COALESCE(MIN(DECODE(CHAR_ID,6534,CHAR_VALUE)),'N/A') AS CATAGORY,
MIN(DECODE(CHAR_ID,6535,CHAR_VALUE)) AS DESC1,
MIN(DECODE(CHAR_ID,6536,CHAR_VALUE)) AS DESC2,
MIN(DECODE(CHAR_ID,6537,CHAR_VALUE)) AS ETYPE,
MIN(DECODE(CHAR_ID,6538,CHAR_VALUE)) AS LEVELL,
MIN(DECODE(CHAR_ID,6539,CHAR_VALUE)) AS MODULE,
MIN(DECODE(CHAR_ID,6540,CHAR_VALUE)) AS MODULE_DESCRIPTION,
MIN(DECODE(CHAR_ID,6541,CHAR_VALUE)) AS NODE,
MIN(DECODE(CHAR_ID,6542,CHAR_VALUE)) AS STATE,
MIN(DECODE(CHAR_ID,6533,CHAR_VALUE)) AS UNIT
FROM CHAR_BATCH_DATA
WHERE subbatch_id = 1774
GROUP BY CHAR_TIME, CHAR_INST, BATCH_ID
So... why does the query omit rows on the first execution? Is this some sort of optimizer issue. Do I need to rebuild indexes? I looked at the indexes, they are all valid.
Thanks for looking,
Danuser2188367 wrote:
I have a query that returns two different results:
Oracle Version : 10.2.0.1.0
I am running the following query on the Oracle server in SQL*Plus Worksheet.
SELECT COUNT(*)
FROM AEJOURNAL_S1
WHERE CHAR_TIME BETWEEN TO_DATE('12-AUG-10 01:17:39 PM','DD-MON-YY HH:MI:SS AM') AND
TO_DATE('13-AUG-10 14:17:34','DD-MON-YY HH24:MI:SS')
AND DESC2 LIKE '%'
AND DESC1 LIKE '%'
AND DESC2 LIKE '%'
AND ETYPE LIKE '%'
AND MODULE LIKE '%'
AND LEVELL = '11-WARNING'
ORDER BY ORDD DESC;
The very first time the query is run, it will return a count of 259. The next time the query is run, lets say, 10 seconds later, it will return a count of 260. The above query is exemplary of the kind of thing I'm trying to do. It seems like the more fields filtered against '%', the more random the count return becomes. Sometime you have to execute the query three or four times before it levels out to a consistent number.
I'm using '%' as the default for various fields, because this was the easiest thing to do to support a data-driven Web interface. Maybe I have to 'dynamically' build the entire where clause, instead of just parameterizing the elements and having default '%'. Anyway, to eliminate the web interface for the purpose of troubleshooting the above query was run directly on the Oracle server.
This query runs against a view. The view does a transpose of data from a table.
Below is the view AEJOURNAL_S1
SELECT
CHAR_TIME,
CHAR_INST,
BATCH_ID,
MIN(DECODE(CHAR_ID,6543,CHAR_VALUE)) AS ORDD,
MIN(DECODE(CHAR_ID,6528,CHAR_VALUE)) AS AREAA,
MIN(DECODE(CHAR_ID,6529,CHAR_VALUE)) AS ATT,
COALESCE(MIN(DECODE(CHAR_ID,6534,CHAR_VALUE)),'N/A') AS CATAGORY,
MIN(DECODE(CHAR_ID,6535,CHAR_VALUE)) AS DESC1,
MIN(DECODE(CHAR_ID,6536,CHAR_VALUE)) AS DESC2,
MIN(DECODE(CHAR_ID,6537,CHAR_VALUE)) AS ETYPE,
MIN(DECODE(CHAR_ID,6538,CHAR_VALUE)) AS LEVELL,
MIN(DECODE(CHAR_ID,6539,CHAR_VALUE)) AS MODULE,
MIN(DECODE(CHAR_ID,6540,CHAR_VALUE)) AS MODULE_DESCRIPTION,
MIN(DECODE(CHAR_ID,6541,CHAR_VALUE)) AS NODE,
MIN(DECODE(CHAR_ID,6542,CHAR_VALUE)) AS STATE,
MIN(DECODE(CHAR_ID,6533,CHAR_VALUE)) AS UNIT
FROM CHAR_BATCH_DATA
WHERE subbatch_id = 1774
GROUP BY CHAR_TIME, CHAR_INST, BATCH_ID
So... why does the query omit rows on the first execution? Is this some sort of optimizer issue. Do I need to rebuild indexes? I looked at the indexes, they are all valid.
Thanks for looking,
DanIn fact you the first time you ran the query the data has been retrived from disk to memory , in the second time the data is already in memory so the respnse time should be faster ,but if you chagne any condition or column or letter case the optimizer will do the first step (data will be retrived from disk to memory ) -
SCCM Query to merge two different collections to one
Hi Team,
I wanted to merge two different collections e.g. NY and LA collection in one single all US Collection. I wanted to see all PCs under US collection. NY and LA computers are manually updated in collection i cannt use there query.
Waiting for your response.If you already have to two collections you can do something like this
select
SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client
from SMS_R_System where SMS_R_System.ResourceId in (select ResourceId from
SMS_CM_RES_COLL_XXXXXXX) or SMS_R_System.ResourceId in (select ResourceId from
SMS_CM_RES_COLL_XXXXXXX)
John Marcum | http://myitforum.com/myitforumwp/author/johnmarcum/ -
CR 4 Ent, Xcelsius and WebI - one query and two different results
Dear Sirs,
I'm using BO 4.0 platform and 3 tools: Crystal Reports for Enterprise, WebI and Dashboard Design (Xcelsius).
I have one question, because in my opinion in this solution is one inconsistency.
I have one table in SQL Server (like below):
IDRec (autoinc) | Col1 (varchar) | Col2 (int)
1 A 1
2 A 1
3 B 2
4 B 2
I have one universe with ONLY 3 dimensions (IDRec, Col1, Col2). I haven't any measures.
And:
1. Using CR 4 Ent and I create report using 3 dimensions (IDRec, Col1, Col2).
I make sure, that I selected option: "Retrieve duplicate rows"
If I have 3 columns in details I have 4 records (4 rows) in my report, when I have 2 columns (Col1 Col2) I have only 2 records (2 rows) in report (Page view).
So universe (or something like this) use option DISTICT (I think).
2. When I use WebI (14.0.2) I have the same situation.
3. When I use Dashboard Desigm (Xcelsius 2011) I have 4 rows !!! ALWAYS - it doesn't matter I selected "Retrieve duplicate rows" or not !!!
When I look to "View script" window, I not see DISTINCT clause.
Am I doing something wrong?
I can change the settings so as to be able to see duplicate records?
It's very important for some calculation, especially in Crystal Reports (for Enterprise).Hi,
Thanks for the response...But the result is deviating from the expected..
expected is
if we have first query returns second query returns
1 4
2 5
3 6
these two queries result should be in one table , with first query result in first column and second query result in second column.
The two queries fetching data from same table(category table as in my post) with different search criteria( in where clause).......Regards,
Rakesh. -
Saving a report with two query providers into .csv format
Hi,
I have developed a webi report which has two query providers. I have linked the objects from these two queries at the report level using merged dimensions. the report is running fine. When I save it in EXCEL or PDF it saves the same report, but when I try to save the report in .CSV format, the output of the second query provided is getting appened at the bottom of the report.
Has anyone encountered similar problem is so whats the solution for it.
For me business wants the report to be saved as .csv only as it acts as a source file to other application.Hi
please take a look at the explanation area in the following note
https://css.wdf.sap.corp/sap/support/notes/1417382
When saving Web Intelligence document as Excel format, the result is saved based on the report design.
When saving Web Intelligence document as CSV format, all data in the Data Provider are saved.
I believe that the behaviour you described is by design so there is not much to do about it. You can open a case by SAP support though asking if this changed in a later service pack (actual service pack version for XI R2 is SP 6).
Regards,
Stratos -
How to merge two search button from different criteria
How to merge two search button from different criteria
this image show the question
http://s24.postimg.org/4algthuj9/1111.jpg
two different criteria for the same view and I need to merge it in one button as when I click
on the button search result give from two criteria parametersYou can!t using af:query. the af:query component comes as is. If you can't do it through the properties, you probably can't do it at all.
As in your other thread, the way to go is to program your own search form. This way you can use a layout and functionality you like.
For this you create a form with input fields for the values you are searching for, put them on hte page in a way you like and in the end by hitting on a button (e.g. called Search) map all inputfields to parameters of a service method you defined in your application module or VO. This service method then executes a view criteria returning all matches in the default iterator (just as if you had used af:query.
Timo -
Merge Two Rows of a table to One row but into two columns
Hi
I Am struck in writing a query to merge two rows into two columns of one row.
Here is the Sample data i am working with,
Col 1 Col 2 Col3 Col4 Col Col6
5000 573-3000 2 0 Phone
5000 573-3036 1 0 Fax
5000 893-5703 3 0 WOrk
3000 232-5656 1 0 Phone
3000 353-5656 2 0 FAx
Here Col,Col3,Col4 form the Key.
now wht i am trying to do is to Merge these type of rows put them into Columns P,F,W,E respectively to achive a Structure as below
Col1 P F W
5000 573-3000 573-3036 893-5703
3000 232-5656 353-5656
Can you please help me how could i do this.
I am pretty ordinary at writing SQL's.
Thanks a Lot in Advance
Message was edited by:
SreebhushanSearch the forum for PIVOT and you'll find plenty of examples.
-
Stepping through a query result set, replacing one string with another.
I want to write a function that replaces the occurance of a string with another different string. I need it to be a CF fuction that is callable from another CF function. I want to "hand" this function an SQL statement (a string) like this: (Please note, don't bother commenting that "there are eaiser ways to write this SQL..., I've made this simple example to get to the point where I need help. I have to use a "sub_optimal" SQL syntax just to demonstrate the situation)
Here is the string I want to pass to the function:
SELECT
[VERYLONGTABLENAME].FIRST_NAME,
[VERYLONGTABLENAME].LAST_NAME,
[VERYLONGTABLENAME].ADDRESSS
FROM
LONGTABLENAME [VERYLONGTABLENAME]
Here is the contents of the ABRV table:
TBL_NM, ABRV <!--- Header row--->
VERYLONGTABLENAME, VLTN
SOMEWHATLONGTALBENAME, SLTN
MYTABLENAME, MTN
ATABLENAME, ATN
The function will return the original string, but with the abreviations in place of the long table names, example:
SELECT
VLTN.FIRST_NAME,
VLTN.LAST_NAME,
VLTN.ADDRESSS
FROM
LONGTABLENAME VLTN
Notice that only the table names surrounded by brackets and that match a value in the ABRV table have been replaced. The LONGTABLENAME immediately following the FROM is left as is.
Now, here is my dum amatuer attempt at writing said function: Please look at the comment lines for where I need help.
<cffunction name="AbrvTblNms" output="false" access="remote" returntype="string" >
<cfargument name="txt" type="string" required="true" />
<cfset var qAbrvs=""> <!--- variable to hold the query results --->
<cfset var output_str="#txt#"> <!--- I'm creating a local variable so I can manipulate the data handed in by the TXT parameter. Is this necessary or can I just use the txt parameter? --->
<cfquery name="qAbrvs" datasource="cfBAA_odbc" result="rsltAbrvs">
SELECT TBL_NM, ABRV FROM BAA_TBL_ABRV ORDER BY 1
</cfquery>
<!--- I'm assuming that at this point the query has run and there are records in the result set --->
<cfloop index="idx_str" list="#qAbrvs#"> <!--- Is this correct? I think not. --->
<cfset output_str = Replace(output_str, "#idx_str#", ) <!--- Is this correct? I think not. --->
</cfloop> <!--- What am I looping on? What is the index? How do I do the string replacement? --->
<!--- The chunck below is a parital listing from my Delphi Object Pascal function that does the same thing
I need to know how to write this part in CF9
while not Eof do
begin
s := StringReplace(s, '[' +FieldByName('TBL_NM').AsString + ']', FieldByName('ABRV').AsString, [rfReplaceAll]);
Next;
end;
--->
<cfreturn output_txt>
</cffunction>
I'm mainly struggling with syntax here. I know what I want to happen, I know how to make it happen in another programming language, just not CF9. Thanks for any help you can provide.RedOctober57 wrote:...
Thanks for any help you can provide.
One:
<cfset var output_str="#txt#"> <!--- I'm creating a local
variable so I can manipulate the data handed in by the TXT parameter.
Is this necessary or can I just use the txt parameter? --->
No you do not need to create a local variable that is a copy of the arguments variable as the arguments scope is already local to the function, but you do not properly reference the arguments scope, so you leave yourself open to using a 'txt' variable in another scope. Thus the better practice would be to reference "arguments.txt" where you need to.
Two:
I know what I want to happen, I know how to make it happen in another programming language, just not CF9.
Then a better start would be to descirbe what you want to happen and give a simple example in the other programming language. Most of us are muti-lingual and can parse out clear and clean code in just about any syntax.
Three:
<cfloop index="idx_str" list="#qAbrvs#"> <!--- Is this correct? I think not. --->
I think you want to be looping over your "qAbrvs" record set returned by your earlier query, maybe.
<cfloop query="qAbrvs">
Four:
<cfset output_str = Replace(output_str, "#idx_str#", ) <!--- Is this correct? I think not. --->
Continuing on that assumption I would guess you want to replace each instance of the long string with the short string form that record set.
<cfset output_str = Replace(output_str,qAbrs.TBLNM,qAbrs.ABRV,"ALL")>
Five:
</cfloop> <!--- What am I looping on? What is the index? How do I do the string replacement? --->
If this is true, then you are looping over the record set of tablenames and abreviations that you want to replace in the string.
Maybe you are looking for
-
Error while deploying the mapping in owb 10gR2
Hi friends, when i tried to deploy the mapping firstly i got the below error like Name Action Status Log COPY_OF_ORG_FINAL_MAPPING Create Warning ORA-06550: line 11, column 3: PL/SQL: SQL Statement ignored COPY_OF_ORG_FINAL_MAPPING Create W
-
NWDI in E.P 7.0 Configuration Problem
Hello Everyone, I have Selected 'DI' While Installing SAP and for Configuring NWDI I have run the DI Template in SAP Netweaver Adminstration. Imported the Configuration in NWDS in DevelopmentConfiguration Perspective. 1.While creating the Development
-
Screen exit for transaction IW31 for ref. object O150
Hi, I need for find screen enhancement for trasaction iw31 in plant maintenance. The requirement is to add 2 more fields (Functional location and Assembly) in the 'reference object' O150 on header tab. Currently the reference object has 2 fields and
-
Dear All, In FK08 we approve the vendor master data changes by clicking on the tab 'changes to sensitive fields', then further digging inside we could see a detailed view of the actual changes.Now would it be possible to display all these changes on
-
Downloading spreadsheet mime types via weblogic 6.1
I'm having a problem with a jsp file -- within the weblogic v6.1 server environment that wasn't occuring when using v4.5.1. The jsp page in question is supposed to handle downloading a spreadsheet file via a 'p