How to write Sql statement for M:M relationship set?
If theres two Entity sets "Department" and "Employee".....
Department Entity contains this attribute dno,dname,address etc and
"Employee" entity contain attribute like Empno,Empname,date,time etc
and theres Many to Many relationship between Employee and Deapartment Entity set,i.e.each employee can work in any department, and each department has at least one employee (Many to Many relationship)
What should be the SQL statement to create table for Many to Many relationship sets for Employee and Department set..
Any helps will be appreciated.
Femi
create 3 tables: employee, department and empdept
in the empdept table you reference foreign keys from the 2 other tables. so if my employee id was 42 and I work for departments 1,2 and 3, this table would look like this:
emp_fk | dept_fk
42 1
42 2
42 3
Similar Messages
-
How to write Select statement for this codition
I need to check whether SGTXT contains BELNR value.
SGTXT is a text field and It should be matched with BELNR
How to write select statement for this.
Select AUGBL AUGDT into t_BSAD
from BSAD
where SGTXT should have the given BELNR Value.
Plz note : Here I cannot give as SGTXT = BELNR as coz BELNR have only 10 digits.Hi,
data temp(12).
concatenate '%' belnr '%' into temp.
Select AUGBL AUGDT into t_BSAD
from BSAD
where SGTXT like temp.
If belnr is having multiple values,just create a internal table as follows.
types : begin of ty,
belnr....
temp(12),
end of ty.
data itab_ type standard table of ty.
data wa type ty.
loop at itab into wa.
concatenate '%' wa-belnr '%' into wa-temp.
modify itab from wa index sy-tabix transporting temp.
endloop.
Change your select statement accordingly.
Kindly reward poits if it helps. -
How to write sql query for counting pairs from below table??
Below is my SQL table structure.
user_id | Name | join_side | left_leg | right_leg | Parent_id
100001 Tinku Left 100002 100003 0
100002 Harish Left 100004 100005 100001
100003 Gorav Right 100006 100007 100001
100004 Prince Left 100008 NULL 100002
100005 Ajay Right NULL NULL 100002
100006 Simran Left NULL NULL 100003
100007 Raman Right NULL NULL 100003
100008 Vijay Left NULL NULL 100004
It is a binary table structure.. Every user has to add two per id under him, one is left_leg and second is right_leg... Parent_id is under which user current user is added.. Hope you will be understand..
I have to write sql query for counting pairs under id "100001". i know there will be important role of parent_id for counting pairs. * what is pair( suppose if any user contains both left_leg and right_leg id, then it is called pair.)
I know there are three pairs under id "100001" :-
1. 100002 and 100003
2. 100004 and 100005
3. 100006 and 100007
100008 will not be counted as pair because it does not have right leg..
But i dont know how to write sql query for this... Any help will be appreciated... This is my college project... And tommorow is the last date of submission.... Hope anyone will help me...
Suppose i have to count pair for id '100002'. Then there is only one pair under id '100002'. i.e 100004 and 100005Sounds like this to me
DECLARE @ID int
SET @ID = 100001--your passed value
SELECT left_leg,right_leg
FROM table
WHERE (user_id = @ID
OR parent_id = @ID)
AND left_leg IS NOT NULL
AND right_leg IS NOT NULL
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
How to write sql query for below mentioned eaxmple.
Hi,
I have requirement.
There are number of rows and I need the result through query as follows.Please help me to proved sql query for below mentioned requirement.
example: table TEST.
COLA COLB COLC COLD COLE COLF MANAGER 5 NULL NULL 3 NULL
SR.MANAGER 6 3 NULL NULL NULL
VP 5 5 4 5 5
I have to write the sql query if COLA IS MANAGER THEN CONSIDER MANGER RECORD,AND IF ANY COLUMN FILED IS NULL FOR MANGER THEN CONSIDER COLA IS SR.MANGER, AND IF ANY COLUMN FILED IS NULL FOR SR,MANGER THEN CONSIDER VP records.
I need output as below.
COLB COLC COLD COLE COLF
5(manager) 3(sr.manger) 4(vp) 3(manger) 3(vp)
Please provide the for above mentioned output.
ThanksDuplicate thread. please view the answer posted in your first thread.
how to write sql query.
And, please don't post any duplicate thread.
Regards.
Satyaki De. -
How to find SQL Statements for BW queries ?
Experts,
Is there a way, we can see what SQL statement BW queries creates ?
please Help.Hi,
use sql trace: transaction ST05.
ask your database admin. He can control the database session.
=> for oracle: you can see the session also in the sap gui.
Sven -
How to write sql query for below example.
Hi,
I have requirement.
There are number of rows and I need the result through query as follows.Please help me to proved sql query for below mentioned requirement.
example: table TEST.
COLA COLB COLC COLD
MANAGER 5 NULL null
SR.MANAGE 6 3 NULL
VP 5 5 4
I have to write the sql query if COLA IS MANAGER THEN CONSIDER MANGER RECORD,AND IF ANY COLUMN FILED IS NULL FOR MANGER THEN CONSIDER COLA IS SR.MANGER, AND IF ANY COLUMN FILED IS NULL FOR SR,MANGER THEN CONSIDER VP records.
I need output as below.
COLB COLC COLD
5(MANGER) 3(sr.manger) 5(vp)
Please provide the for above mentioned output.
Thanks<<if COLA IS MANAGER THEN CONSIDER MANGER RECORD>>
What does this sentence means? COLA does not cnatin a single record but the number of records with diffrent values.
Regards
Arun -
Pass ORG_ID as sql statement for parameter in request set
We are in a multi-org environment. We are running the request PRC: Generate Draft Revenue for a Single Project as part of the request set. We want the request to automatically fill in the open pa period as the accrue through date. We have been using the SQL Statement below as the value for the accrue through date parameter.
select end_date
from pa_periods_all
where status = 'O'
and current_pa_period_flag = 'Y'
Unfortunately that does not limit to a specific company. We a company that still have DEC-05 while another has an open period of JAN-06. This is causing the program fits. How do I pass the org_id to the request? [in beginners terms please]
Thanks.
AnneNo idea what might be wroong without more info...
Do some output. Test the ${params.id} variable passed to the second jsp. If that is correct, then error is in the select statement or display of jsp2. If it is correct the error comes from jsp1.
If I have to guess, then I would say the error comes from JSP1, and the ${row.vac_id} should only be called once. In which case I would do something like this:
//in jsp 1
<c:forEach var="row" items="${results.rows}" varStatus="counter" >
<c:set var="vac_id" value="${row.vac_id}" scope="page"/>
<tr>
<td>${vac_id}</td>
<td><a href="vacancydetails.jsp?id=${vac_id}">More</a></td>But that is a guess only...
Errr... Hold on to that as reference, but the it is entirely likely that I misspelled ${params.id} It may be ${param.id} I forget and away from my machine right now... -
How to write SQL hints for this query?
The query is like:
select * from foo, t
where foo.name in
(select name from bar
where id in (
select id from car
where date < sysdate
and foo.a = t.b;
I want the innermostsubquery 'select id from car ...' to be executed first, and the subquery 'select name from bar ...' to be execute second, and the outermost query 'select * from foo,t ...' to be executed the last. How can I write the Oracle sql hints to force the order?
Thanks.user553560
You might be able to create a large set of hints to force the access path you want - but unless you really know what you are doing with hints, you may find that your solution is very unstable (it might be luck rather than correctness that let's it work to start with).
The difficulty in this query is the double layer of IN subqueries, so if you can rewrite the query, you might try manually unnesting as follows:
select
t1.*. t.*
from
select
distinct t2.name
from t2
where t2.id in (
select t3.id
from t3
where t3.dated < sysdate
) v,
t1,
t
where
t1.name = v.name
and t1.a = t.bDepending on your indexing and statistics, you may find that a simple /*+ unnest */ hint in the first subquery will be sufficient to do this for your. Again depending on the statistics you may find that you have to put extra hints into the above to make Oracle use the join method and indexes you think appropriate.
N.B. The first step (as others have noted) is to check that your statistics are good before you start manipulating the code or using hints.
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk -
How to write if statement for knowing that user is executing in background.
Hai Experts.
I am having a report , in that i want two types of output say when i execute in foreground it should say " Hello it is foreground".
when i execute it in background as a job it should display " Hello it is back ground".
please tell me how to code this in the report.
if forground.
write : hello it is foreground.
else if it is background.
write : it is back ground.
please tell me the code in ABAPif sy-batch = space
write : 'hello it is foreground'.
elseif sy-batch = 'X'.
write : 'it is back ground'.
endif.
Regards,
Rich Heilman -
How to monitor/capture SQL statement for an event?
I want to capture all sql statements for 10 minutes that ran against the database. How should i do that?
Thanks,
DaveThe following document will give u the requred know how.
http://www.oracle.com/technology/products/manageability/database/pdf/ow05/PS_S001_274001_106-1_FIN_v1.pdf -
How to create sql query for item master with operator LIKE with variables?
hi all,
How to create sql query for item master with
operator LIKE(Contains,Start With,End With) with variables using query generator in SAP B1 ?
JeyakanthanHi Jeyakanthan,
here is an example (put the like statement into the where field)
SELECT T0.CardCode, T0.CardName FROM OITM T0 WHERE T0.CardName Like '%%test%%'
The %% sign is a wildcard. If you need start with write 'test%%' and otherwise ends with '%%test'. For contains you need '%%test%%'. You also could combinate this statements like 'test%%abc%%'. This means starts with test and contains abc.
Regards Steffen -
Nested SQL statements for complex, detailed queries.
Is it possible to write nested SQL statements for complex, detailed queries. A nested query
has a WHERE clause that includes a SELECT statement ? Is it true or false ?Hi wahid,
Here are pretty good examples:
http://www.databasejournal.com/features/mssql/article.php/3464481/Using-a-Subquery-in-a-T-SQL-Statement.htm
http://technet.microsoft.com/en-us/library/aa213252(v=sql.80).aspx
Regards Harsh -
How to write select statement in XSL-FO type XML program
Hi All,
Could you please anyone explain briefly how to write select statement in XSL-FO XML Program.
Requirement:
In the seeded program, OAF page is creating one XML file and through XSL-FO type XML Pulisher loading data and generating PDF output. as per the requirement some of the informations are missing in the XML file and for modifing the OAF page will be taking someting. we are planing to write a select query inside the XSL-FO program to get the required information.
Could you please help me how to write a select statement inside the XSL-FO type programs.
Please give me some example program for this...
Thanks in Advance.
Regards,
SenthilHi ,
Please check the below code and modified plant as select-option
Check the below code :
tables : mara,
mast.
data : begin of i_data occurs 0,
matnr like mara-matnr,
end of i_data.
select-options : s_matnr for mara-matnr,
<b>S_werks for mast-werks.</b>
start-of-selection.
select a~matnr into table i_data
from mara as a inner join mast as b on amatnr = bmatnr
where <b>b~werks in s_werks</b>
and a~matnr in s_matnr
and a~mtart = 'AA'
or a~mtart = 'UT'
and b~stlan = '1'.
loop at i_data.
write:/ i_data-matnr.
endloop.
Hope you got it.
Thanks
Seshu -
How to write sql query with many parameter in ireport
hai,
i'm a new user in ireport.how to write sql query with many parameters in ireport's report query?i already know to create a parameter like(select * from payment where entity=$P{entity}.
but i don't know to create query if more than 1 parameter.i also have parameter such as
$P{entity},$P{id},$P{ic}.please help me for this.
thanksYou are in the wrong place. The ireport support forum may be found here
http://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=215&func=showcat&catid=9 -
Preparing Dynamic SQL statement for inserting in Pro*C
Hi Friends,
From quite some time i am struggling writing Dynamic SQL statement for dynamic insert and update in Pro*C.
Can somebody go through my code and suggest me the rigth way of doing.
Right now it throws an error saying " Error while updating ORA-00904: invalid column name "
Please help me.
Girish.
int main()
EXEC SQL BEGIN DECLARE SECTION;
char *uid ="scott/tiger";
static char sqlstmt[129];
struct /* DEPT record */
int dept_num;
char dept_name[15];
char location[14];
} dept_rec;
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER SQLERROR DO sql_error();
EXEC SQL CONNECT :uid;
dept_rec.dept_num = 50;
strcpy(dept_rec.dept_name,"ADMIN");
strcpy(dept_rec.location,"IN");
strcpy(sqlstmt,"UPDATE dept set DNAME = dept_rec.dept_name where DEPTNO = dept_rec.dept_num");
EXEC SQL EXECUTE IMMEDIATE:sqlstmt;
EXEC SQL COMMIT;
exit(0);
void sql_error()
printf("\nError while updating %s",sqlca.sqlerrm.sqlerrmc);
EXEC SQL ROLLBACK;
}A bit rusty here but this is how I see it.
Think of it this way ..
all Oracle is going to see is:
UPDATE dept set DNAME = dept_rec.dept_name where DEPTNO = dept_rec.dept_num
Its NOT going to know what dept_rec.dept_name is or dept_rec.dept_num is ..
it doesnt go back and fill in those values.
You need something like
strcpy(sqlstmt,"UPDATE dept set DNAME = \"");
strcat(sqlstmt,dept_rec.dept_name);
strcat(sqlstmt,"\" where DEPTNO = ");
strcat(sqlstmt,dept_rec.dept_num);
printf(sqlsmt); # Just to be sure the update statement look right during testing.
Maybe you are looking for
-
Windows 7 - Driver Availability Chart For Creative Products is nearly useless
<span class="text">[url="http://support.creative.com/kb/showarticle.aspx?sid=605">Windows 7 - Driver Availability Chart For Creative Products[/url] is outdated Windows pre-release drivers (at least for the Audigy SB0090 series) back from July. This a
-
Latest update to iPad has lagging issues with typing, how do i fix this?
My son's iPad was just updated to OS7.1 and eve since then his type functions will not work on the device. I have tried reseting the device and turing off the document setting in ICLOUD. Neither of these solutions worked. I am concerned that forms s
-
which tables contain tax fields like BED,CESS,discounts and the net value after these calculations.. wchich tcode contains these fields??... Thanks, Sri
-
Maximum number of instances that can be created on an oracle server ?
Hello all.... Can you tell me what is the maximum number of instances that can be created on an oracle server ? thanks and regards vinay raj
-
URGENT! Exporting JPEGs problem...
Hello everyone, Just a quick question... have tried everything, and cannot figure this one out. Client needs a 300dpi JPEG for printing (60cm x 90cm), the image being in vector format. Normally I would of course just make a PDF, but for some reason i