How to select few columns based on certain conditions
i have a table with n columns, of which in 2 columns each may have similar values for certain number of rows
i want to find if one of the entries in a column has same value in the next few rows
For example the two columns are
supplier_name supplier_code
hll 013
hll 013
hll 013
hll 013
if i first encounter hll with 013 i have to check whether hll with 013 record is further available
if it is so i have to display the columns for which multiple entries is available
can anyone send the query
Duplicate thread?
selecting certain columns in oracle
Similar Messages
-
How to create a column based on a condition ?
Hi all,
I am trying to create a stored procedure that will return ID,Name and a column of type bit called called checked based on a condition
please review my code and tell me what is wrong with it
ALTER PROCEDURE [dbo].[SelectStoresNames]
AS
BEGIN
WITH locations_CTE ( ID, Name, Checked)
AS
select loc.ID,loc.Name,
(case when loc. ID in (select distinct a.StoreId
from mPromoteStores a
inner join mPromote b
on a.PromoteId=b.PromoteId
where b.promoId=144120) then 1 else 0 end as [Checked])
FROM [dbo].[mLocations] loc where SchedulePullEnabled=1 order by Name
Select *
from locations_CTE
ENDPlease post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. You have no idea!
Temporal data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
This is minimal polite behavior on SQL forums.
>> I am trying to create a stored procedure that will return store_id, store_name and a column of type bit called “checked” based on a condition <<
I fixed the vague, useless, generic data elements, made wild guesses on the DDL you did not post and got rid of the assembly language bit flags (https://www.simple-talk.com/sql/t-sql-programming/bit-of-a-problem/)
1. IN (SELECT DISTINCT ..) is redundant
2. aliases in alphabetic order are no help for maintaining code
3. What is that “m” prefix? Better not be metadata...
4. We also do not use “-cte” postfixes; tell us what the table is and not how you got it. This is another version of the “vw-” or “Volkswagen” design flaw for views.
5. “promote” is a verb, so how can it have an identifier? Entities have identifiers. A set of “Promotions” could have a “promo_id”, but this might be a typo ..
6. Is “schedule_pull_enabled” another assembly language flag? I have the horrible feeling your unseen schema is not in 1NF ...
Since you did not post DDL here is as far as I can get ..
CREATE PROCEDURE Select_Stores_Names
AS
SELECT PS.store_id, PS.store_name
FROM Promote_Stores AS PS,
Promotes AS P
WHERE PS.promote_id = P.promote_id
AND P.promo_id = 144120 -- promo vs promote?
AND ???;
Want to follow the forum rules and try again?
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
How to aggregate a column based date column (for weekly single row)?
How to aggregate a column based date column (for weekly single row)?
Hi,
Consider the below statement for daily bases which is ok
SELECT ID, DATE, SUM(AMOUNT) FROM TABLE_NAME GROUP BY ID, DATE ORDER BY ID, DATE
The same like the above statement, I want output on weekly, fortnightly, and monthly bases, How to do this? Need your help... -
How to make few columns of single record inactive in Table conrol?
Hi all,
Scenario is like this : i have one table control , it is displaying 10 records , in that first four columns are editable. Now my requirement is, whenever record having intial values( suppose one record having initial values among ten) except key field , we need to deactive that particular record , now table control should contain ten records , but nine records are in editable state and one record in non editable state .
How to make few columns of single record inactive in Table conrol?
Thanks in advance.hi there...
select the column that u want to convert to non editable mode in the screen layout. then double click on it. go to the attributes tab and uncheck the input chk box. the check box will become disabled for input. u can do this for any number of columns.
if u want to do it dyanamically, loop at screen. check for the screen element's name. when itmatches the column u want to disable, simply set the input value as 0.
dont forget to modify sscreen after setting the attribute values.
i hope this helps.
do reward if helpful. -
How to Override Cost Center in IT 1 based on certain conditions
Hi,
I have a pretty good understanding on how Cost Center gets defaulted based on Org Structure. The standard SAP solution for Cost Center will not work for my client and I need to determine the cost center based on certain conditions. I understand that I have to write custom code in some user exit or badi. I tried user exit EXIT_SAPFP50M_001, but it did not work.
Here is my code:
DATA: I0001 LIKE P0001.
CASE INNNN-INFTY.
WHEN '0001'.
CALL METHOD CL_HR_PNNNN_TYPE_CAST=>PRELP_TO_PNNNN
EXPORTING
PRELP = INNNN
IMPORTING
PNNNN = I0001.
This is just an example to test the concept
I0001-kostl = 'COST_CENTER'.
CALL METHOD cl_hr_pnnnn_type_cast=>pnnnn_to_prelp
EXPORTING
pnnnn = i0001
IMPORTING
prelp = innnn.
endcase.
When I change IT 1 record and hit enter, I can see that my code is being executed. I can see cost center being updated on the screen, but when I save it, its not able to retain that new cost center value. This might be because cost center is not an open field.
How can I change my code so it retains its value after saving?.
Thanks!Contd to manoj
Cost Center will be a Open feild when the value of the switch PLOGI ORGA should be balnk if it is haveing 1 than it will not default the value kindly check -
How to select different Querys based on Variable Value
Hi guys i need to know how to select different Querys, based on variable values selected by the user, i try to do it using a Web Template but i don´t know how to program a Dynamic Query.....
I hope sombody could help me with this
Message was edited by: Oscar DiazHi Diaz,
Can you explain the exact scenario which you are looking for!!!
regards
Happy Tony -
VT02N - do PGI and Invoice for certain deliveries either based on certain conditions
Hi Friends ,
We are using VT04 for creating shipments . While shipment completion stage in VT02N an activity profile has been maintained which does both the Goods issue and Invoice.
We have a business requirement , PGI and Invoice should be created only for specific set of deliveries based on certain conditions.
Is there any standard way to do this or by using user exits.
Please guide.
Thanks,
Nileshsa.what about adding a check in userexit RV60AFZZ, when the condition is not met during invoice creation, error out and disable the creation of the invoice document?
-
Need to show the images in calculated column based on the condition in sharepoint 2013.
Hi ,
I'm working in sharepoint 2013, In this i want to show an image in calculated column based on the condition, but image is not showing .
In sharepoint 2010 its working with help of javascript in content editor on the same page. Same thing i tried in SP 2013. but doesn't work.
Could any one please give proper solution for this?
Thanks in advance.
by,
Siva.Hi please provide the JS you have used in the content editor as well as the calculation for the column so we can better understand what's maybe differs?
Blog: chrisstahl.wordpress.com Twitter:
@Cstahl -
How to select all columns in a trigger?
I add a "before delete" trigger on a table, in order to insert the records to a backup table before they are deleted.
but I cannot write like this : insert into t_backup select * from :old;
The table has more than 30 columns so I don't want to select them one by one, how can I select all columns?Yes, it is possible by writing something like this :
where col1 = :old.col1; But it is not directly supported. First, we need a package to remember all the OLD records:.... and please see below link for complete code in action :
http://www.dbforums.com/oracle/925729-trigger-back-up-data.html
What I am doing here, just copying the code and replacing "emp" with "test" (The table name on which I am going to apply this using notepad find and replace):
SQL> select * from test_backup;
no rows selected
SQL> select * from test;
A
1
2
4
5
SQL> select * from test_backup;
no rows selected
SQL>
create or replace package test_trg_pkg as
type test_type is table of test%ROWTYPE index by binary_integer;
test_tab test_type;
end;
create or replace trigger test_bds before delete on test
begin
test_trg_pkg.test_tab.delete;
end;
create or replace trigger test_adr after delete on test
for each row
declare
-- To allow us to select the old values
pragma autonomous_transaction;
begin
select *
into test_trg_pkg.test_tab(test_trg_pkg.test_tab.COUNT+1)
from test
where a = :old.a; <----- Here you have to give your column name.
end;
create or replace trigger test_ads after delete on test
begin
for i in 1..test_trg_pkg.test_tab.COUNT loop
insert into test_backup values test_trg_pkg.test_tab(i);
end loop;
end;
SQL> delete from test where a=1;
1 row deleted.
SQL> select * from test_backup;
A
1
SQL> delete from test where a=2;
1 row deleted.
SQL> select * from test_backup;
A
1
2
SQL>Regards
Girish Sharma -
How to hide table column based on country molga value
Hi Experts,
I am doing some enhancement in ess application. I want to hide table column based on country code i.e. Molga value.
I want to hide coulm for only Japan country reset of them i need to be show those coulmn.
Could you please provide me a sample code.
Regards
ChakriHi Chakri,
Your setting the table value that time you will get the Country Code.
1.Create the attribute like Country_Column_Visible Data Type bind the com.sap.ide.webdynpro.uielementdefinitions.Visibility this value you need to bind the table country column.
2.In Table You need to check the country code Japan is available you need follow this below sample code.
for(int i=0;i<tablesize;i++)
tablesithValue=wdContext.nodeTable().getTablenode(i);
if(null != tablesithValue.getcountrycode)
if(tablesithValue.getcountrycode.equalsIgnoreCase("Japan"))
wdContext.currentxxxxElement.setCountry_Column_Visible(WDVisibility.NONE);
}else
wdContext.currentxxxxElement.setCountry_Column_Visible(WDVisibility.VISIBLE);
Use the above code you condition it will work.I hope it will help you.
BR,
Durga -
How to group few columns in ALV in web dynpro under a common column header?
Hi All,
Please let me know the way to group few columns in ALV display under a common column header in a web dynpro application .
For e.g.
year
| Q1 | Q2 |......
Thanks in advance.
Regards
ArchanaHi Archana,
Creating a group header is possible in case of normal Table UI element. I don't think any such functionality exists in case of ALV. Just go through Thomas' comments in this thread: header group in wd alv.
I hope it helps.
Regards
Arjun -
Inserting new columns based on the condition!
Hi guys,
I have a very simple query like the following…
SELECT table2.column_code2,
table2.column_description2,
table2.column_code1,
table1.column_description1
FROM database_001.table2 table1 LFET OUTER JOIN database_001.table2 table1 on (table2.column_code1 = table1.column_code1)
From this query, its returning me a result set of something like below:
column_code1 column_description1 column_code2 column_description2
RO1 BOOK RL1
PDF/ECOPY
RO2 PAPER RL2
CONFERENCE
RO5 JOURNAL
RL11 OTHER
Now, on the above query I want to insert three extra columns with the name (status, location and contact) where the results in the extra three columns would be based on the conditions I want to define in the query based on the above results…
Something for example (sorry, I am not trying to write a condition: my question is how to write it),
if column_code1 = RO1 and column_description2 = PDF/ECOPY on status column it should return a value ‘ONLINE’ & on location column it should return ‘WEB’ and on contact column it should write ‘BOB’.
Also,
if column_code1 = RO5 and column_description1 = JOURNAL on status column it should return a value ‘ON PRESS FOR PRINT’ & on location column it should return ‘S.R STREET, LONDON’ and on contact column it should write
‘SMITH’ like below result…so the final output should be the top four columns and the extra three columns…I hope someone can help me into this…thanks a lot…
status location
contact
ONLINE WEB
BOB
ON PRESS FOR PRINT S.R STREET, LONDON SMITHHi artistdigital,
you can use case statment for same in sql server. MSDN link - > http://technet.microsoft.com/en-us/library/ms181765.aspx
Try code like this:
SELECT table2.column_code2,
table2.column_description2,
table2.column_code1,
table1.column_description1,
case when column_code1 = 'RO1' and column_description2 = 'PDF/ECOPY' then 'ONLINE'
when column_code1 = 'RO5' and column_description1 = 'PDF/ECOPY' then 'ON PRESS FOR PRINT'
end as [status],
case when column_code1 = 'RO1' and column_description2 = 'PDF/ECOPY' then 'WEB'
when column_code1 = 'RO5' and column_description1 = 'PDF/ECOPY' then 'S.R STREET, LONDON'
end as [Location],
case when column_code1 = 'RO1' and column_description2 = 'PDF/ECOPY' then 'BOB'
when column_code1 = 'RO5' and column_description1 = 'PDF/ECOPY' then 'SMITH'
end as [contact]
FROM table2
join table1
on table2.column_code1 = table1.column_code1
Regards Harsh -
Oracle Business Intelligence How to choose data set based on a condition
Hi,
I am using Oracle Business Intelligence for creating reports, i am facing a situation where i have two quries (data sets in BI), one to display a Failure message and other to fetch data from the table to be displayed in the report.
The problem is i am unable to choose which data set to run based on a condition. How to use a condition based on which the dataset will be run
For example : i will read a table column value if it is 'S' means success, then i have to run the dataset to fetch the data from the table.
If the column value has 'F' then i have to run the dataset which will display failure message
Please let me know if any of you have any idea on this
Thanks in advance
MuthukumaranHi Chinna,
You have to use some scripting as well as coding to perform the tasks listed by you. First of all make your form Dynamic, In your Adobe lifecycle Designer, open your form,
Goto, File --> Form Properties,
Goto the Defaults tab,
Select "Dynamic PDF" for the XDP Preview Format:
Click OK.
This setting will now allow dynamicity in your Form, when you view it in PDF Preview tab.
For Hiding/Unhiding the fields/SF, you can use the presence property and set it based on the conditions. like:
if (this.rawValue == null)
TextField1.presence = "hidden";
For your second task, you may map a method corresponding to onSubmit event of the IF and write the code to create the workflow and make RFC call here.
For third one, you need to convert the PDFObject from Binary context into a byte array and save it at appropriate location.
Hope I have answered all your queries.
Cheers,
Arafat -
How to select values frm table giving the condition value at runtime in SQL
Hi All,
How to select values from a table by giving the condition value at runtime in SQL
My SQL statement is select * from employee where empno=<empno>, this empno I want to provide at run time. Also I don't have any bind variables defined. Can anyone please tell how can I achieve this. Also do I have to write a SQL or pl/sql statement.Hi Roshni Shankar,
You can use substitution variable in case of SQL.
SQL> select * from employees where emplployee_id = &emp_id;
Enter value for emp_id: 100
old 1: select * from employees where emplployee_id = &emp_id
new 1: select * from employees where emplployee_id = 100If you want to put condition on varchar values then eighter provide values in single quotes or use single quote for substitution variable.
SQL> select * from employees where last_name = &emp_name;
Enter value for emp_name: 'King'
old 1: select * from employees where last_name = &emp_name
new 1: select * from employees where last_name = 'King'
no rows selected
SQL> select * from employees where last_name = '&e_name';
Enter value for e_name: King
old 1: select * from employees where last_name = '&e_name'
new 1: select * from employees where last_name = 'King'In case of pl/sql you can pass values to procedure and you can use those values at run time.
create or replace procedure test (p_emp_id number)
as
v_last_name varchar2(100);
begin
select last_name
into v_last_name
from employees
where employee_id = p_emp_id;
dbms_output.put_line(p_emp_id ||' -> '||v_last_name);
end;
show errors
SQL>exec test(100);
SQL>exec test(101);Edited by: Gaurav Bhide on Oct 29, 2012 4:07 AM -
Setting a field as Mandatory dynamically based on certain condition
Hi All -
I am working on ADOBE Interactive forms. I am not able to find out, How to set a particular field as a 'Mandatory field' based on some condition. I am using FormCalc as scripting language.
i.e: I have a field "RATING". I want to make the next field "COMMENT" as mandatory when "RATING" is less than 3.Hi Vishal,
You need to set the mandatory attribute of the specific field according to your condition. In FormCalc this will be similar to this,
if (Rating < 3) then
$.mandatory = "error"
$.mandatoryMessage = "The corresponding Comment field is mandatory. Please fill"
else
$.mandatory = "disabled"
endif
The mandatory property can be set as:
"error" : Makes the field compulsory to be filled before submission
"disabled" : Makes the field optional
"warning" : Gives a warning to the user that the field should be filled, but doesn't cause an error on submission
The property "mandatoryMessage" specifies the message to be displayed to the user when the mandatory field isn't filled before submission.
Regards,
Rose
Maybe you are looking for
-
Don't see files on USB Drive connected to Airport Extreme
I just connected an external drive to my Airport Extreme via USB. It appears as a shared device in the finder sidebar. When I select it, none of the files that reside on the drive appear. It is a 1TB drive with 600GB of files on it, but none of the f
-
All info stated in question. About the third time I've asked this question with no help.
-
Project Manager. I'm a bit Confused
i tried reading the manual but i dozed off last night. i'm still confused on this one. here is my setup. 2 internal drives (Main) and (Audio). 1 firewire drive with ALL my samples. all Audio for projects is on Audio drive all Samples are on Sample dr
-
How to get a reference to the owner of a class instance?
Within a method of a class, how can I get a reference to the object containing the class instance? To be clear: I have class B that contains a method, say "myfunc()". Class A (say, the application itself or a custom component) instantiates a new inst
-
How to access report placeholder in format trigger
How can i access the report placeholder inside the format trigger. I am trying to access it like :F_AMOUNT as i am seeing it in the object navigator but it is giving me error that it is bad bind variable.