Can i select Records from two tables into an itab.
Hi,
Suppose that i have two tables spfli and sflight.
Now i want the records from both the tables into a single internal table.
If so please let me know how this can be done.
itab should consist of all the columns in sflight and spfli.
Regards,
Sai
Sai,
Yes u can do it using JOINs.
Use this link for ref
http://www.sap-img.com/abap/inner-joins.htm
INNER JOIN results are an intersection of the tables being joined where in only if both the tables havethe data the result is pused onto the result set.
WHERE as in LEFT OUTR JOIN you can push the data of the LEF T table on the resultset even when the join condition is not met.
The use is that you wantto have all the data that is there in left table and also the right table if the join condition is a success then right table fileds will have data else they are initial.
OUTJOIN's are used in MAINTENANNCE VIEWS, HELP VIEWS .
INNER JOINS are used DATABSE VIEWS.
Inner Join:-
SELECT pcarrid pconnid ffldate bbookid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( ( spfli AS p
INNER JOIN sflight AS f ON pcarrid = fcarrid AND
pconnid = fconnid )
INNER JOIN sbook AS b ON bcarrid = fcarrid AND
bconnid = fconnid AND
bfldate = ffldate )
WHERE p~cityfrom = 'FRANKFURT' AND
p~cityto = 'NEW YORK' AND
fseatsmax > fseatsocc.
Left Outer Join
SELECT scarrid scarrname p~connid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM scarr AS s
LEFT OUTER JOIN spfli AS p ON scarrid = pcarrid AND
p~cityfrom = 'FRANKFURT'.
Reward if helpful,
Karthik
Similar Messages
-
Hi all,
I have two tables:
CRETE TABLE T1 (T1_COL1 NUMBER, T1_COL2 NUMBER)
CRETE TABLE T2 (T2_COL1 NUMBER, T2_COL2 NUMBER)
T1 may or may not have records. T2 always has records. There are two scenarios.
Scenario 1:
=======
SELECT * FROM T1 returns five rows, and SELECT * FROM T2 returns 10 rows.
Now I need the five rows from T1.
Scenario 2:
=======
SELECT * FROM T1 returns zero rows, and SELECT * FROM T2 returns 10 rows.
Now I need the 10 rows from T2.
In other words, if records present in T1, I need them all. If not, I need records from T2.
There are no common columns (for joins).
Now need a single query to achive this. I tried set operators, CASE and DECODE. But I'm unable to solve it.
Please help. Thanks in advance.Iniyavan wrote:
Yes, Justin. I'm sure that this is the way it's modelled. I also find it's tough and odd.Are you sure it's the right way for that data to be modeled? I understand that's the way it is being modeled, but a data model change may be the best option.
Is there any other way, which is simpler, without using RANK?That's the simplest option I can think of. You could also do something like
SELECT t1_col1, t1_col2
FROM (
SELECT t1_col1, t1_col2, rownum rn
FROM (
SELECT t1_col1, t1_col2
FROM (
SELECT t1_col1, t1_col2, 1 tbl
FROM t1
UNION ALL
SELECT t2_col2, t2_col2, 2 tbl
FROM t2
ORDER BY tbl
WHERE rn = 1I'm not sure that's any simpler...
Justin -
How can i fetch records from 3 tables in a single query without using join
Hi.
Can any body please tell me <b>How can i fetch records from 3 tables with a single query without using joins</b>
Thanx
prabhuduttaHi Prabgudutta,
We can fetch the data by using the views concept.
Go throuth this info we can know the how to create view and same like database table only we can fetch the data.
Views conatin the data at runtime only.
Four different view types are supported. These differ in the
way in which the view is implemented and in the methods
permitted for accessing the view data.
Database views are implemented with an equivalent view on
the database.
Projection views are used to hide fields of a table (only
projection).
Help views can be used as selection method in search helps.
Maintenance views permit you to maintain the data
distributed
on several tables for one application object at one time.
step by step creation of Maintenance view:
With the help of the table maintenance generator, you are able to maintain the ENTRIES of the table in SM30 transaction.
It can be set in transaction SE11 - Tools - Table maintenance generator.
Table maintanance Generator is used to manually input values using transaction sm30
follow below steps
1) go to se11 check table maintanance check box under attributes tab
2) utilities-table maintanance Generator-> create function group and assign it under
function group input box. Also assign authorization group default &NC& .
3) select standard recording routine radio in table table mainitainence generator to move table
contents to quality and production by assigning it to request.
4) select maintaience type as single step.
5) maintainence screen as system generated numbers this dialog box appears when you click on create button
6) save and activate table
One step, two step in Table Maintenance Generator
Single step: Only overview screen is created i.e. the Table Maintenance Program will have only one screen where you can add, delete or edit records.
Two step: Two screens namely the overview screen and Single screen are created. The user can see the key fields in the first screen and can further go on to edit further details.
SM30 is used for table maintenance(addition or deletion of records),
For all the tables in SE11 for which Table maintenance is selected , they can be maintained in SM30
Sm30 is used to maintain the table ,i.e to delete ,insert or modify the field values and all..
It creates the maintenance screen for u for the aprticular table as the maintenance is not allowed for the table..
In the SE11 delivery and maintenance tab, keep the maintenance allowed..
Then come to the SM30 and then enter the table name and press maintain..,
Give the authorization group if necessary and give the function group and then select maintenance type as one step and give the screen numbers as system specified..
Then create,,,
Then u will able to see the maintenance view for the table in which u can able to insert and delete the table values...
We use SM30 transaction for entering values into any DB table.
First we create a table in SE11 and create the table maintenance generator for that Table using (utilities-> table maintenance generator) and create it.
Then it will create a View.
After that from SM30, enter the table name and Maintain, create new entries, change the existing entries for that table.
Hope this resolves your query.
Reward all the helpful answers.
Rgds,
P.Naganjana Reddy -
Selecting data from two tables
I am trying to select data from two tables. The only problem that I am running into, is that i am only seeing results from my 'uploads' table. there is also a record in documents where user = 1 that should show up. here is my sql:
$userIDNum = 1;
$sql="Select *
from uploads, documents
WHERE uploads.user = documents.user AND uploads.user = $userIDNum
ORDER BY uploads.title ASC, documents.title ASC";You'll need to explain a little more about your data and what you are trying to accomplish. Your current sql will select all columns from both the uploads and documents tables but only rows where the user id in both tables match, AND the user id equals 1. Is that not what you are seeing? Where's the code that outputs the results?
-
Select data from two tables...!
HI Experts...!
i m a beginner user and i want to select data from two tables proj and prps.....using joins.....and internal tables i have written a code...
SELECT prps~pspnr
prps~objnr
prps~psphi
proj~ernam
proj~erdat
proj~pspnr
INTO table itab -
itab is internal table
FROM prps inner join proj
WHERE pspnr in p_no and prpspsphi = projpspnr.
but there is error in from clause ..please help me....
Advance thanx....Hi,
check the sample code bellow above two reply will solve out your problem but one more extra line in your code pointed out bellow.
TABLES: prps, proj.
TYPES: BEGIN OF ty_test,
pspnr LIKE prps-pspnr,
objnr LIKE prps-objnr,
psphi LIKE prps-psphi,
ernam LIKE proj-ernam,
erdat LIKE proj-erdat,
END OF ty_test.
DATA: itab TYPE STANDARD TABLE OF ty_test WITH HEADER LINE.
SELECT-OPTIONS: p_no FOR prps-pspnr.
SELECT prps~pspnr
prps~objnr
prps~psphi
proj~ernam
proj~erdat
* proj~pspnr " No need for this you have selected this in
* the first line because it is commone so you only need to select from any one
INTO TABLE itab
FROM prps INNER JOIN proj ON ( prps~pspnr = proj~pspnr )
WHERE prps~pspnr IN p_no.
Best Regards,
Faisal
Edited by: Rob Burbank on Dec 24, 2009 12:24 PM -
How can I select columns from a table EMP, using Select statement?.
Hi Friends,
How can I select columns from a table EMP?.
I want to select columns of EMP table, using select statement.
Please reply me urgently.
ShahzadSomething like this:
scott@DBA> select empno,ename,job from emp;
EMPNO ENAME JOB
7369 SMITH CLERK
7499 ALLEN SALESMAN
7521 WARD SALESMAN
7566 JONES MANAGER
7654 MARTIN SALESMAN
7698 BLAKE MANAGER
7782 CLARK MANAGER
7788 SCOTT ANALYST
7839 KING PRESIDENT
7844 TURNER SALESMAN
7876 ADAMS CLERK
7900 JAMES CLERK
7902 FORD ANALYST
7934 MILLER CLERK
14 rows selected.Check the documentation:
http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#sthref9697
Message was edited by:
Delfino Nunez -
Help with listing records from two tables
Hi: I have two tables joined by the first field. The field is primary key in first table. Need help listing records from both tables with each record one line/record.
create table EVENTS (
event_key varchar2(64) primary key,
event_description varchar2(64),
create_time int
create table EVENT_UPDATES (
event_key varchar2(64) NOT NULL ,
update_description varchar2(64),
update_time int
insert into EVENTS values('Event1', 'This is event1', 1);
insert into EVENT_UPDATES values('Event1', 'Ticket created', 3);
insert into EVENT_UPDATES values('Event1', 'Event cleared', 10);
insert into EVENTS values('Event2', 'This is event2', 4);
insert into EVENT_UPDATES values('Event2', 'Ticket created', 6);
insert into EVENT_UPDATES values('Event2', 'Event cleared', 8);I want to print each record in EVENTS table as one line and corresponding records in EVENT_UPDATES as one line/record like this
Event1 1 This is event1
3 Ticket created
10 Event cleared
Event2 4 This is event2
6 Ticket created
8 Event clearedTIA
Raviselect case weight
when 1 then event_key
end key,
time_val,
description
from (
select event_key,
create_time time_val,
event_description description,
1 weight
from events
union all
select event_key,
update_time,
update_description,
2 weight
from event_updates
order by event_key,
weight
KEY TIME_VAL DESCRIPTION
Event1 1 This is event1
3 Ticket created
10 Event cleared
Event2 4 This is event2
6 Ticket created
8 Event cleared
6 rows selected.
SQL> SY. -
Retrive data from two tables into one internal table.
Hi SDN,
I am downloading the Assets data from two tables ANLA,ANLZ.
there is a common field ANL1in both tables and i have to retrive the data by using anl1 into the internal table.
can you please send me the SELECT Syntax for this probl.....
Thank you & Regards,
ManojHi manoj,
Please see the following sample code. But kindly don't use join as it may hamper ur performance. No trouble in using two select query.
data: begin of itab occurs 0,
BUKRS like anla-BUKRS,
ANLN1 like anla-ANLN1,
BDATU like anlz-BDATU,
end of itab.
select anlabukrs anlaANLN1 anlzBDATU into corresponding fields of table itab from anla inner join anlz on anlaanl1 eq anlz~anl1 where (logexp).
Please come back for any clarification.
Thanks and Regards,
saurabh -
Selecting columns from two table is slow but same
I am selecting 27 columns from two tables
which running for more than 30 minutes. but
if I select count(*) with the same query
except the columns it is coming in seconds.
Where is the error?If you post
1) The table definitions for the underlying tables
2) The indexes that are on the tables
3) The two SQL statements you're running
4) The explain plan for both statements
we can probably be of some assistance.
My guess is that the count(*) is able to return much more quickly because the optimizer is able to use a significantly faster query plan that is based on an index which the longer-running query cannot utilize. Without the information I've requested, though, it's hard to do more than speculate.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Delete records from two tables
Hi All,
I have two tables (tableA and tableB) and i have four combination primary key.
How can I delete the records from tableA that are not in tableB?
In my sample below I need to delete the records from year 2013.
I have a loop to insert the new ones.
Thanks
Johnny
create table tableA(
keyA_id number,
keyB_id number,
keyC_id number,
keyD_id number,
amount number,
CONSTRAINT "PK_TABLEA" PRIMARY KEY (keyA_id, keyB_id, keyC_id, keyD_id)
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2011,10);
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2012,40);
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2013,20);
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2011,10);
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2012,30);
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2013,20);
create table tableB(
keyA_id number,
keyB_id number,
keyC_id number,
keyD_id number,
amount number,
CONSTRAINT "PK_TABLEB" PRIMARY KEY (keyA_id, keyB_id, keyC_id, keyD_id)
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2011,10);
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2012,40);
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2014,40);
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2011,10);
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2012,30);
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2014,30);r you trying to do something like below ?
Delete from TableA A
where not exists (select 1 from TableB B where
A.keyA_id=B.keyA_id and
A.keyB_id=B.keyB_id and
A.keyC_id=B.keyC_id and
A.keyD_id=B.keyD_id) -
Select record from database table
how to select a record from data-base table for current month in module-pool, i.e if current month is august then records selected should between 1/08/10 to 31/08/10.
And, i also want to select records for last month i.e if current month is august then records selected should be between 1/07/10 to 31/07/10.
And one thing more, it should work for every scenario. Like for months are changing then it should work according to that.
Example: If month changes to October then current month ll be October and last month ll become September.
Plz help me out.
Moderator message: you chose a better forum this time, but the question is still too basic to be asked here, please (re)search yourself first, these forums are not catering to beginners.
locked by: Thomas Zloch on Aug 8, 2010 9:41 PMHi Nishant,
You can use the option <b>ORDER BY </b> in your SELECT clause.
This is the SAP Documentation for <b>ORDER BY </b> option.
<i>Variant 1</i>
<b>...ORDER BY PRIMARY KEY</b>
<b>Effect</b>
Sorts the selected lines in ascending order by the primary key of the database table. This variant is only permitted for SELECT * ....
<i>Notes</i>
Since views do not have a primary key, specifying ORDER BY PRIMARY KEY only makes sense with database tables. If, however, you do specify ORDER BY PRIMARY KEY with a view, all fields of the view are sorted in ascending order.
<i>Variant 2</i>
<b>ORDER BY f1 ... fn</b>
<i>Effect</i>
Sorts the selected records in ascending order by the specified column references f1 ... fn. If a list is also specified in the SELECT clause, the column references f1, ..., fn must appear in this list.
By supplementing the statement with DESCENDING, you can sort in descending order using any of the fields f1, ..., fn.
The default sort sequence is ascending order, but you can make this explicit by adding the addition ASCENDING.
Consider this code this will select the latest 10 records form DB table(Note can use <b>Variant 2</b> for DB tables also.
REPORT zarun_1.
DATA : it_mara TYPE STANDARD TABLE OF mara WITH HEADER LINE.
START-OF-SELECTION.
SELECT * FROM mara
INTO TABLE it_mara
<b>UP TO 10 ROWS "No of rows you need(give 1 here)
ORDER BY matnr DESCENDING. "Specify the Key Fields here.</b>
LOOP AT it_mara.
WRITE : / it_mara-matnr,
it_mara-mtart.
ENDLOOP.
Regards,
Arun Sambargi.
Message was edited by: Arun Sambargi -
How do I extract matching records from two tables?
I'm trying to extract client records from our client database to put together a very targeted email campaign. As an example, the result I want is a list of names and email addresses of those clients who have a record in our system, have not had a visit in our clinic in the last year, and live within 200 miles of our clinic. I can capture the first two criteria in one extract, and the second in another. I can then import those as tab delimited data into Numbers. What I then need to do is create a third table that represents ONLY those records that exist in both tables.
Can someone tell me if this is possible and if so, how to do it?
I'd be very appreciative of any help, thank you.conejo61 wrote:
I can then import those as tab delimited data into Numbers. What I then need to do is create a third table that represents ONLY those records that exist in both tables.
You can create a column that generates a serial marker on the table from which you want to transfer the data, making all the names that also appear on the other table. Not that the formula will mark only exact matches.
Here's a short example:
Table 1 on the left, is one of the two tables imported from the tab delimited data files. It has other data, but only the names in column A are used to identify records appearing on both tables.
Table 2 on the right, contains the names and other data (represented by the email addresses in column B), to be transferred to the third table.
Column C of this table contains the formula that counts off the rows containing names appearing on both tables. The version below is in C2, and is filled down to the end of the column.
=IF(COUNTIF(Table 1 :: $B,A2)>0,MAX($C$1:C1)+1,"")
Note that jane Doe is not counted (or transferred) as her name is recorded differently on the two tables.
Table 3 is the results table. It contains one formula for each column to be transferred from Table 2 to Table 3.
A2: =IF((ROW()-1>MAX(Table 2 :: $C)),"",LOOKUP(ROW()-1,Table 2 :: $C,Table 2 :: $A))
B2: =IF((ROW()-1>MAX(Table 2 :: $C)),"",LOOKUP(ROW()-1,Table 2 :: $C,Table 2 :: $B))
Regards,
Barry
EDIT: I was working in Numbers '09 when developing this, and got the following warning when I saved a copy as an iWork '08 document:
Referencing row or column ranges that include header or footer cells isn't supported. The formula references were updated to exclude header and footer cells.
The formulas in Table 2::C2 references C1. You may have to ensure that Table 2 does not include a header row.
B.
EDIT2: A check on the file in Numbers '08 showed no apparent change to the formula, and editing Jane Doe's name on table 1 resulted in her name being added to Table 3.
Message was edited by: Barry -
How to pass selected records from one table to another ?
Hi,
In my view i have designed a table with certain records. I need to pass only specific records of this table to another table which been designed in another view. Can anybody please give sum idea for this.
Rgds
Sudhanshuhi,
Refer the below code:
1. I have selected some data from the table.
2. The selected data is moved to some other internal table.
3. Internal table is further binded to the node in which data is to be shown.
data : lo_nd type ref to if_wd_context_node,
lo_nd1 type ref to if_wd_context_node,
lt_temp type wdr_context_element_set,
wa_temp type ref to if_wd_context_element,
ls_node1 type sflight,
lt_node1 type STANDARD TABLE OF sflight.
lo_nd = wd_context->get_child_node('CN_MAIN'). <CN_MAIN is my node>
CALL METHOD lo_nd->get_selected_elements <here selected data is moved to lt_temp>
RECEIVING
set = lt_temp.
loop at lt_temp INTO wa_temp.
CALL METHOD wa_temp->get_static_attributes
IMPORTING
static_attributes = ls_node1. <Selected data in work area.>
APPEND ls_node1 TO lt_node1. < Data moved to internal Table>
CLEAR ls_node1.
ENDLOOP.
Finally Internal table is binded to the node required.
lo_nd1 = wd_context->get_child_node('CN_MAIN2').
lo_nd1->bind_table( lt_node1 ).
In your case , map this CN_MAIN2 with the Component Controller and from component controller you can access data in your second view also.
I hope it helps.
Thanx.
Saurav. -
How do you Select data from two tables with similar data amd merge the output together.
I have two Tables containing Sales Data. I want to read the Table a sort by date and accumulate dollars by order date. Then I want to read the second table and accumulate these dollar amounts by date and then merge the records together so that I gave 1 row
with amounts for type A and amounts for type b.
Here are the tables I am looking at.
Select Cast(J.Order_Date As Varchar(11))) As [Order Date]
,Sum(Case when Sales_Code like '%Comm%' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Comm]
,Sum(Case when Sales_Code = '5-Day' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
,Sum(Case when Sales_Code like '%Auto%" then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
,Sum(Case when Sales_Code = '' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Fixed]
,Sum(Case when Sales_Code = 'XX' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Comm)
,Sum(Case when Sales_Code = 'YY' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Auto)
,Sum(Case when Sales_Code = 'ZZ' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Fixed)
from [PRODUCTION].dbo.Job As J
union all
Select Cast(SH.Order_Date As Varchar(11))) As [Order Date]
,Sum(Case when Sales_Code like '%Comm%' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Comm]
,Sum(Case when Sales_Code = '5-Day' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
,Sum(Case when Sales_Code like '%Auto%" then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
,Sum(Case when Sales_Code = '' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Fixed]
,Sum(Case when Sales_Code = 'XX' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Comm)
,Sum(Case when Sales_Code = 'YY' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Auto)
,Sum(Case when Sales_Code = 'ZZ' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Fixed)
from [PRODUCTION].dbo.SO_Detail As SD
Inner Join [PRODUCTION].dbo.SO_Header As SH
on SD.Sales_Order = SH.Sales_Order
Group by J.Order_Date
Order by J.Order_Date Desc
Looking for output like
Order Date Job Comm Job AUto Job Fixed SO Comm SO AUto SO Fixed
Mar-11-2014 100.00 250.00 50.00 200.00 300.00 400.00
Mar-10-2014 500.00 340.00 0.00 110.00 400.00 500.00
Mar-09-2014 600.00 333.00 56.00 210.00 500.00 300.00
Thanks for your help
SWProductionSeeing the output it looks like what you need is this
select COALESCE(p.[Order Date],q.[Order Date]) AS [Order Date],
COALESCE([Job Comm],0) AS [Job Comm],
COALESCE([Job AUto],0) AS [Job AUto],COALESCE([Job Fixed],0) AS [Job Fixed],COALESCE([SO Comm],0) AS [SO Comm],COALESCE([SO AUto],0) AS [SO AUto],COALESCE([SO Fixed],0) AS [SO Fixed]
from
Select Cast(J.Order_Date As Varchar(11))) As [Order Date]
,Sum(Case when Sales_Code like '%Comm%' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Comm]
,Sum(Case when Sales_Code = '5-Day' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
,Sum(Case when Sales_Code like '%Auto%" then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Auto]
,Sum(Case when Sales_Code = '' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [Job Fixed]
,Sum(Case when Sales_Code = 'XX' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Comm)
,Sum(Case when Sales_Code = 'YY' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Auto)
,Sum(Case when Sales_Code = 'ZZ' then (J.Order_Quantity * J.Unit_Price) Else 0 end) As Decimal(11,2) As [SO Fixed)
from [PRODUCTION].dbo.Job As J
)p
full join
Select Cast(SH.Order_Date As Varchar(11))) As [Order Date]
,Sum(Case when Sales_Code like '%Comm%' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Comm]
,Sum(Case when Sales_Code = '5-Day' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
,Sum(Case when Sales_Code like '%Auto%" then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Auto]
,Sum(Case when Sales_Code = '' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [SO Fixed]
,Sum(Case when Sales_Code = 'XX' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Comm)
,Sum(Case when Sales_Code = 'YY' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Auto)
,Sum(Case when Sales_Code = 'ZZ' then SD.Ext_Amt Else 0 end) As Decimal(11,2) As [Job Fixed)
from [PRODUCTION].dbo.SO_Detail As SD
Inner Join [PRODUCTION].dbo.SO_Header As SH
on SD.Sales_Order = SH.Sales_Order
Group by J.Order_Date
)q
on p.[Order Date] = q.[Order Date]
Order by COALESCE(p.[Order Date],q.[Order Date]) Desc
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Selecting Records from one table where records don't exist in a linked table
Post Author: RMC
CA Forum: Crystal Reports
Tables:
Stock (Main Table)
Transactions (Left Outer Join)
Criteria:
Select all items with no transactions between a selected date range.
The items will exist in Main table but I want to select all items that haven't been in a transaction between a date range so I can identify no movement with stock items just sitting in the database doing nothing.
Any suggestions??Post Author: yangster
CA Forum: Crystal Reports
Sorry for the delay. Dam meetings all day yesterday.You are essentially looking for something that doesn't exist in the db so you need to look at it from a different approach.You definitely don't want to use a full outer join. From what i can tell from your description above you are looking for stocks that are inactive/idle.So you need not look at data that doesn't exist but the last activity date.So you'd want something along the lines ofselect s.stock_name, s.stock_blah, max(t.transaction_date) Transaction_datefrom stocks sjoin transactions t on s.itemid = t.itemidwhere whatever restrictions you need to addgroup by s.stock_name, s.stock_blahthis will produce one record for each stock you have in the stock table showing you only the last date of activityput that in a command in crystalin the selection expert in crystal reports put in a simple criteriatransaction_date <= some datethis will only pull in records based on your date selection so if you say give me all records from dec 31, 2006 you will know all the records being pulled in are stocks that have been idle since dec 31, 2006 or earlierlet me know if this doesn't work
Maybe you are looking for
-
When i pull firefox back up i want all my tabs to appear in seperate tab windows.
-
Upgraded to Mountain Lion. Where's iPhoto?
I just upgraded to Mountain Lion a few days ago and I can't find iPhoto. I read on another thread that I can log in with my Apple ID, click on options before purchasing and I should be able to download it free. Well, I signed into the App Store and
-
Upgrade from 10.1 to 10.2
dear all , if i have oracle database 10.1.0 on windows and i have another server on unix can you tell me the best method to transfer database from windows to unix ??? another question if i have 10.1.0 and i need to upgrade it to 10.2.0 what i do ???
-
Error Log deteted by Hotspot Virtual Machine file "hs_err_pid320.log"
# An unexpected error has been detected by HotSpot Virtual Machine: # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c9110f3, pid=320, tid=3288 # Java VM: Java HotSpot(TM) Client VM (1.5.0_10-b03 mixed mode, sharing) # Problematic frame: # C [ntdll
-
Limited to 99 photos in slideshow
I am running idvd 6 wiith current updates, slideshow of about 280 was burned to dvd and will play completely in the computer but will stop at slide 99 when played in dvd player. Another issue is the photos lost sharpness when viewed on computer in th