Order in a query in SQL Command Processor
Hi all
I'm trying 'HTML DB 1.6' @htmldb.oracle.com.
Now when i run a simple query against a table in the 'SQL Command Processor', the order by doesn't work proparly. It seems that the ORDER BY clause is ignored.
Here is the query:
SELECT ng
FROM ges_rep_adr
ORDER BY ng
By the way the same happens in a report.
Has anybody an idea what's the problem?
Thanks in advance and best regards
Martin
Martin,
Try: select replace(substr(ng,1,1),' ','!')||substr(ng,2) from ges_rep_adr order by ngto see the cases where a leading space character in the output is not rendered visually and leads you to conclude that the rows are sorted wrong. If that's not it, let us know.
Scott
Similar Messages
-
Schema name added to SQL query after SQL Command
Post Author: rickeb1
CA Forum: Data Connectivity and SQL
Hello,
I am using Crystal Reports XI. I have created a Crystal report in the usual manner using a set of tables from a given database schema. When I look at the SQL query that Crystal generates, there are no data schema qualifiers anywhere.
Then I added an SQL Command object that I use as an additional table. Now when I look at the generated SQL query, the data schema name is added to the beginning of the original query as well as to the new SQL Comand code. It also creates an EXTERNAL JOIN which uses this hard-coded schema name (not exactly sure what an "external join" is).
This hard-coding of the schema name is causing a problem when we try to migrate the report to a different environment. Is there some way to avoid having Crystal generate a query with the schema name imbedded in the query, or is there a way to remove it after it is generated?
Thanks!Post Author: rickeb1
CA Forum: Data Connectivity and SQL
Actually, our problem may be related to this:
http://boardreader.com/t/Crystal_XI_249231/The_Show_SQL_Query_SQL_command_changes_89667.html
Any help greatly (and desparately) apapreciated! -
Code block works in SQL Command Processor but not in application
Hello forum,
Been struggling with this for a few days without success:
I have a form with a popup LOV called P6_POPUP, a file browse item called P6_BROWSE, a SUBMIT button, and a Process with the following code:
declare
q_image_id number;
begin
select host_family_photos_seq.nextval into q_image_id from dual;
insert into host_family_photos (image_id, file_object_id, image_name)
select q_image_id, id, filename
from htmldb_application_files where filename = :P6_BROWSE;
update host_family set image_id = q_image_id where family_name = :P6_POPUP;
end;
The Process Point is set to On Submit after Computations and Validations and When Button Pressed is set to the Submit button.
When I run the page the file is imported into HTMLDB_APPLICATION_FILES
but the insert and update do not occur.
The URL header after submitting is as follows:
http://127.0.0.1:8080/apex/f?p=115:1:480837828458787::NO:::&success_msg=Photo%20Imported%2FB87C5A54684B0DF005D09D0DFE6E98D6%2F
However if I run the above code in the APEX SQL Command window and supply the required variables it works every time - most confusing.
Not sure what to try from here.
thanks for your time,
BrettScott:
I always thought that the File Browse item maps to the NAME column in the view (below) and that is guaranteed to be unique. The NAME column seems to have a system-generated "F1234" id embedded in it (to guarantee uniqueness, I thought).
In other words, when we put a File Browse item on the page, submitting the page uploads the file into the HTMLDB_APPLICATION_FILES table and the way to access that record (to copy/move it into our own custom table) is by doing
from htmldb_application_files
where name = :P1_BROWSEThanks
SQL> desc htmldb_application_files
Name Null? Type
ID NOT NULL NUMBER
FLOW_ID NOT NULL NUMBER
NAME NOT NULL VARCHAR2(90)
FILENAME VARCHAR2(400)
TITLE VARCHAR2(255)
MIME_TYPE VARCHAR2(48)
DOC_SIZE NUMBER
DAD_CHARSET VARCHAR2(128)
CREATED_BY VARCHAR2(255)
CREATED_ON DATE
UPDATED_BY VARCHAR2(255)
UPDATED_ON DATE
LAST_UPDATED DATE
CONTENT_TYPE VARCHAR2(128)
BLOB_CONTENT BLOB
LANGUAGE VARCHAR2(30)
DESCRIPTION VARCHAR2(4000)
FILE_TYPE VARCHAR2(255)
FILE_CHARSET VARCHAR2(128) -
How do i get a output in CSV of a SQL query executed via SQL Command prompt
Hi All,
I have a question with reference to SQL command prompt. I have a sql query which runs properly and gives proper execution in SQL Management console in GUI.
This report is used to pull the free disk space report of our servers
As i want to schedule it as a report so i want to script it to run via SQL command prompt. I made the script and it works fine if i enter it in SQL command prompt. When i try to extract the output to a CSV File it fails. Below is the details of the command
i am using to query to pull the data. Can anyone help me in getting the output of this query in SQL command prompt.
sqlcmd -W -s , -S Servers FQDN
use operationsmanager
Go
Query:"select Path, InstanceName, SampleValue
from PerformanceDataAllView pdv with (NOLOCK)
inner join PerformanceCounterView pcv on pdv.performancesourceinternalid = pcv.performancesourceinternalid
inner join BaseManagedEntity bme on pcv.ManagedEntityId = bme.BaseManagedEntityId
where SampleValue < '20' and CounterName='% Free Space' and TimeSampled > '2014-08-06 11:00:00.00'
order by countername, timesampled" -s "," -o "C:\DataSqlCmd.csv"
Go
When i enter the command without the quotes when the query is starting and ending and also without the output command (-s "," -o "C:\DataSqlCmd.csv") it is working and shows the output in the command prompt. Below is the screen shot for
your reference.
Due to security reasons i have to erase the server names:
But when i add the line to extract the output ( -s "," -o "C:\DataSqlCmd.csv") It gives me this error:
The exact command would be:
sqlcmd -W -s , -S CINMLVSCOM01.e2klab.ge.com
use operationsmanager
Go
"select Path, InstanceName, SampleValue
from PerformanceDataAllView pdv with (NOLOCK)
inner join PerformanceCounterView pcv on pdv.performancesourceinternalid = pcv.performancesourceinternalid
inner join BaseManagedEntity bme on pcv.ManagedEntityId = bme.BaseManagedEntityId
where SampleValue < '20' and CounterName='% Free Space' and TimeSampled > '2014-08-06 11:00:00.00'
order by countername, timesampled" -s "," -o "C:\DataSqlCmd.csv" -h-1
Go
saying the syntax is not correct or some thing as per the below screenshot.
Can any one please help. Below is just the query whi i use to get the output in SQL management studio.
Can any one make a command for the below quer so i can directly execute and test for getting the output.
select Path, InstanceName, SampleValue
from PerformanceDataAllView pdv with (NOLOCK)
inner join PerformanceCounterView pcv on pdv.performancesourceinternalid = pcv.performancesourceinternalid
inner join BaseManagedEntity bme on pcv.ManagedEntityId = bme.BaseManagedEntityId
where SampleValue < '20' and CounterName='% Free Space' and TimeSampled > '2014-08-06 11:00:00.00'
order by countername, timesampled
Gautam.75801Can you try the below query?
select Path, InstanceName, SampleValue
from PerformanceDataAllView pdv with (NOLOCK)
inner join PerformanceCounterView pcv on pdv.performancesourceinternalid = pcv.performancesourceinternalid
inner join BaseManagedEntity bme on pcv.ManagedEntityId = bme.BaseManagedEntityId
where SampleValue < 20 and CounterName like '% Free Space' and TimeSampled > '2014-08-06 11:00:00.00'
order by countername, timesampled
-- replace the below query part in the below SQLCMD C:\>SQLCMD -S SERVERNAME -E -d operationsmanager -Q "select * from sys.databases ds with (nolock) where name='master'" -s "," -o "F:\PowerSQL\MyData.csv" -h -1
SQLCMD -S SERVERNAME -E -d OperationsManager -Q "select Path, InstanceName, SampleValue
from PerformanceDataAllView pdv with (NOLOCK)
inner join PerformanceCounterView pcv on pdv.performancesourceinternalid = pcv.performancesourceinternalid
inner join BaseManagedEntity bme on pcv.ManagedEntityId = bme.BaseManagedEntityId
where SampleValue < '20' and CounterName='% Free Space' and TimeSampled > '2014-08-06 11:00:00.00'
order by countername, timesampled" -s "," -o "c:\MyData.csv" -h -1
Refer for the other ways
http://dba.stackexchange.com/questions/23566/writing-select-result-to-a-csv-file
--Prashanth -
using apex 4.1 i'm entering the following query in the sql command window and I keep getting a pop-up for Entering Bind Variable. I'm not using bind variables though, anyone else see this issue before?
SELECT A.FIRST,A.LAST,A.COMPANY AS CNAME,
J.TOT_MAN_HOURS,
J.ACREAGE,
W.NUM_WORKERS,
W.START_DT
FROM EW_ACCOUNTS A, EW_WORK_ORDER W, EW_JOBS J
WHERE A.ID = J.ACCT_ID
AND J.JOB_ID = W.JOB_ID
AND W.START_DT >= SYSDATE
AND W.START_DT < SYSDATE+1
ORDER BY W.START_DTI tried that and it didn't seem to help either.
Funny though, if I write a new query against just one of the tables and write out each column name. it works. If I use the * instead of writing each column name, I have the same issue.
This is in apex.appshosting.com free demo environment. I sent them an email asking about it and they told me it was a code issue and they don't support the demo environment. -
Error in SQl Query - SQl Command not properly ended
Hi All
I have this SQL query that returns the following error when I run it in TOAD:
SELECT
VC.CAMPAIGN_NUMBER,VC.CAMPAIGN_TITLE,VC.CAMPAIGN_DESC,
VCV.START_DATE, VCV.END_DATE,VC.CAMPAIGN_TYPE,VC.APPLICABILITY,
VC.CAMPAIGN_PRIORITY
FROM
VM_CAMPAIGN_VIN VCV ,VM_CAMPAIGN VC
WHERE
VCV.VIN = 'US'
AND
VCV.CAMPAIGN_NUMBER = VC.CAMPAIGN_NUMBER AND VC.COUNTRY_CODE = 'E'
AND VC.LANGUAGE_CODE = 'L' AND VC.CAMPAIGN_TYPE = null
AND SYSDATE BETWEEN VCV.START_DATE AND VCV.END_DATE
AND SYSDATE BETWEEN VC.START_DATE AND VC.END_DATE)
A ORDER BY A.CAMPAIGN_PRIORITY DESC, A.END_DATE
The error is:
SQl Command not properly ended
Any help is highly appreciated. ThanksThanks a lot to everyone. It helped me run the query without any problem. Now I have another issue. This may not be the right place to post this question, I think.My apologies for that. The problem is, Weblogic posts an error as follows:
java.sql.SQLException: ORA-00923: FROM keyword not found where expected
I am wondering if this is an Java related error or an SQL related error.
Well, I am using the SQL Statement which you helped debug, and it is inside something called "XXSQLConstants.java consisting of the following SQL statement:
public static final String XX_ALL_CAMPS_SELECT = "SELECT * FROM" +
"(SELECT vc.campaign_number, vc.campaign_title, vc.campaign_desc, vc.start_date," +
"vc.end_date, vc.campaign_type, vc.applicability, vc.campaign_priority" +
"FROM vm_campaign vc" +
"WHERE vc.applicability = 'Y'" +
"AND vc.country_code = ? " +
"AND vc.language_code = ? " +
"AND vc.campaign_type = ? "+
"AND SYSDATE BETWEEN vc.start_date AND vc.end_date" +
"AND NOT EXISTS (" +
"SELECT 'X'" +
"FROM vm_campaign_vin vcv" +
"WHERE (vcv.vin = ? " +
"AND vcv.campaign_number = vc.campaign_number" +
"))" +
"UNION" +
"SELECT vc.campaign_number, vc.campaign_title, vc.campaign_desc," +
"vcv.start_date, vcv.end_date, vc.campaign_type, vc.applicability," +
"vc.campaign_priority" +
"FROM vm_campaign_vin vcv, vm_campaign vc" +
"WHERE vcv.vin = ? " +
"AND vcv.campaign_number = vc.campaign_number" +
"AND vc.country_code = ? " +
"AND vc.language_code = ? " +
"AND vc.campaign_type IS NULL" +
"AND SYSDATE BETWEEN vcv.start_date AND vcv.end_date" +
"AND SYSDATE BETWEEN vc.start_date AND vc.end_date)";
The SQl runs fine when tested (well, it does not return any data for the rows returned, but there are no errors), but in my application server I get the following error (pointing out the same SQL code pasted above:
java.sql.SQLException: ORA-00923: FROM keyword not found where expected
Any suggestions? Thanks in advance. I appreciate all replies -
Does CTAS evaluate "order by" in APEX SQL Command window?
I need to recreate my table in order to change the column order. When I use the SQL Commands window and run the SQL, it runs successfully, creates the new table, but doesn't reorder the columns.
Is this expected behavior?user648567 wrote:
Please update your forum profile with a real handle instead of "user648567".
I need to recreate my table in order to change the column order. When I use the SQL Commands window and run the SQL, it runs successfully, creates the new table, but doesn't reorder the columns.
What do you mean by "order by"?
Using an "ORDER BY" clause in a CTAS (in APEX or anywhare else) will have no effect on column order, which is determined by the order in which columns appear in the projection. It will affect the order in which rows are returned by that query, and it will not determine the order in which rows will be returned by querying the new table in the future.
To change the column order the columns in the SELECT clause of the CTAS would have to be in a different order from those in the original table, -
Nested query in FROM clause causes 'SQL Command not properly ended' error
SELECT sj.job_id AS job_id, 'STATUS_AWAITING_PREPARATION' AS job_status, sjr.email_sys_attach_filename AS attach_filename, sje.emailaddr as emailaddr_lastsentto
FROM arsnd_jobs sj, (SELECT emailaddr from ARSND_JOB_EMAILS where job_id=sj.job_id AND ROW_NUM=1) as SJE, ARSND_JOB_QUEUE sjq,ARSND_JOB_RECIPIENTS sjr
WHERE sj.job_id=sjq.job_id and sj.job_id=sjr.job_id
AND sjq.PROCESSING_STATE=0
ORDER BY sj.created
I don't see anything wrong with the above query, it fails with 'SQL Command not properly ended'.
If I remove the usage of the nested query in the FROM clause, then it doesn't give that error. Please advice what I'm doing wrong.Pls try
SELECT sj.job_id AS job_id, 'STATUS_AWAITING_PREPARATION' AS job_status, sjr.email_sys_attach_filename AS attach_filename, sje.emailaddr as emailaddr_lastsentto
FROM arsnd_jobs sj, (SELECT emailaddr from ARSND_JOB_EMAILS where job_id=sj.job_id AND ROW_NUM=1) SJE, ARSND_JOB_QUEUE sjq,ARSND_JOB_RECIPIENTS sjr
WHERE sj.job_id=sjq.job_id and sj.job_id=sjr.job_id
AND sjq.PROCESSING_STATE=0
ORDER BY sj.created
I have removed the 'as' clause you used for alias of the subquery. It should work fine now..... -
Query running on sql commands prompt not running on report region
Hi All,
Facing a weird issue now. I have written a report query which is running absolutely fine in sql command prompt but when i trying to run this as a report it is just processing and the report is not loading. What could be the reason behing this?
Thanks in Advance
RegardsHi,
With no other information about the problem is hard to know what's happening. If you could at least provide us with the query then I think it would be easier for us to help you.
Regards,
Sergio -
How to use lengthy query in a "SQL Command from Variable"
My oracle SQL Query length is more than 14000 characters, so how can i use this for "SQL command from variable".
SarvanEither create a view or a table valued UDF. Using stored procedure in OLEDB source has some gotchas it will not pick up metadata information by default due to late binding.
http://consultingblogs.emc.com/jamiethomson/archive/2006/12/20/SSIS_3A00_-Using-stored-procedures-inside-an-OLE-DB-Source-component.aspx
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Can I use multiline SQL commands in a query (within a component)?
I would like to modify the following query:
<td>ItranslationString</td>
<td>
INSERT INTO TRANSLATIONSTRINGS (daKey, daLanguage, daTranslation, daStringFlag, daSourceFile) VALUES (?, ?, ?, 'N', ?)
</td>
<td>daKeyField varchar
daLanguageField varchar
daTranslationField varchar
StringTranslationFilename varchar
</td>
so that the daSourceFile a) is selected from another record, if it exists b) uses the constant, if not.
In SQL Command the commands (without placeholders) look:
declare c integer;
res varchar(30);
key_var varchar(100);
def_lang_var varchar(5);
begin
key_var := 'newString';
def_lang_var := 'en';
res := 'ap_string.htm';
select count(*) into c FROM TRANSLATIONSTRINGS WHERE daKey = key_var AND daLanguage = def_lang_var;
if c > 0 then
select daSourceFile into res FROM TRANSLATIONSTRINGS WHERE daKey = key_var AND daLanguage = def_lang_var;
end if;
INSERT INTO TRANSLATIONSTRINGS (daKey, daLanguage, daTranslation, daStringFlag, daSourceFile) VALUES (key_var, 'cs', 'translation', 'N', res);
end;
However, such a query does not work in the query resource (multiline commands cannot be used?).
Neither can I think of one line query that would provide the same functionality (tried to test with COALESCE).Yes, I got the point. The query looks like:
INSERT INTO TRANSLATIONSTRINGS (daKey, daLanguage, daTranslation, daStringFlag, daSourceFile)
SELECT daKey, daLanguage, daTranslation, daStringFlag, daSourceFile FROM (
select 'newString1' daKey, 'en' daLanguage, 'transl' daTranslation, 'N' daStringFlag, daSourceFile FROM TRANSLATIONSTRINGS WHERE daKey = 'newString1' AND daLanguage = 'cs' UNION ALL SELECT 'newString1' daKey, 'en' daLanguage, 'transl' daTranslation, 'N' daStringFlag, 'default' daSourceFile FROM DUAL)
WHERE rownum<=1;
so that's the way how to solve it via SQL.
(Since I can't use DECLARE, I need to bind entry parameters as many times as they appear in the query - not a very nice way, but it works).
The question still is, whether there is a way how to use a multiline query in Component Queries. Even though it is not mentioned specifically in the documentation, it seems it is NOT to be possible by design. So the real question is really WHY - I guess it would be a little bit more convenient to begin/commit transactions, use variables, etc. in a multiline query.
Yet, Sam, thanks! -
Copying Access Queries to Query Builder instead of SQL Commands
Is there a way to copy Microsoft Access Queries to Query Builder (saved sql) instead of SQL Commands (saved sql)...Thanks in advance.
Hello,
No, that functionality does not exist currently, you would need to build your own.
If you search this forum there are a few threads which detail how you can install the Application Builder and SQL Workshop applications into the APEX environment itself so you can see how they (meaning the Oracle team) have built those apps.
Hope this helps,
John.
http://jes.blogs.shellprompt.net
http://apex-evangelists.com -
Xml query error. ORA-00933: SQL command not properly ended
Hi all,
My Database Version: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0.
CREATE table test (Name varchar2(3), Id number);
insert into test values ('abc', 61);
insert into test values ('def', 46);
select table_name,
column_name,
'abc' search_string,
result
from cols,xmltable(('ora:view("'||table_name||'")/ROW/'||column_name||'[ora:contains(text(),"%'|| 'abc' || '%") > 0]')
columns result varchar2(10) path '.'
where table_name in ('TEST');
and i get: ORA-00933: SQL command not properly ended it points over '*xmltable*'ok, its possible to get output from a xml like this.
i need output like this,
customerid CustomerName Country
1 xxxx 4
2 yyyy 5
xml:
<Customer>
<CustomerInformation>
<Customerid>1</Customerid>
<CustomerName>xxxx</CustomerName>
<Country>4</Country>
</CustomerInformation>
<CustomerInformation>
<Customerid>2</Customerid>
<CustomerName>yyyy</CustomerName>
<Country>5</Country>
</CustomerInformation>
</Customer>
This xml is input to my stored procedure, i need to insert the xml tag values into customner_table.
For this i insert the xml inro a xml_document_table having a xmltype column.
after , by using the below mentioned query to select xml_tag values from that column.
when i execute this query
INSERT into customer_table(customer_id)
SELECT X.XML_DOCUMENT.extract('/Customer/commodityInfo/CustomerInformation/Customerid/text()').getStringVal() "Customerid" from XML_DOCUMENT_TABLE X;
i got output in a single row.
customerid_
1 <next line> 2
But i need output like this,
Customerid_
1
2
im struggling with this simple insert. pls share ur idea.....
Edited by: 887268 on Apr 4, 2012 10:04 PM
Edited by: 887268 on Apr 4, 2012 10:17 PM -
Crystal Report performance - subreports or sql command?
Hello,
bit of quandary, I've an existing report that contains six subreports all sharing the same parameter to the main report, a 'projectID' field.
The main report approximately returns 300 records/projects and each of the 6 subreports are passed the corresponding 'projectID' field 300 times.
Now, I've succesfully incorporated the main report query and corresponding subreports into a TSQL command containing a number of subqueries in the Select clause:
SELECT PROJECT.PROJECTID, PROJECT.TITLE, PROJECT.REFERENCE, PROJECTSTATUS.PROJECTSTATUS, PROJECT.INPUT_DATE
,(SELECT max(INPUT_DATE) FROM V_PROJECT_NOTE AS VPN
WHERE PROJECT.PROJECTID = VPN.PROJECTID) AS LastHeadline
,(SELECT
MAX(CASE
WHEN MODIFIED_DATE IS NULL THEN INPUT_DATE
WHEN INPUT_DATE > MODIFIED_DATE THEN INPUT_DATE
ELSE MODIFIED_DATE
END) FROM ISSUE WHERE PROJECT.PROJECTID = ISSUE.PROJECTID) AS LastNewIssue
,(SELECT max(ISSUENOTE.INPUT_DATE) FROM ISSUE
INNER JOIN ISSUENOTE ON ISSUE.ISSUEID = ISSUENOTE.ISSUEID
WHERE PROJECT.PROJECTID = ISSUE.PROJECTID ) AS LastIssueNote
,(SELECT max(modified_date) FROM V_PROJECT_RISK_LAST_AMMENDED AS VPR
WHERE PROJECT.PROJECTID = VPR.PROJECTID) AS LastRiskLogUpdate
,(SELECT max(INPUT_DATE) FROM PROJECT_CHECKLIST AS PC
WHERE PROJECT.PROJECTID = PC.PROJECTID) AS LastChecklistUpdate
,(SELECT max(input_date) FROM V_PROJECT_ACTIVITY_LAST_AMMENDED AS VPA
WHERE PROJECT.PROJECTID = VPA.PROJECTID) AS LastGANTTUpdate
,V_PROJECT_KEYCONTACT.USERNAME AS KeyContact
,(SELECT USERPROFILE.USERNAME AS Supervisor
FROM USERPROFILE INNER JOIN
PROJECT_MEMBER AS SUPERVISOR ON USERPROFILE.USERID = SUPERVISOR.USERID RIGHT OUTER JOIN
PROJECT_MEMBER AS KEYCONTACT ON SUPERVISOR.PROJECT_MEMBERID = KEYCONTACT.PARENTID
WHERE PROJECT.PROJECTID = KEYCONTACT.PROJECTID
AND KEYCONTACT.KEY_CONTACT =1) AS Supervisor
FROM PROJECT INNER JOIN
PROJECTSTATUS ON PROJECT.PROJECTSTATUSID = PROJECTSTATUS.PROJECTSTATUSID LEFT OUTER JOIN
V_PROJECT_KEYCONTACT ON PROJECT.PROJECTID = V_PROJECT_KEYCONTACT.PROJECTID
WHERE V_PROJECT_KEYCONTACT.USERNAME IN ('aaa','bbb','ccc')
AND (PROJECTSTATUS.PROJECTSTATUS IN ('111', '222', '333'))
AND ((PROJECT.TITLE NOT LIKE 'xxx%') AND (PROJECT.TITLE NOT LIKE 'yyy%') AND (PROJECT.TITLE NOT LIKE 'zzz%'))
ORDER BY V_PROJECT_KEYCONTACT.USERNAME, PROJECT.INPUT_DATE
Now, I've run both SQL Server Profiler and looked at the Performance Information in Crystal and the SQL command method is an order of magnitude less efficient!!
I may have to post my query on a TSQL forum but was wondering if anyone on here can possible shed any light on it?
Thanks in advance,
DomDom,
I assume that the last edit was to remove a few curse words...
The reality is that we can give a good explanation as to why the sub-report version would execute faster that the command version w/o seeing the report (with the sub-reports included).
Looking at the SQL, I can tell that it's a fairly expensive query, firing several sub-queries for every row returned by the outer query. That said, I sounds like the same thing is taking place with the sub-report version too... So I would think that the performance would be similar.
The only thing that I can think of, and this is just a guess... With the sub-report version, each all queries are being run independently and then combined locally by CR, whereas the command version, everything is combined. The more complex the query, the harder the optimizer has to work to come up with the best execution plan... and the greater the likelihood that that the resulting plan isn't as optimized as it could be.
That said, I'd still think the command version would be faster over all. Are you seeing real differences between the two reports, in the amount of time that it takes from refresh to final render?
Either way, I think moving all of those sub-queries from the select list (where they are executing once for every row) down to the FROM area (where they only have to execute once) should increase the speed dramatically and surpass the sub-report version by a decent margin.
Give this version of your SQL a test drive and see if it yields an improvement.
SELECT
PROJECT.PROJECTID,
PROJECT.TITLE,
PROJECT.REFERENCE,
PROJECTSTATUS.PROJECTSTATUS,
PROJECT.INPUT_DATE,
VPN.LastHeadline,
ISSUE.LastNewIssue,
ISSUE_NOTE.LastIssueNote,
VPR.LastRiskLogUpdate,
PC.LastChecklistUpdate,
VPA.LastGANTTUpdate,
V_PROJECT_KEYCONTACT.USERNAME AS KeyContact,
Supervisor.Supervisor
FROM PROJECT
INNER JOIN PROJECTSTATUS ON PROJECT.PROJECTSTATUSID = PROJECTSTATUS.PROJECTSTATUSID
LEFT OUTER JOIN V_PROJECT_KEYCONTACT ON PROJECT.PROJECTID = V_PROJECT_KEYCONTACT.PROJECTID
LEFT OUTER JOIN (
SELECT PROJECTID,
max(INPUT_DATE) AS LastHeadline
FROM V_PROJECT_NOTE
GROUP BYPROJECTID) AS VPN ON PROJECT.PROJECTID = VPN.PROJECTID
LEFT OUTER JOIN (
SELECT PROJECTID,
MAX(CASE
WHEN MODIFIED_DATE IS NULL THEN INPUT_DATE
WHEN INPUT_DATE > MODIFIED_DATE THEN INPUT_DATE
ELSE MODIFIED_DATE END) AS LastNewIssue
FROM ISSUE
GROUP BY PROJECTID) AS ISSUE ON PROJECT.PROJECTID = ISSUE.PROJECTID
LEFT OUTER JOIN (
SELECT ISSUE.PROJECTID,
max(ISSUENOTE.INPUT_DATE) AS LastIssueNote
FROM ISSUE
INNER JOIN ISSUENOTE ON ISSUE.ISSUEID = ISSUENOTE.ISSUEID
GROUP BY ISSUE.PROJECTID) AS ISSUE_NOTE ON PROJECT.PROJECTID = ISSUE_NOTE.PROJECTID
LEFT OUTER JOIN (
SELECT PROJECTID,
max(modified_date) AS LastRiskLogUpdate
FROM V_PROJECT_RISK_LAST_AMMENDED
GROUP BY PROJECTID) AS VPR ON PROJECT.PROJECTID = VPR.PROJECTID
LEFT OUTER JOIN (
SELECT PROJECTID,
max(INPUT_DATE) AS LastChecklistUpdate
FROM PROJECT_CHECKLIST
GROUP BY PROJECTID) AS PC ON PROJECT.PROJECTID = PC.PROJECTID
LEFT OUTER JOIN (
SELECT PROJECTID,
max(input_date) AS LastGANTTUpdate
FROM V_PROJECT_ACTIVITY_LAST_AMMENDED
GROUP BY PROJECTID) AS VPA ON PROJECT.PROJECTID = VPA.PROJECTID
LEFT OUTER JOIN (
SELECT PROJECTID,
USERPROFILE.USERNAME AS Supervisor
FROM USERPROFILE
INNER JOIN PROJECT_MEMBER AS SUPERVISOR ON USERPROFILE.USERID = SUPERVISOR.USERID RIGHT
OUTER JOIN PROJECT_MEMBER AS KEYCONTACT ON SUPERVISOR.PROJECT_MEMBERID = KEYCONTACT.PARENTID
WHERE KEYCONTACT.KEY_CONTACT =1) AS Supervisor ON PROJECT.PROJECTID = Supervisor.PROJECTID
WHERE V_PROJECT_KEYCONTACT.USERNAME IN ('aaa','bbb','ccc')
AND (PROJECTSTATUS.PROJECTSTATUS IN ('111', '222', '333'))
AND ((PROJECT.TITLE NOT LIKE 'xxx%')
AND (PROJECT.TITLE NOT LIKE 'yyy%')
AND (PROJECT.TITLE NOT LIKE 'zzz%'))
ORDER BY V_PROJECT_KEYCONTACT.USERNAME, PROJECT.INPUT_DATE
HTH,
Jason -
Without using SubReport or SQL Command in Main Report, get desired results without duplicating
It seems so simple. I just need the cost, at a certain time (based on a parameter), for each item. I wrote a SQL Command that works beautifully, but when it connects to the existing report, it slows to a horrible crawl and cannot be used for tables with over 4 million records. Here is the SQL Command that provides the desired results:
SELECT TOP 1 WITH TIES "INVENTITEMPRICE"."ITEMID", "INVENTITEMPRICE"."PRICETYPE", "INVENTITEMPRICE"."MARKUP", "INVENTITEMPRICE"."PRICEUNIT", "INVENTITEMPRICE"."PRICE", "INVENTITEMPRICE"."PRICEQTY", "INVENTITEMPRICE"."ACTIVATIONDATE", "INVENTITEMPRICE"."DATAAREAID"
FROM ("AX09PROD"."dbo"."INVENTITEMPRICE" "INVENTITEMPRICE" INNER JOIN "AX09PROD"."dbo"."INVENTTABLE" "INVENTTABLE" ON (("INVENTITEMPRICE"."ITEMID"="INVENTTABLE"."ITEMID") AND ("INVENTITEMPRICE"."DATAAREAID"="INVENTTABLE"."DATAAREAID")))
WHERE ("INVENTITEMPRICE"."DATAAREAID"=N'TMC' AND "INVENTITEMPRICE"."PRICETYPE"=0 AND "INVENTITEMPRICE"."ACTIVATIONDATE"<={?As Of Date})
ORDER BY ROW_NUMBER () OVER(PARTITION BY "INVENTITEMPRICE"."ITEMID" ORDER BY "INVENTITEMPRICE"."ACTIVATIONDATE" DESC)
I've attached the report with saved data. However, when I remove the restrictions of just certain items, it is unusable as it is SO SLOW!
I can also get the desired results from using a subreport but it takes forever to export due to the number of records/items. Whenever possible, I avoid subreports for this reason. I've attached that report with data as well.
Please be patient as I'm not savvy in SQL, but decent in generating reports. What am I doing wrong? This seems SO simple. The premise is that I want the corresponding information based on the date entered: If the date entered is 3/15/2014, the result should be 91.15 as indicated below. I'd simply like this value to be placed in a formula per item.
Item 80014:
Activation Date
Cost Price
6/2/2014
104.43
4/1/2014
91.58
3/1/2014
91.15
2/1/2014
92.89
1/1/2014
93.57
Any assistance would be GREATLY appreciated!
Thanks!
Teena
Update: I was unable to attach the reports with .rpt or .txt extensions. There were well under 1MB. Any suggestions?hi Teena,
if you're going the inline subquery route, try something like the following...the last line in the sub-query 'where' clause should in theory take care of matching the correct price based on relating the item id's between your cost price & inventory data. this should leave you with distinct values for each itemid then. hopefully it won't error out as i'm just guessing on the syntax.
SELECT DISTINCT
"INVENTTABLE"."ITEMID",
"INVENTTRANS"."DATAAREAID",
"INVENTTRANS"."DATEPHYSICAL",
"INVENTTRANS"."QTY",
"INVENTTABLE"."ITEMGROUPID",
"INVENTTABLE"."ITEMNAME",
"INVENTTRANS"."TRANSREFID",
"INVENTTRANS"."STATUSISSUE",
"INVENTTABLE"."ITEMTYPE",
"INVENTTRANS"."TRANSTYPE",
"INVENTTRANS"."RECID",
"INVENTTRANS"."DIRECTION",
SELECT TOP 1 "INVENTITEMPRICE"."PRICE"
FROM "AX09PROD"."dbo"."INVENTITEMPRICE" "INVENTITEMPRICE"
WHERE "INVENTITEMPRICE"."DATAAREAID" LIKE 'TMC%'
AND "INVENTITEMPRICE"."PRICETYPE"=0
AND "INVENTITEMPRICE"."ACTIVATIONDATE"<={?As Of Date}
AND "INVENTITEMPRICE"."ITEMID" = "INVENTTABLE"."ITEMID"
ORDER BY "INVENTITEMPRICE"."ACTIVATIONDATE" DESC
) AS ITEMPRICE
FROM
"AX09PROD"."dbo"."INVENTTABLE" "INVENTTABLE"
LEFT OUTER JOIN "AX09PROD"."dbo"."INVENTTRANS" "INVENTTRANS"
ON ("INVENTTABLE"."DATAAREAID"="INVENTTRANS"."DATAAREAID")
AND ("INVENTTABLE"."ITEMID"="INVENTTRANS"."ITEMID")
WHERE
"INVENTTRANS"."DATAAREAID" LIKE 'TMC%'
AND (("INVENTTABLE"."ITEMGROUPID" LIKE 'RAW%') OR ("INVENTTABLE"."ITEMGROUPID" BETWEEN '000' AND '999') OR ("INVENTTABLE"."ITEMGROUPID" LIKE 'Ship_Box'))
AND "INVENTTABLE"."ITEMTYPE" IN (0,1)
ORDER BY
"INVENTTABLE"."ITEMGROUPID",
"INVENTTABLE"."ITEMID",
"INVENTTRANS"."DATEPHYSICAL" ASC
Message was edited by: Jamie Wiseman
Maybe you are looking for
-
Can`t install Premiere 5.0 on my Windows 7 64 bit?
When I press the setup.exe, it says I cant run this file on my 64 bit system. What to do?
-
I bought the iphone 4s about a year ago, he was not new. The seller told me that he did the factory unlock, but he lied. Now I live in Russia and want to use the iPhone with a local GSM sim card. Serial number (removed), IMEI (removed). Thank you! Pe
-
Folks; Another question in the same vein as one earlier today... Is there a way to get the name of a variable? Unsurprisingly, neither of these attempts work: 1) set x to "Test Value" set y to (name of x) -- what I want is y to be 'x' OR 2) set x to
-
Use QuickTime Pro to extract audio from VCD
Can I use QuickTime Pro to extract the audio from a VCD? after that, I would like to convert that audio file to an mp3.
-
Cannot download the new os into itunes
i have a 2 month old ipad2 and it is having some issues with opening email. i went to restore it and it started the process to download a new os. when i try to download the new operating system into itunes i get the mesg that the network timed out.