SQL Syntax - help needed
Guys,
Help me understand the syntax please!! With PL/SQL I have achieved a task quite easily, with a branch of code to include or exclude some part of the query - no problem. But to use SQL ......
If i have a variable on a page, say :p10_open_or_closed
.. and I set the value of this to the text "Is Not Null"
How can I incorporate this into an SQL query, say
Select ID, Date1, Date2, Comment
From Table1
where Date1 Is Not Null
Is there a way of substituting the ":p10_open_or_closed" variable into this query?
ie
Select ID, Date1, Date2, Comment
From Table1
where Date1 ":p10_open_or_closed"
Thanks.
Thanks for your help gents.
Originally, I had a PL/SQL Statement constructing the code as needed, as Rekha
suggested.
if :P1_OPEN_OR_CLOSED = 1 then
q:=q||' and ';
q:=q||' p.ACTUAL_INSTALL_DATE is null ';
end if;
if :P1_OPEN_OR_CLOSED = 2 then
q:=q||' and ';
q:=q||' p.ACTUAL_INSTALL_DATE is not null ';
end if;
But, to use a Tabular form, where users can update fields of multiple records on screen then submit for a MRU, the option of PL/SQL code is not allowed, only SQL. So Phil UK, no it's not an elegant way of doing things, but I'm forced to use SQL, yeah?
There are definitely ways that I can filter for the solution I am after, but they all involve more in depth solutions (that are not that great). Thus, I asked at this forum.
Andy, your solution works :~) which makes me very happy. I'm not sure how just now but I'll learn from it.
Thanks again.
Similar Messages
-
Having trouble with SQLServer 2008 (not MySQL) and my database connection in Dreamweaver CS6. My document type is set as .asp using VBScript. I can list the table information but cannot use the insert wizard to add new records. I don't get any errors after creating the insert form, but no records get inserted. I'm not a VBScript expert, but do I have to manually write some code to insert records? How do I attach it to a button?
Thanks for the quick reply. I won't be back in the office for a few days, but I'll try to post it when I get back in. It's pretty much the code generated from the Dreamweaver Insert Record wizard. I see where the submit button is created and the value is set but the action on the form is set to MM_insert, so I don't see where the submit code is actually called.
Date: Wed, 3 Oct 2012 12:06:14 -0600
From: [email protected]
To: [email protected]
Subject: SQL Server2008 help needed
Re: SQL Server2008 help needed
created by bregent in Dreamweaver General - View the full discussion
This post should be moved to the app dev forum. Please post the code from your form and the insert script pages.
Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/4746757#4746757
Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4746757#4746757
To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4746757#4746757. In the Actions box on the right, click the Stop Email Notifications link.
Start a new discussion in Dreamweaver General by email or at Adobe Community
For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746. -
SQL problem - help needed ASAP!!
Hey guys,
Doing a college project... would really appreciate some help. I am trying to use a variable in the where clause of a select cursor in PL/SQL. The code is this:
procedure results(p_search_entry varchar2, p_search_field varchar2) is
cursor c_results is
select * from physics_b where p_search_field = p_search_entry;
begin
for cv_results in c_results
loop
-- loop through actions
end loop;
The problem is that I don't know how to get the where clause to accept the variable passed into the procedure as the field name. Does anyone know the syntax for this?
Thanks very much!
NiallThis isn't the correct forum for this kind of question. The SQL and PL/SQL forum PL/SQL is probably best.
That said, you can't do what you want that way.
You can do
procedure results (p_search_entry in varchar2)
cursor c_result is
select * fro physics_b where subject=p_search_entry;(assuming subject is a column in physics_b)
You can't use a variable to represent a column directly. You need to build the statement as a string and then use execute immediate.
statement:='select * fro physics_b where '||p_search_field||' = :1';
-- this bit is probably bad syntax.
execute immediate statement using p_search_entry;Look up execute immediate and bind variables -
Hi All,
I am creating a report which is having 2 sql queries ,1 for the main columns that i need to show and 2 from total sum and count.
Report is something as given below
SET TAB OFF;
set linesize 1500;
set pagesize 50;
SET FEEDBACK OFF;
SET WRAP OFF
COLUMN today NEW_VALUE VAR1 NOPRINT;
TTITLE LEFT 'ABC Inc.' SKIP 1 -
LEFT 'Daily Report' SKIP 1 -
LEFT 'As Of ' VAR1 SKIP 2
BTITLE LEFT SKIP 'Page No : ' FORMAT 9999999999 SQL.PNO SKIP 3;
COL SR_NO HEADING 'Seq' FORMAT 999999;
COL REFNO HEADING 'Ref No' FORMAT A20;
COL ORIG_NAME HEADING ' Branch Name'
FORMAT A50;
SELECT ROWNUM SR_NO,
REF_NO REFNO,
ORIGIN_NAME BRNAME
FROM BANK
WHERE PASS_CD=101
SELECT ' Failure Count : '|| NVL(COUNT(DECODE(CODE,1,CODE,NULL)),0) ||
' Failure Total Amt : '|| NVL(SUM(DECODE(CODE,799,AMT,NULL)),0)
|| CHR(10) ||
' Successful Count : '|| NVL(COUNT(DECODE(CODE,000,CODE,NULL)),0) ||
' Successful Total Amt: '|| NVL(SUM(DECODE(CODE,000,AMT,NULL)),0)
FROM BANK;
CLEAR BREAKS;
CLEAR COLUMN;
TTITLE OFF;
When i am running this second query output is going to secong page and title is repeated again and same as 1rst page is showing page no-1
Kindly help me,i want the output on the same page at bottom.
Thanksi think its only work in ISQL* PLUS enivironment iam
not sure.It does work in SQL*Plus
is that i can use in the package??http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12048.htm -
Oracle 11G Install on Win 7 With PL/SQL Developer Help Needed
Today is my first day with Oracle. I have tried to Install Ora11g from our network drive.I think the installation went fine. I also installated PL/SQL Developer when i try to log in i got the following error see below.
PL/SQL Developer - (Not logged on)
Initialization error
SQL*Net not properly installed
OracleHomeKey: SOFTWARE\ORACLE
OracleHomeDir:
OK
After i did some research online i found this solution "go to Tools > Preferences > options set manually "Oracle Home" to the folder of ORACLE_HOME and "OCI Library" to the oci.dll file located in ORACLE_HOME/bin/oci.dll"
C:\app\user\product\11.2.0\client_1\bin.dll <=== I believe this is my Oracle_Home
C:\app\user\product\11.2.0\client_1\bin\oci.dll <==== Is my OCI Library.
When i apply thse 2 paths i get the following error.
Initialization error
COuld not load " C:\app\user\product\11.2.0\client_1\bin.dll
OCIDLL forced to C:\app\user\product\11.2.0\client_1\bin.dll
LoadLibrary(C:\app\user\product\11.2.0\client_1\bin\.dll)returned 0
Can someone help me with this ???????????????/Pl indicate which version of Win 7 - you will need Professional or higher - Home versions are not supported/certified, so things may or may not work as expected.
http://download.oracle.com/docs/cd/E11882_01/install.112/e16773/reqs.htm#CHDHGGFE
HTH
Srini -
How to optimize this SQL. Help needed.
Hi All,
Can you please help with this SQL:
SELECT /*+ INDEX(zl1 zipcode_lat1) */
zl2.zipcode as zipcode,l.location_id as location_id,
sqrt(POWER((69.1 * ((zl2.latitude*57.295779513082320876798154814105) - (zl1.latitude*57.295779513082320876798154814105))),2) + POWER((69.1 * ((zl2.longitude*57.295779513082320876798154814105) - (zl1.longitude*57.295779513082320876798154814105)) * cos((zl1.latitude*57.295779513082320876798154814105)/57.3)),2)) as distance
FROM location_atao l, zipcode_atao zl1, client c, zipcode_atao zl2
WHERE zl1.zipcode = l.zipcode
AND l.client_id = c.client_id
AND c.client_id = 306363
And l.appType = 'HOURLY'
and c.milessearchzipcode >= sqrt(POWER((69.1 * ((zl2.latitude*57.295779513082320876798154814105) - (zl1.latitude*57.295779513082320876798154814105))),2) + POWER((69.1 * ((zl2.longitude*57.295779513082320876798154814105) - (zl1.longitude*57.295779513082320876798154814105)) * cos((zl1.latitude*57.295779513082320876798154814105)/57.3)),2))
I tried to optimize it by adding country column in zipcode_atao table. So that we can limit the search in zipcode_atao table based on country.
Any other suggestions.
ThanksWelcome to the forum.
Please follow the instructions given in this thread:
How to post a SQL statement tuning request
HOW TO: Post a SQL statement tuning request - template posting
and add the nessecary details we need to your thread.
Depending on your database version (the result of: select * from v$version; ):
Have you tried running the query without the index-hint?
Are your table (and index) statatistics up-to-date? -
Hi,
I normally get a csv having data as
column1 ;columnb;columnc;
13 ; 12 ; 13 ;
11 ;13 ;33;
as the table where it needs to go is say table
xys( a number, b number , c number).
so the control file is fairly simple ...
But from now I need to restrict data entry if the change in format happens in the csv
say if it is like
column2;column1;column3,
12,13;12;
11;13;14;
or say the csv like
column1;column2;column3;column4;
11;13;14;15;
111;134;14;12;
in both cases sql loader should not run and throw the error saying the reason in the log.
how do i manage it in the control file `???
any ideas???
regards
Message was edited by:
SHUBHHello,
do you only need to check the first line of the file if it contains a line like
column1;column2;column3 ?
If yes, maybe a small script like this could be a starting point:
You have to replace "column1;column2;column3" with the header information that's valid and instead of file1 in the CURRENTSTRING=... Line write the name of your input file.
I hope this helps. (But maybe some of the experts here knows a way to do the verification checks with SQLLDR, so maybe its worth to wait a little bit :)
#!/bin/ksh
VALIDSTRING="column1;column2;column3"
CURRENTSTRING=`head -n 1 file1`
if [[ $VALIDSTRING == $CURRENTSTRING ]]
then
echo "They match."
else
echo "They dont match."
fi
-- -
Hello,
I am in need of some SQL help as I am not sure how to do it. I want to only return rows of data that meet the following criteria:
1) in tableA columnA it could have a value shown as such: A,B,1,2,3,5,8
2) in tableA columnB it shows one of the following four variables (Test1, Test2, Test3, Test4)
3) in tableA columnC it will show a date.
4) in tableB there is a row for each day of the year.
5) in tableB there is a column that matches each of the four variables in #2 above.
First it should match the date in tableA ColumnC to the row in tableB that matches. Then it should then find the column in tableB that matches to the value in tableA columnB. in that cell it will have a single value from A-D or 1-9. If it is an A for example, it will need to check against tableA columnA. if it has an A in it, it will return it. If it does not, it will not.
Does anyone have any idea how to write this? Is this possible?
Thank you,
JeffCheck the query using hardcoded values first - values taken from your explication
select x.idfield
from tablea x,
(select datedefinefield,
'VARIABLE4' the_variable,
case 'VARIABLE4' when 'VARIABLE1'
then variable1
when 'VARIABLE2'
then variable2
when 'VARIABLE3'
then variable3
when 'VARIABLE4'
then variable4
end the_value
from tableb
where datedefinefield = date '2013-01-01'
) y
where x.datefield = y.datedefinefield
and x.variablefield = y.the_variable
and instr(','||x.codefield||',',','||y.the_value||',') > 0
then replace the hardcoded values with bind variables
select x.idfield
from tablea x,
(select datedefinefield,
:the_variable the_variable,
case :the_variable when 'VARIABLE1'
then variable1
when 'VARIABLE2'
then variable2
when 'VARIABLE3'
then variable3
when 'VARIABLE4'
then variable4
end the_value
from tableb
where datedefinefield = to_date(:the_date,'yyyymmdd')
) y
where x.datefield = y.datedefinefield
and x.variablefield = y.the_variable
and instr(','||x.codefield||',',','||y.the_value||',') > 0
type the values in the window SQL Developer displays before execution to prompt you for bind variable values
VARIABLE4 for the_variable
20130101 for the_date
no quotes this time then hit the Apply ( not very sure that's the caption) button to start execution and you should get the same result as with hardcoded values.
If that works, you can start playing with (submitting values of your choice)
Regards
Etbin -
Based on your inputs-I studied and created the below objects.I apologise for asking lengthy questions,but i
need your help very much now to proceed next.
There is a COMPANY WHICH has many divisions/departments in it.
These divisions has employees.
*{color:#0000ff}--Created employee table which employee_id and Salary.*
**employees (*empid,salary){color}*
*{color:#0000ff}***DO i need to put the DEPT_ID and Manager_id in the EMPLOYEES table? {color}*
*{color:#0000ff}--Presently,iCreated a relationship table to have EMPLOYEE"S MANAGER information.a manager is an employee itself.{color}*
*{color:#0000ff}--Created a table for EMPLOyee and department---RELATIONSHIP ---> empl_id and dept_id{color}*
The COMPANY has numerous Products(also we can say projects) and these project work is done by the various depts.
*{color:#0000ff}Projects /Job table*
*--job_id*
*--Project_name*
*--Budget Amount{color}*
*{color:#0000ff}--Created a table for Project and department---RELATIONSHIP ---> proj_id and dept_id*
*--Also,Created a table for Project and Employee---RELATIONSHIP ---> proj_id and employee_id{color}*
Also,here scenario (1)Employees can work or be a part of many or multiple departments and work for multiple projects/products at a time (2)As usual-each Department has a manager.**EVery dept can handle or work only on one project.
*{color:#0000ff}--Created a table for Project and department---RELATIONSHIP ---> proj_id and dept_id*
*--Also,Created a table for Project and Employee---RELATIONSHIP ---> proj_id and employee_id*
*{color}*
_*{color:#000000}***(1)Are the tables and the relationships defined above enough or have i created too much tables?Please advise me.{color}*_
Queries:-Need to write SQLs for below items.Please help me.Could you all have a look
bq. h5. {color:#0000ff} \\ _ (2)SQL for a person see all his manager?***A person can have 2,3 managers._ \\ _ (3)need a person--->manager-->and their manager's MANAGER_ \\ _ (4)How will managers to view all employees reporting to him._ \\ {color} \\ h5. \\ {color:#0000ff}_(5)feasibility (SQL) to support the increase of salaries of employees in a department by percentage or amount wise._ \\ _ (6)SQL to update or change manager of a department/employee._ \\ {color} \\ h5. \\ {color:#0000ff}_(7)If a employee is removed-then all related details should also be removed._ \\ _ (8)to remove person and department,terminate a person from organisation_ \\ _ SHIFTING a person to different department,assign a person to a department_{color} \\ h5. {color:#0000ff}_SQL to collect all info of a person, his managers , departments and project this employee works._ \\ _ find Department which dont have managers._{color} \\ h5. \\ {color:#0000ff}_****find expenditure all projects together in terms of salary_{color}Sorry for all the confusion with the questions.So let me clear myself,i am doing this not as assignment or homework,but something
which interests me and trying to leran.Earlier as I stated that its a part of my school(** well frnakly speaking, it was my plan if i could
put this as an item of the school as the scope is very huge.
*(1)one employee can be in many departments(1 TO MANY) and and each department has one manager.(1 to 1)*
Created a table for EMPLOyee and department-RELATIONSHIP ---> empl_id and dept_id*
(2)Also,an employee can work in multiple items/projects(1-MANY) at a time. And a project HAS only one department.(1 to 1)
**Projects table created has codes,the Project name ,Planned budget cost/amount, start_date and end_date AND DEPART_ID
Also,Created a table for Project and Employee-RELATIONSHIP ---> proj_id and employee_id*
This is the full scenario has put above.So,i needed help as I am very confused if i have done the correct relationships.
And,these below items are my plans to allow the schema nd tables support it.
(2)how will a person see all his manager?***A person can have 2,3 managers.(EMP->MANAGER relationship TABLE)
(3)SQL to be able to show a person--->manager-->and their manager's MANAGER
(4)How will managers to view all employees reporting to him.
(5)SQL to support the increase of salaries of employees in a department by percentage or amount wise.
(6)SQL to update or change manager of a department/employee.
(7)If a employee is removed-then all related details should also be removed.
(8)to remove person and department,terminate a person from organisation
SHIFTING a person to different department,assign a person to a department
Projects /Job table EMPLOYEES TABLE-> SALARY info
--job_id
--Project_name
--Budget Amount -
I'm having trouble with an SQL query. I've created a simple logon page wherein a user will enter their user name and password. The program will look in an Access database for the user name, sort it by Date/Time modified, and check to see if their password matches the most recent password. Unfortunately, the query returns no results. I'm absolutely certain that I'm doing the query correctly (I've imported it directly from my old VB6 code). Something simple is eluding me. Any help would be appreciated.
private void LogOn() {
//make sure that the user name/password is valid, then load the main menu
try {
//open the database connection
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:LawOffice2000", "", "");
Statement select = con.createStatement();
String strTemp = "Select * From EMPLOYEES Where INITIALS = '" + txtUserName.getText() + "' Order By DATE Desc, TIME Desc";
ResultSet result = select.executeQuery(strTemp);
while(result.next()) {
if (txtPassword.getPassword().toString() == result.getString("Password")) {
MenuMain.main();
else {
System.out.println("Password Bad");
System.out.println(txtUserName.getText());
System.out.println(result.getString("Password"));
break; //exit loop
//close the connection
con.close(); }
catch (Exception e) {
System.out.println("LawOfficeSuite_LogOn: " + e);
return; }
}The problem is here: "txtPassword.getPassword().toString() == result.getString("Password"))"
Don't confuse String's equals() method with the equality operator '=='. The == operator checks that two references refer to the same object. If you want to compare the contents of Strings (whether two strings contain the same characters), use equals(), e.g. if (str1.equals(str2))...
Example:String s1 = "foo";
String s2 = new String("foo");
System.out.println("s1 == s2: " + (s1 == s2)); // false
System.out.println("s1.equals(s2): " + (s1.equals(s2))); // trueFor more information, check out Comparison operators: equals() versus == -
Syntax help needed in update using 'WITH' Clause
Update CP_JP_CORP_FSASA_FEEDUPLOAD_r r
set (
gfrn,
tenor_code,
tenor_description,
exposure_category,
frr,
facility_classification,
limit_amount,
limit_usd,
approval_ccy,
approval_date,
expiry_date,
avail_status_code,
avail_status_desc,
revolving_indicator,
committed_flag,
committed_until_date,
committed_amount,
advised_flag,
advised_amount,
facility_long_description,
booking_unit_code,
extending_unit_code,
extending_unit_short_desc,
approving_unit_code,
approving_unit_short_des,
transaction_type,
branch_no
=
With t as
Select fac.gfrn,fac.tenor_code,fac.tenor_description,fac.exposure_category,fac.frr,
fac.facility_classification,fac.limit_amount,fac.limit_usd,fac.approval_ccy,
fac.approval_date,fac.expiry_date,fac.avail_status_code,fac.avail_status_desc,
fac.revolving_indicator,fac.committed_flag,fac.committed_until_date,fac.committed_amount,
fac.advised_flag,fac.advised_amount,fac.facility_long_description,fac.booking_unit_code,
fac.extending_unit_code,fac.extending_unit_short_desc,fac.approving_unit_code,fac.approving_unit_short_des,
/*'Check' normalflag,
cust.adjusted_orr fsasaorr1stborrower,
'Normal' category1stborrower,
cust.adjusted_orr fsasaorr2ndborrower,
'Normal' category2ndborrower,
cust.adjusted_orr fsasaorrfinal,
'Normal' categoryfinal */
txn.transaction_type,txn.branch_no,txn.gfcid,txn.transaction_id
from cp_fsa_boj_corp_cr_fac_hist fac,
--cp_fsa_boj_corp_cr_cust_hist cust,
cp_fsa_boj_corp_cr_txn_hist txn
where fac.gfcid = txn.gfcid
and fac.facility_id = txn.facility_id
and fac.as_of_date = txn.as_of_date
and to_char(fac.as_of_date,'yyyymm') = p_financial_period
and fac.as_of_date = last_day(fac.as_of_date)
select t.gfrn,
t.tenor_code,
t.tenor_description,
t.exposure_category,
t.frr,
t.facility_classification,
t.limit_amount,
t.limit_usd,
t.approval_ccy,
t.approval_date,
t.expiry_date,
t.avail_status_code,
t.avail_status_desc,
t.revolving_indicator,
t.committed_flag,
t.committed_until_date,
t.committed_amount,
t.advised_flag,
t.advised_amount,
t.facility_long_description
t.booking_unit_code,
t.extending_unit_code,
t.extending_unit_short_desc,
t.approving_unit_code,
t.approving_unit_short_des,
t.transaction_type,
t.branch_no
from t
where r.financialperiod = p_financial_period
and exists
Select 1
from t
where t.transaction_id = r.ce_trans_id
)I'm facing syntax problemHii All,
This is my actual update.(I stopped performing dml operations in cursors following Karthick Arp) :-)
Update CP_JP_CORP_FSASA_FEEDUPLOAD_r r
set (
gfrn,
tenor_code,
tenor_description,
exposure_category,
frr,
facility_classification,
limit_amount,
limit_usd,
approval_ccy,
approval_date,
expiry_date,
avail_status_code,
avail_status_desc,
revolving_indicator,
committed_flag,
committed_until_date,
committed_amount,
advised_flag,
advised_amount,
facility_long_description,
booking_unit_code,
extending_unit_code,
extending_unit_short_desc,
approving_unit_code,
approving_unit_short_des,
transaction_type,
branch_no
= (
Select fac.gfrn,fac.tenor_code,fac.tenor_description,fac.exposure_category,fac.frr,
fac.facility_classification,fac.limit_amount,fac.limit_usd,fac.approval_ccy,
fac.approval_date,fac.expiry_date,fac.avail_status_code,fac.avail_status_desc,
fac.revolving_indicator,fac.committed_flag,fac.committed_until_date,fac.committed_amount,
fac.advised_flag,fac.advised_amount,fac.facility_long_description,fac.booking_unit_code,
fac.extending_unit_code,fac.extending_unit_short_desc,fac.approving_unit_code,fac.approving_unit_short_des,
txn.transaction_type,txn.branch_no
from cp_fsa_boj_corp_cr_fac_hist fac,
--cp_fsa_boj_corp_cr_cust_hist cust,
cp_fsa_boj_corp_cr_txn_hist txn
where fac.gfcid = txn.gfcid
and fac.facility_id = txn.facility_id
and fac.as_of_date = txn.as_of_date
and to_char(fac.as_of_date,'yyyymm') = p_financial_period
and fac.as_of_date = last_day(fac.as_of_date)
where Exists
Select 1
from cp_fsa_boj_corp_cr_fac_hist fac,
cp_fsa_boj_corp_cr_txn_hist txn
where fac.gfcid = txn.gfcid
and fac.facility_id = txn.facility_id
and fac.as_of_date = txn.as_of_date
and to_char(fac.as_of_date,'yyyymm') = p_financial_period
and fac.as_of_date = last_day(fac.as_of_date)
and txn.transaction_id = r.ce_trans_id
)Now in my update I'm using same 'SELECT' twice once in 'SET' and again in 'EXISTS' clause. I'd like to make use of 'WITH' Clause and avoid unnecessary 'SELECT' . Please help me. -
I am sure some of you will laugh lol, but I am drawing a blank and need some assistance if anyone is willing to help:
I have this query:
SELECT DISTINCT ID
FROM (SELECT productcode
FROM sforce_product2
WHERE productcode NOT LIKE 'DSXXX%'
AND productcode NOT LIKE 'DO NOT USE%'
AND productcode NOT LIKE 'MAXXXX%'
AND isactive = 'true'
MINUS
SELECT productcode
FROM vew_product_export) a,
sforce_product2
WHERE a.productcode = sforce_product2.productcode
which returns 112 ID's (which is wrong)
The inner SELECT statement:
SELECT productcode
FROM sforce_product2
WHERE productcode NOT LIKE 'DSXXX%'
AND productcode NOT LIKE 'DO NOT USE%'
AND productcode NOT LIKE 'MAXXXX%'
AND isactive = 'true'
MINUS
SELECT productcode
FROM vew_product_export
returns 106.
Am I doing something simple wrong or is my query just mangled!
TIA,
MikeSELECT DISTINCT ID
FROM (SELECT productcode
FROM sforce_product2
WHERE productcode NOT LIKE 'DSXXX%'
AND productcode NOT LIKE 'DO NOT USE%'
AND productcode NOT LIKE 'MAXXXX%'
AND isactive = 'true'
MINUS
SELECT productcode
FROM vew_product_export) a,
sforce_product2
WHERE a.productcode = sforce_product2.productcodethe above code is returning an ID column which i think most probable from the sforce_product2 table
while this query below returns the 106 value that is coming from the column productcode.
SELECT productcode
FROM sforce_product2
WHERE productcode NOT LIKE 'DSXXX%'
AND productcode NOT LIKE 'DO NOT USE%'
AND productcode NOT LIKE 'MAXXXX%'
AND isactive = 'true'
MINUS
SELECT productcode
FROM vew_product_exportso i think there is nothing wrong because if you will review the 112 is from the column ID while the 106 is from the column productcode. -
T-SQL script help needed on creating a distribution.
Hello Team -
I'm new to T-SQL.
I have a set of sales reps and have accounts assigned to them. I want to be able to take out only those accounts for each
sales rep whose REVMIX won't exceed more than 10% (summing up the total revmix and capping it to <=10%). Not sure how to get to it.
Kindly help. Below is how the data looks like.
SALES REP
ACCOUNT_ID
REVENUE
TOTALREVENUE
REVMIX
23626
123456791
100
$44,100
0.2%
23626
123456793
300
$44,100
0.7%
23626
123456795
500
$44,100
1.1%
23626
123456797
700
$44,100
1.6%
23626
123456799
900
$44,100
2.0%
23626
123456801
1100
$44,100
2.5%
23626
123456803
1300
$44,100
2.9%
23626
123456805
1500
$44,100
3.4%
23626
123456807
1700
$44,100
3.9%
23626
123456809
1900
$44,100
4.3%
23626
123456811
2100
$44,100
4.8%
23626
123456813
2300
$44,100
5.2%
23626
123456815
2500
$44,100
5.7%
23626
123456817
2700
$44,100
6.1%
23626
123456819
2900
$44,100
6.6%
23626
123456821
3100
$44,100
7.0%
23626
123456823
3300
$44,100
7.5%
23626
123456825
3500
$44,100
7.9%
23626
123456827
3700
$44,100
8.4%
23626
123456829
3900
$44,100
8.84%
23626
123456831
4100
$44,100
9.30%
236267
123456802
4300
167500
2.57%
236267
123456814
4500
167500
2.69%
236267
123456826
4700
167500
2.81%
236267
123456838
4900
167500
2.93%
236267
123456850
5100
167500
3.04%
236267
123456862
5300
167500
3.16%
236267
123456874
5500
167500
3.28%
236267
123456886
5700
167500
3.40%
236267
123456898
5900
167500
3.52%
236267
123456910
6100
167500
3.64%
236267
123456922
6300
167500
3.76%
236267
123456934
6500
167500
3.88%
236267
123456946
6700
167500
4.00%
236267
123456958
6900
167500
4.12%
236267
123456970
7100
167500
4.24%
236267
123456982
7300
167500
4.36%
236267
123456994
7500
167500
4.48%
236267
123457006
7700
167500
4.60%
236267
123457018
7900
167500
4.72%
236267
123457030
8100
167500
4.84%
236267
123457042
8300
167500
4.96%
236267
123457054
8500
167500
5.07%
236267
123457066
8700
167500
5.19%
236267
123457078
8900
167500
5.31%
236267
123457090
9100
167500
5.43%
236268
123457102
9300
136500
6.81%
236268
123457114
9500
136500
6.96%
236268
123457126
9700
136500
7.11%
236268
123457138
9900
136500
7.25%
236268
123457150
10100
136500
7.40%
236268
123457162
10300
136500
7.55%
236268
123457174
10500
136500
7.69%
236268
123457186
10700
136500
7.84%
236268
123457198
10900
136500
7.99%
236268
123457210
11100
136500
8.13%
236268
123457222
11300
136500
8.28%
236268
123457234
11500
136500
8.42%
236268
123457246
11700
136500
8.57%This is close to a live data. There are about 23 rows here from the table. Sum(REVENUE) for the 10 rows would add up to 2380114.397. I will get 10% MIX if I divide it with RUNNINGTOTAL_REVENUE. For some reason when
I'm applying where condition it's not returning those first 10 rows. Not sure what the problem is. :(
SALESREP
ACCOUNT_ID
REVENUE
RUNNINGTOTAL_REVENUE
MIX
236300
ACCOUNT1
17917.83
23451885.59
0%
236300
ACCOUNT2
67402.07
23451885.59
0%
236300
ACCOUNT3
69576.646
23451885.59
0%
236300
ACCOUNT4
82828.84
23451885.59
0%
236300
ACCOUNT5
130955.866
23451885.59
1%
236300
ACCOUNT6
153865.04
23451885.59
1%
236300
ACCOUNT7
316329.34
23451885.59
1%
236300
ACCOUNT8
476030
23451885.59
2%
236300
ACCOUNT9
483660.01
23451885.59
2%
236300
ACCOUNT10
581548.755
23451885.59
2%
236300
ACCOUNT11
669007.05
23451885.59
3%
236300
ACCOUNT12
683942.12
23451885.59
3%
236300
ACCOUNT13
748481.98
23451885.59
3%
236300
ACCOUNT14
878047.8
23451885.59
4%
236300
ACCOUNT15
1127457.05
23451885.59
5%
236300
ACCOUNT16
1221103.91
23451885.59
5%
236300
ACCOUNT17
1422627.56
23451885.59
6%
236300
ACCOUNT18
1492686.19
23451885.59
6%
236300
ACCOUNT19
1698136.33
23451885.59
7%
236300
ACCOUNT20
2536279.246
23451885.59
11%
236300
ACCOUNT21
2618973.05
23451885.59
11%
236300
ACCOUNT22
2860847.283
23451885.59
12%
236300
ACCOUNT23
3114181.627
23451885.59
13% -
Derived column syntax help needed
I am struggling getting the following case statement into the derived column format in SSIS
CASE
WHEN SUBSTRING(REPLICATE('0', 9 - LEN(Data)) + CAST(Data AS VARCHAR(9)), 4, 6) IS NULL
THEN 0
ELSE RTRIM(SUBSTRING(REPLICATE('0', 9 - LEN(Data)) + CAST(Data AS VARCHAR(9)), 4, 6))
END
Here are examples for the data in Data
row 1 - 1201303
row 2 - 123456789
row 3 - null
row 4 - 12345678
the first row result would be 201303
row 2 result would be 456789
row 3 result would be 0
row 4 result would be 345678
Andre ToerienI have a problem with the isnull, the isnull needs to be on the first 6 characters as well.
Maybe its best explained with the other similar fields
ISNULL(LEFT((DT_STR,3,1252)CYCLE_YYYYMM,3)) ? "0" : LEFT((DT_STR,3,1252)CYCLE_YYYYMM,3)
and
ISNULL(RIGHT((DT_STR,3,1252)CYCLE_YYYYMM,6)) ? "0" : RIGHT((DT_STR,6,1252)CYCLE_YYYYMM,6)
We are trying to keep the coding similar on all our fields even if its a but redundant, we moved over from an Adabas system, and in the last example there are actuallt cases with the first three characters being seen as nulls, if I understand correctly
the fields in Adabas are right aligned which causes this, so I need to cater for the difference between a true null where I expect a null value to be returned and one where a substring on a left(field,6) return a null which then as to return a 0..
ISNULL(LEFT((DT_STR,3,1252)CYCLE_YYYYMM,3)) ? "0" : LEFT((DT_STR,3,1252)CYCLE_YYYYMM,3)---this one is actually a substring(field,1,3) and the one below is a substring(field,4,6)
ISNULL(RIGHT((DT_STR,3,1252)CYCLE_YYYYMM,6)) ? "0" : RIGHT((DT_STR,6,1252)CYCLE_YYYYMM,6)
some of the vause in sql are actually 0 for the 1,3 and 201302 for the 4,6, same field
Hope this makes sense, i actually tested this and the data actually is like that. I also need an example of how to handle the second example
ISNULL(RIGHT((DT_STR,3,1252)CYCLE_YYYYMM,6)) ? "0" : RIGHT((DT_STR,6,1252)CYCLE_YYYYMM,6) - this is of course the substring 4,6 field
I am serious;y considering leaving the derived column if I cannot get this to work, have been struggling with this for a few days
Andre Toerien -
Tweak for sql query - help needed for smalll change
Hi.
I am trying to run a script that checks for used space on all tablespaces and returns the results.
So far so good:
set lines 200 pages 2000
col tablespace_name heading 'Tablespace' format a30 truncate
col total_maxspace_mb heading 'MB|Max Size' format 9G999G999
col total_allocspace_mb heading 'MB|Allocated' format 9G999G999
col used_space_mb heading 'MB|Used' format 9G999G999D99
col free_space_mb heading 'MB|Free Till Max' like used_space_mb
col free_space_ext_mb heading 'MB|Free Till Ext' like used_space_mb
col pct_used heading '%|Used' format 999D99
col pct_free heading '%|Free' like pct_used
break on report
compute sum label 'Total Size:' of total_maxspace_mb total_allocspace_mb used_space_mb - free_space_mb (used_space_mb/total_maxspace_mb)*100 on report
select
alloc.tablespace_name,
(alloc.total_allocspace_mb - free.free_space_mb) used_space_mb,
free.free_space_mb free_space_ext_mb,
((alloc.total_allocspace_mb - free.free_space_mb)/alloc.total_maxspace_mb)*100 pct_used,
((free.free_space_mb+(alloc.total_maxspace_mb-alloc.total_allocspace_mb))/alloc.total_maxspace_mb)*100 pct_free
FROM (SELECT tablespace_name,
ROUND(SUM(CASE WHEN maxbytes = 0 THEN bytes ELSE maxbytes END)/1048576) total_maxspace_mb,
ROUND(SUM(bytes)/1048576) total_allocspace_mb
FROM dba_data_files
WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
GROUP BY tablespace_name) alloc,
(SELECT tablespace_name,
SUM(bytes)/1048576 free_space_mb
FROM dba_free_space
WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
GROUP BY tablespace_name) free
WHERE alloc.tablespace_name = free.tablespace_name (+)
ORDER BY pct_used DESC
The above returns something like this:
MB MB % %
Tablespace Used Free Till Ext Used Free
APPS_TS_ARCHIVE 1,993.13 54.88 97.32 2.68
APPS_TS_TX_IDX 14,756.13 1,086.88 91.37 8.63
APPS_TS_TX_DATA 20,525.75 594.25 80.18 19.82
APPS_TS_MEDIA 6,092.00 180.00 74.37 25.63
APPS_TS_INTERFACE 13,177.63 366.38 71.49 28.51
The above works fine, but I would like to further change the query so that only those tablespaces with free space less than 5% (or used space more than 95%) are returned.
I have been working on this all morning and wanted to open it up to the masters!
I have tried using WHERE pct_used > 95 but to no avail.
Any advice would be appreciated.
Many thanks.
10.2.0.4
Linux Red Hat 4.Thanks for that.
What is confusing is that the below query works for every other (about 10 others) database but not this one (?)
SQL> set lines 200 pages 2000
SQL>
SQL> col tablespace_name heading 'Tablespace' format a30 truncate
SQL> col total_maxspace_mb heading 'MB|Max Size' format 9G999G999
SQL> col total_allocspace_mb heading 'MB|Allocated' format 9G999G999
SQL> col used_space_mb heading 'MB|Used' format 9G999G999D99
SQL> col free_space_mb heading 'MB|Free Till Max' like used_space_mb
SQL> col free_space_ext_mb heading 'MB|Free Till Ext' like used_space_mb
SQL> col pct_used heading '%|Used' format 999D99
SQL> col pct_free heading '%|Free' like pct_used
SQL>
SQL> break on report
SQL> compute sum label 'Total Size:' of total_maxspace_mb total_allocspace_mb used_space_mb - free_space_mb (used_space_mb/total_maxspace_mb)*100 on report
SQL>
SQL> select /*+ALL_ROWS */
2 alloc.tablespace_name,
3 alloc.total_maxspace_mb,
4 alloc.total_allocspace_mb,
5 (alloc.total_allocspace_mb - free.free_space_mb) used_space_mb,
6 free.free_space_mb+(alloc.total_maxspace_mb-alloc.total_allocspace_mb) free_space_mb,
7 free.free_space_mb free_space_ext_mb,
8 ((alloc.total_allocspace_mb - free.free_space_mb)/alloc.total_maxspace_mb)*100 pct_used,
9 ((free.free_space_mb+(alloc.total_maxspace_mb-alloc.total_allocspace_mb))/alloc.total_maxspace_mb)*100 pct_free
10 FROM (SELECT tablespace_name,
11 ROUND(SUM(CASE WHEN maxbytes = 0 THEN bytes ELSE maxbytes END)/1048576) total_maxspace_mb,
12 ROUND(SUM(bytes)/1048576) total_allocspace_mb
13 FROM dba_data_files
14 WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
15 GROUP BY tablespace_name) alloc,
16 (SELECT tablespace_name,
17 SUM(bytes)/1048576 free_space_mb
18 FROM dba_free_space
19 WHERE file_id NOT IN (SELECT FILE# FROM v$recover_file)
20 GROUP BY tablespace_name) free
21 WHERE alloc.tablespace_name = free.tablespace_name (+)
22 ORDER BY pct_used DESC
23 /
((alloc.total_allocspace_mb - free.free_space_mb)/alloc.total_maxspace_mb)*100 pct_used,
ERROR at line 8:
ORA-01476: divisor is equal to zero
Maybe you are looking for
-
Material master data complete in bi - infoset or multiprovider
Hi all. for one of the reporting requirement of my client i need to extract the complete material master data in BI - from MARA, MARC, MARD, MSTLB tabls. which i have done and stored in the infoobjects - 0MATERIAL, 0MAT_ST_LOC, 0MAT_PLANT, 0MAT_SALES
-
I have created a single page PDF file with an embedded FLV file and a bit of text that has a hyperlink to my web site. This file plays just fine for me, but I have a tester who reports: "On my computer it downloads as a black screen with white lette
-
Adobe Acrobat Reader 8.1 just quit working.
I can't create a PDF document through the print menu. No longer able to print documents I previously created with the program. When I open the progam, it automatically closes within a few seconds. Error message received when I try to either print
-
Gmail gives no problems. Did not have problem on earlier versions. Incoming attachments seem to be readable
-
RFC Error Received while opening queries from BEx Analiser
Hi Friends, We have recently upgraded BW 3.5 to BI 7.0 and installed SAP GUI 710. When we try to open queries using old 3.5 BEx Analyser, we are getting error ' RFC Error Received '. strange thing is, it is not happening with all the users. For some