Get query result in E-mail

Hi Everyone,
I am trying to get SQL Query Result in e-mail with proper format.
I tired DB mail but result is not in proper format . It's hard to read from attachment. 
From Below Query HTML format showing first 3 columns good after that all getting mixed up. 
Select Ticktsno,customer_Id,Phone,Open date-time,OpenedBy,Assign_to,Category,Support_level,Incident_type,Description from dbo.query_result. 
HTML Code: 
 if @@ROWCOUNT > 0
begin
declare @emailSubject varchar(100),
  @columnHeaders varchar(1000),
  @tableHTML nvarchar(max)
select @emailSubject = 'My Results Email',
      -- Subject of Email
  @columnHeaders = 'tickets</th><th>Customer</th><th>Phone</th><th>Open Date/Time</th><th>OpenedBy</th><th>Assign_To</th><th>Category</th><th>Support_Level</th><th>Incident_Type</th><th>Status</th><th>DEscription'
   -- Column headers (must put </th><th> between each header)
set @tableHTML =
  '<div><b>My Email Header</b></div><br>' + -- This is the bold text at the top of your email
  '<table border="1" cellpadding="5"><font face="Calibri" size=2>' +
  '<tr><th>' + @columnHeaders + '</th></tr>' +
  convert(nvarchar(max),
   SELECT td =  Tickets,       '',
                    td =  Customer, '',
                    td =  Phone, '',
                    td = [Open Date/Time], '',
                    td = OpenedBy, '',
                    td = Assign_To,
                    td = Category,
                    td =  Support_Level,
                    td = Incident_Type ,
td = [Description]         
                     from master.dbo.QueryResult_2000
   for xml path('tr'), type))
  +'</font></table>'
EXEC msdb.dbo.sp_send_dbmail @recipients='[email protected]',
    @subject = 'Query Result',
    @body = @tableHTML,
    @body_format = 'HTML' ;
end
What changes should make in HTML code to get report in proper HTML  format
Please Mark As Answer if it is helpful. \\Aim To Inspire Rather to Teach A.Shah

Thanks Uri for kind reply..I was able to edit that script. Script is running fine from SSMS and sending e-mail notification. But When I am running from SQK agent job getting successful but not getting e-mail notification.
I enabled the profile from SQL job properties also. 
Any thoughts on this?
Please Mark As Answer if it is helpful. \\Aim To Inspire Rather to Teach A.Shah
Hi Logicinisde,
According to your description, if you run the scripts in the SSMS, it can send an email with HTML format to your mailbox. When you run this scripts by using SQL Server Agent job, it can show running successfully but you could not get any email. We need to
verify if you select the correct Mail profile. After configuring the alert system, restart the SQL Server Agent service. If you experience any problems sending e-mail notifications through the SQL Server Agent, check the service account that the agent is running.
If the SQL Server Agent is running with one of the built-in accounts like the Local System account, resources outside the SQL Server machine will be unavailable. This includes SMTP mail servers that are on other machines. If this is the case, change the service
account for the SQL Server Agent to a domain account to resolve this issue.
For more information about using Database Mail in SQL Server and using Database Mail with SQL Server Agent, you can review the following articles.
http://www.idevelopment.info/data/SQLServer/DBA_tips/Database_Administration/DBA_22.shtml
http://technet.microsoft.com/en-us/library/ms190606(v=sql.105).aspx
Regards,
Sofiya Li
Sofiya Li
TechNet Community Support

Similar Messages

  • How to get query result in comma dilimited text or excel file?

    Does anybody know how to get query results in comma delimited
    text file or excel file, I tried spool abc.txt, but the result
    showed some ------ lines
    Thanks

    Try doing this in your sql scripts
    set heading off
    set pagesize 0
    set linesize 4000
    set feedback off
    set verify off
    set trimespace on
    set colsep ","
    spool output.txt
    select * from dual (or whatever you are querying
    spool off
    There may be a couple other set statement that you could add but
    this should get you started in the right direction

  • Getting query results from a PL/SQL procedure

    Hi! So, I’m a little stumped and I can’t seem to find the answer to what I believe is probably a simple question…
    So, here goes… I have a big ol’ union query that I use to create a report on a page, it’s about 25k – not over the 32k limit, but fails to be able to compile every time (I always get a 400 – Bad Request error). I’m not sure why this is happening, but I can remove a union statement and it compiles just fine – so it has something to do with the size of the query. ANYWAY – I’ve resolved that I should put this bad boy into the database as a stored procedure and just call it from Apex, my problem is I can’t figure out quite how to do this with variables, etc.…
    Instead of giving you my whole big query, I’ll use the emp table as the concept is the same:
    Say we have a query that creates a report on a page:
    select empno, ename, job, mgr, hiredate, sal, comm, deptno
    from emp
    where job = :P_JOB
    and hiredate >= :P_HIREDATE;
    How would I take this query, create it as a stored procedure on the db, pass the variables from Apex and return the query result set from the stored proc as a report?
    I really appreciate any help on this!
    Best,
    Gilcrest

    Hi Gilcrest,
    You should create the query as a View and use the view name and the WHERE clause in the report's sql source.
    Andy

  • How to get Query Results based on Analysis Authorization Ranges????

    Hi Experts,
    I have gone through the lot of SDN Links, however not able to find the answer to my question.
    I have an Authorization Issue, “NO Authorization “
    Error : EYE 007 ( Insufficient Authorizations )
    <b>Here is the issue:</b>
    Need to see the complete query result when I gave the range in Analysis Authorization for Controlling Area 001-005. Controlling Area is auth relevant and right now a variable is inserted in the query for it. If I select Controlling Area 001, the result for Controlling Area 001 is displayed in query. If 002 then also displayed. If I do not enter anything, then I get the <b>Eye 007 error message</b>.
    I am not sure how do I display/authorize the entire result in the query for all the Controlling Areas, I have authorized user to see??
    <b>Its really urgent, please help..!</b>
    Here are the logs:
    Authorization Check Log
    Date and Execution Time (Local Server)
    Execution Date: 06.09.2007
    Execution Time: 14:48:41
    Executed Query: 0CCA_C11/GBCCA_MP01_Q0002_AP
    Executed by User ZBI_TEST_001
    Executed with Analysis Authorizations of Another User ZBI_TEST_001
      InfoProvider Check  
    Building the Buffer...
    ...Buffer Built
    Are there authorizations for accessing InfoProvider 0CCA_C11 with activity 03?
    Authorization exists for general access to InfoProvider 0CCA_C11 with activity 03 
      InfoProvider Check  
    Authorization exists for general access to InfoProvider 0CCA_C11 with activity 03 
      Relevant Characteristics for Detailed Authorization Check  
    (Characteristics with Full Authorization Are Not Listed!)
      List of Effective Authorization-Relevant Characteristics for InfoProvider 0CCA_C11:  
    0CO_AREA 
    0TCAACTVT 
      Relevant Characteristics for Detailed Authorization Check  
    (Characteristics with Full Authorization Are Not Listed!)
      List of Effective Authorization-Relevant Characteristics for InfoProvider :  
    List Is Empty:
      There Are No Characteristics That Have to Be Checked in Detail  
      Authorization Check  
      Detail Check for InfoProvider 0CCA_C11  
      Preprocessing:  
    Selection Checked for Consistency, Preprocessed and Supplemented As Needed
    Subselection (Technical SUBNR) 1
    Check Node Definitions and Value Authorizations...
    Node- and Value Authorizations Are OK
    End of Preprocessing
    Filling the Buffer...
    ...Buffer Filled
      Main Check:  
      Subselection (Technical SUBNR) 1  
    Supplementation of Selection for Aggregated Characteristics
      No Check for Aggregation Authorization Required  
    Following Set Is Checked  Comparison with Following Authorized Set  Result  Remaining Set 
    Characteristic  Contents 
    0CO_AREA
    0TCAACTVT
    SQL Format:
    CO_AREA = '0003'
    AND TCAACTVT = '03'
    Characteristic  Contents 
    0CO_AREA  I BT 0001 0005
    0TCAACTVT  I EQ 03
    I EQ 16
    Authorized   
      Subselection (SUBNR) Is Authorized  
      Authorization Check Complete  
      Authorization Check  
      Detail Check for InfoProvider 0CCA_C11  
      Preprocessing:  
    Selection Checked for Consistency, Preprocessed and Supplemented As Needed
    Subselection (Technical SUBNR) 1
    Check Node Definitions and Value Authorizations...
    Node- and Value Authorizations Are OK
    End of Preprocessing
    Filling the Buffer...
    ...Buffer Filled
      Main Check:  
      Subselection (Technical SUBNR) 1  
    Supplementation of Selection for Aggregated Characteristics
      No Check for Aggregation Authorization Required  
    Following Set Is Checked  Comparison with Following Authorized Set  Result  Remaining Set 
    Characteristic  Contents 
    0CO_AREA
    0TCAACTVT
    SQL Format:
    TCAACTVT = '03'
    Characteristic  Contents 
    0CO_AREA  I BT 0001 0005
    0TCAACTVT  I EQ 03
    I EQ 16
    Partially or Fully Authorized (Intersection)   Characteristic  Contents 
    0CO_AREA
    0TCAACTVT
    SQL Format:
    ( CO_AREA < '0001'
    OR CO_AREA > '0005' )
    AND TCAACTVT = '03'
    Value selection partially authorized. Check of remainder at end
    Following Set Is Checked  Comparison with Following Authorized Set  Result  Remaining Set 
    Characteristic  Contents 
    0CO_AREA
    0TCAACTVT
    SQL Format:
    ( CO_AREA < '0001'
    OR CO_AREA > '0005' )
    AND TCAACTVT = '03'
    Characteristic  Contents 
    0CO_AREA  I BT 0001 0005
    0TCAACTVT  I EQ 03
    I EQ 16
    Not Authorized   
    All Authorizations Tested
      Message EYE007: You do not have sufficient authorization  
      No Sufficient Authorization for This Subselection (SUBNR)  
    Following CHANMIDs Are Affected:
    184 ( 0CO_AREA )
      Authorization Check Complete  

    Hi,
        Have you defined the vaule for 0CO_AREA as BT 001-005 in you Authorization for 0CO_AREA.Also how have you defined your Authorization Variable on the query? Have you define as select options or interval? I thing you need to define it as interval or select options.
    Hope it helps,
    Cheers,
    Balaji

  • Get query results to itab; using RSCRMBW_REPORT?

    Hi,
    I am interested in "calling" a BW query from an R/3 system and getting the results in an internal table.  I'm on the path of using function module RSCRMBW_REPORT, but I'm not sure how to use it since I keep getting an error: "Could not find query definition:" - maybe I am not using the correct parameters?
    Currently I'm using:
    I_MODE                          OPEN
    I_REPORTUID                     Z0VENDOR_TEST >>>the name of the query that I'm trying to test
    (along with the defaults).
    If anyone can please help out; I'd really appreciate it
    Thanks!!

    Hi
    look at these threads:
    Re: Calling BW queries programatically
    Re: RSCRM_BAPI
    I hope it helps.
    Edan

  • UTL_SMTP to send all the query result in one mail

    Hello All,
    I have a procedure for Oracle User Password Expiry Notification via mail using UTL_SMTP
    Also, I have created a table (email_address) to store the email addresses
    TableName: EMAIL_ADDRESS (username, email)
    USERNAME
    EMAIL
    HR
    [email protected]
    SH
    [email protected]
    SAMPLE
    [email protected]
    TEST
    [email protected]
    My PL/SQL
    declare
    crlf VARCHAR2(2)  := chr(13)||chr(10);
    CURSOR c1 IS SELECT
    e.alternate_name,e.email,e.cc,u.expiry_date, round(u.expiry_date-sysdate) as date_diff
    FROM dba_users u, email_address e
    WHERE u.username=e.username;
    username VARCHAR2(50);
    email VARCHAR2(250);
    expire_date varchar2(50);
    date_diff  varchar2(50);
    sender VARCHAR2(40) := '[email protected]';
    message VARCHAR2(200);
    mailhost VARCHAR2(30) := 'x.x.x.x'; 
    mail_conn UTL_SMTP.connection;
    BEGIN
    message:=' user will expire in '; 
    OPEN c1;
    LOOP
    FETCH c1 INTO username,email,expire_date,date_diff;
    EXIT WHEN c1%NOTFOUND; 
    mail_conn := UTL_SMTP.open_connection(mailhost, 25);
    UTL_SMTP.helo(mail_conn, mailhost);
    UTL_SMTP.mail(mail_conn, sender);
    UTL_SMTP.rcpt(mail_conn, email);
    UTL_SMTP.data(mail_conn, 'To: ' || email || crlf || 'Subject: ' || '[Test Mail]: Oracle User Password Expiry Reminder(user: '|| username ||')' || crlf || 'Password of ' || username||message||' '||date_diff||'days'||' (Expiry Date: ' || expire_date ||');
    UTL_SMTP.quit(mail_conn);
    END LOOP;
    CLOSE c1;
    END;
    But when I execute the above PL/SQL, I am getting 4 different mails having each user password expiry information.
    But I want all the user password expiry information in one mail.
    Is it possible??

    declare
    crlf VARCHAR2(2)  := chr(13)||chr(10);
    CURSOR c1 IS SELECT 
    e.alternate_name,e.email,e.cc,u.expiry_date, round(u.expiry_date-sysdate) as date_diff 
    FROM dba_users u, email_address e 
    WHERE u.username=e.username;
    username VARCHAR2(50); 
    email VARCHAR2(250);
    expire_date varchar2(50);
    date_diff  varchar2(50);
    sender VARCHAR2(40) := '[email protected]';  
    message VARCHAR2(200);
    final_message varchar2(1000);
    mailhost VARCHAR2(30) := 'x.x.x.x';  
    mail_conn UTL_SMTP.connection; 
    BEGIN 
    message:=' user will expire in ';  
    OPEN c1; 
    LOOP 
    FETCH c1 INTO username,email,expire_date,date_diff; 
    EXIT WHEN c1%NOTFOUND;  
       final_message := final_message || 'user: '|| username ||')' || crlf || 'Password of ' || username||message||' '||date_diff||'days'||' (Expiry Date: ' || expire_date || '): ';
    END LOOP; 
    CLOSE c1;
    mail_conn := UTL_SMTP.open_connection(mailhost, 25); 
    UTL_SMTP.helo(mail_conn, mailhost);
    UTL_SMTP.mail(mail_conn, sender); 
    UTL_SMTP.rcpt(mail_conn, email);
    UTL_SMTP.DATA(mail_conn, 'To: ' || email || crlf || 'Subject: ' || '[Test Mail]: Oracle User Password Expiry Reminder('||final_message||')';
    UTL_SMTP.quit(mail_conn);
    END;

  • Search criterias in one page, the query results in another page?

    Hi, can I put search criterias in one page, and get query results in another page?
    Need help
    Thanks in advance
    karman

    If you meant a situation like: Page 1 has some items and page 2 has a report which refers page 1 itemsThen your report _query would fetch proper results provided the page 1 item values are available in the session_.
    That is, after submitting their values(using page submit,dynamic action,ajax etx) to session state , their values would be available in any page (anywhere in that session ) , until the page cache for the item page(page 1) is cleared.

  • Problem viewing Query Result

    Hi- I occasionally come across this issue when I run any query in SQL Developer (3.0.02), the Query Result tab shows a bold red Exclamation point and the display grid is blank. It says "Fetched 50 rows in 0.235 seconds" but the results aren't displayed. There is nothing wrong with the queries so it seems like some type of display problem but I can't figure out how to fix it. Like I said, it doesn't happen all the time and I run the same saved queries so I know it's not a problem with the actual queries. Has anyone ever seen or heard of this before?

    Hi,
    Sounds like you are using an early adopter version of 3.0. Why not upgrade to the latest production release (3.1.07.42)?
    A similar situation is described in this old thread:
    Re: Randomly not getting query results
    Regards,
    SQL Developer Team

  • How to get the query result of improvement (Before and After ) using sql de

    how to get the query result of improvement (Before and After ) using sql developer.

    Check
    http://www.oracle.com/technetwork/articles/sql/exploring-sql-developer-1637307.html

  • How to get the dynamic query result

    If in one query, there is the amount range dimension, based on different dimension value combination, the customer revenue should be refreshed into different range, how to make it by cube?
    eg.
    Customer Store    Material  Month    Amount
    C001     M & S    Tennis    2005/01   "10"
    C001     Douglas  Tennis    2005/02   "60"
    C002     M & S    Soccer    2005/01    "1"
    C002     M & S    Soccer    2005/02    "50"
    C002     M & S    Tennis    2005/02    "50"
    C003     Douglas  Tennis    2005/01    20
    Query condition:
    Time Customer Amount Range     Amount
    2005 C001     0~50_____________0
    2005 C001     51~100___________70
    2005 C001     100 +____________0
    2005 C002     0~50_____________0
    2005 C002     51~100___________0
    2005 C002     100+_____________101
    2005 C003     0~50_____________20
    2005 C003     51~100___________0
    2005 C003     100+_____________0
    However, if I drill down Time into month, the result is total different, I only list the result related to customer C001
    Time     Customer  Amount Range    Amount
    2005/01  C001      0~50____________10
    2005/01  C001      51~100__________0
    2005/01  C001      100 +___________0
    2005/02  C001      0~50____________0
    2005/02  C001      51~100__________60
    2005/02  C001      100 +___________0
    Any good solution on that? Thanks for any input.
    Message was edited by: Lei Shao

    Hi, Sen,
    I used your solution in my infocube and query, where I created a structure with 'between'. However, it is still the simple summation in different amount range.
    Just like the following:
    Sales ORG / Sales Office / Sales Rep / Amount
    East      / Atlanta      / 1001      / 3
    East      / Atlanta      / 1002      / 4
    So the query result is the same:
    S-ORG / S-Office / S-Rep / Amount Range / Amount
    East  / Atlanta  / 1001  / 0~5          / 3
    East  / Atlanta  / 1001  / 5+           / 0
    East  / Atlanta  / 1002  / 0~5          / 4
    East  / Atlanta  / 1002  / 5+           / 0
    When I remove 'drill down' for Sales Rep, the result is:
    S-ORG / S-Office / Amount Range / Amount
    East  / Atlanta  / 0~5          / 7
    East  / Atlanta  / 5+           / 0
    However our expection for the result is different, because in business traction, if we remove sales rep, the sales org and sales office will get the sub-total like this: (we can image it with ABAP program sub-total)
    Sales ORG / Sales Office / Amount
    East      / Atlanta      / 7
    So our expection for the result is:
    S-ORG / S-Office / Amount Range / Amount
    East  / Atlanta  / 0~5          / 0
    East  / Atlanta  / 5+           / 7
    Therefore, any good suggestion for this?
    Thanks a lot
    Regards,
    LS

  • How can I get the result of web forms by mail ????

    Hi,
    please,
    can someone help me, I spent two days looking on internet to know what I need to install on the web server to get the result of web forms and send it by mail.
    I can't find anything and I don't know what I should look for too ?
    Thanks

    Hi,
    thanks for your answer but I was in fact trying to install Formication, I already opened a thread here :
    http://discussions.apple.com/thread.jspa?threadID=841656&tstart=0
    Can you help me with this one ?
    I installed the last release of FormMail and it start to work now but I'm more insterested in "Formication".
    I'm since two days trying to find documentation for this one and I finally decided to write directly to the author as I really can't find anything to install and use it.
    If you know how to install or have any direction to give me it would be really fine.
    Thanks

  • Ho to get script result with query's in 11g

    Hi,
    While doing refresh tasks i need to run some select query's. am so lazy to check each query one by one so i placed all querys in one script and i ran
    i went fine but it is showing only result of the query but it is not showing query. Can we get query and out put of query through script.
    Ex : one.sql
    the script have below querys
    select name from v$database;
    select count(*) from v$datafile;
    select count(*) from dba_db_links;
    select owner,db_link from dba_db_links;
    can any one help me on this..
    Regards
    Edited by: 889571 on May 19, 2013 2:59 PM

    [oracle@localhost samples]$ cat sample.sql
    set term on echo on
    select name from v$database;
    select count(*) from v$datafile;
    select count(*) from dba_db_links;
    select owner,db_link from dba_db_links;
    [oracle@localhost samples]$ sqlplus user1/user1 @sample.sql
    SQL*Plus: Release 11.2.0.2.0 Production on Sun May 19 16:06:20 2013
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> select name from v$database;
    NAME
    ORCL
    SQL> select count(*) from v$datafile;
      COUNT(*)
             6
    SQL> select count(*) from dba_db_links;
      COUNT(*)
             0
    SQL> select owner,db_link from dba_db_links;
    no rows selected
    SQL>

  • Use APD to get Rank from TopN query result to target for Universe

    Hello,
    I am trying to take a query result set where I am calculating a key figure as Rank and run it through an APD to write to a DSO.
    This is a top 5 query for a dashboard.  I keep getting an MDX failure on the query.
    Any ideas? 
    My ultimate goal is to set up a process to take TopN query results and get them into a target that can be used in a Universe.
    Thanks,
    Chris

    Hello Chris,
    I recommend to post this query to the [Universe Designer and Business Views Designer|Semantic Layer; forum.
    This forum is dedicated to topics related to the universes and business views.
    It is monitored by qualified technicians and you will get a faster response there.
    Also, all Enterprise Information Management queries remain in one place and thus can be easily searched in one place.
    Thanks a lot,
    Falk

  • How to comple query to get correct results?

    Hello,
    I am having problems getting the results from a query.  I have 2 tables:
    Marriage table
    People1ID People2ID DateMarried
    1 4 5/5/2014
    5 7 6/5/2014
    2 3 7/5/2014
    People table
    PeopleID First Last
    1 Bob Jones
    2 Mary Smith
    3 Steve Smith
    4 Jane Jones
    5 Robert Apple
    6 Julie Jackson
    7 Diane Apple
    Looking for result like this:
    First1 Last1 First2 Last2 DateMarried
    Bob Jones Jane Jones 5/5/2014
    Robert Apple Diane Apple 6/5/2014
    Mary Smith Steve Smith 6/5/2014
    Paul

    I'm little confuse on your expected result specially on the third row column "Datemarried". Are you sure that its 6/5/2014. I think its 7/5/2014. Anyway you can try this query.
    select b.[First], b.[Last],
    c.[First],c.[Last], 
    a.DateMarried from marriage a
    left outer join People b
    on a.people1id=b.peopleid
    left outer join People c
    on a.people2id=c.peopleid
    this will be the result:
    First Last
    First Last
    DateMarried
    Bob Jones
    Jane Jones
    5/5/2014
    Robert Apple
    Diane Apple
    6/5/2014
    Mary Smith
    Steve Smith
    7/5/2014

  • HOW TO CHANGE SQL QUERY TO GET SPECIFIC RESULT

    I HAVE FOLLOWING QUERY AND ITS FUNCTIONING BUT I WANT ALL THOSE RECORD SHOULD BE DISPLADE WICH HAVE NO TRANSACTION IN SALES ANS SALES RETURN WHILE RETREVING DATA FROM DATABASE.
    I TRIED TO USE + OPERATOR BUT I DON'T KNOW HOW TO CHANGE THE QUERY TO GET THE RESULT
    MAIN TABLE IS BEING USED TO FETCH RECORD
    SALES_HEADER,SALES_DETAIL
    SALES_HEADERR,SALES_DETAILR
    STOCK_REG
    AND THE QUERY IS
    select s.item_code,S.DESCR,s.GRAND_TOTAL,
    sum(decode(d.dayno,01,NVL(S.QTY,0),0)) DAY1,
    sum(decode(d.dayno,02,NVL(S.QTY,0),0)) DAY2,
    sum(decode(d.dayno,03,NVL(S.QTY,0),0)) DAY3,
    sum(decode(d.dayno,04,NVL(S.QTY,0),0)) DAY4,
    sum(decode(d.dayno,05,NVL(S.QTY,0),0)) DAY5,
    sum(decode(d.dayno,06,NVL(S.QTY,0),0)) DAY6,
    sum(decode(d.dayno,07,NVL(S.QTY,0),0)) DAY7,
    sum(decode(d.dayno,08,NVL(S.QTY,0),0)) DAY8,
    sum(decode(d.dayno,09,NVL(S.QTY,0),0)) DAY9,
    sum(decode(d.dayno,10,NVL(S.QTY,0),0)) DAY10,
    sum(decode(d.dayno,11,NVL(S.QTY,0),0)) DAY11,
    sum(decode(d.dayno,12,NVL(S.QTY,0),0)) DAY12,
    sum(decode(d.dayno,13,NVL(S.QTY,0),0)) DAY13,
    sum(decode(d.dayno,14,NVL(S.QTY,0),0)) DAY14,
    sum(decode(d.dayno,15,NVL(S.QTY,0),0)) DAY15,
    sum(decode(d.dayno,16,NVL(S.QTY,0),0)) DAY16,
    sum(decode(d.dayno,17,NVL(S.QTY,0),0)) DAY17,
    sum(decode(d.dayno,18,NVL(S.QTY,0),0)) DAY18,
    sum(decode(d.dayno,19,NVL(S.QTY,0),0)) DAY19,
    sum(decode(d.dayno,20,NVL(S.QTY,0),0)) DAY20,
    sum(decode(d.dayno,21,NVL(S.QTY,0),0)) DAY21,
    sum(decode(d.dayno,22,NVL(S.QTY,0),0)) DAY22,
    sum(decode(d.dayno,23,NVL(S.QTY,0),0)) DAY23,
    sum(decode(d.dayno,24,NVL(S.QTY,0),0)) DAY24,
    sum(decode(d.dayno,25,NVL(S.QTY,0),0)) DAY25,
    sum(decode(d.dayno,26,NVL(S.QTY,0),0)) DAY26,
    sum(decode(d.dayno,27,NVL(S.QTY,0),0)) DAY27,
    sum(decode(d.dayno,28,NVL(S.QTY,0),0)) DAY28,
    sum(decode(d.dayno,29,NVL(S.QTY,0),0)) DAY29,
    sum(decode(d.dayno,30,NVL(S.QTY,0),0)) DAY30,
    sum(decode(d.dayno,31,NVL(S.QTY,0),0)) DAY31,
    sum(S.qty) TU
    FROM
    (select nvl(sales_detail.qty+sales_detail.bonus,0) as qty,
    sales_detail.item_code AS ITEM_CODE,
    stock_reg.descr AS descr,
    s_date as sale_date,stock_reg.GRAND_TOTAL AS GRAND_TOTAL FROM
    SALES_DETAIL,SALES_HEADER,STOCK_REG
    WHERE SALES_DETAIL.S_ID = SALES_HEADER.S_ID AND
    SALES_DETAIL.ITEM_CODE = STOCK_REG.ITEM_CODE(+) AND
    STOCK_REG.COMCODE='C1'
    UNION all
    select -1*nvl(sales_detailR.qty+sales_detailR.bonus,0) as qty,
    sales_detailR.item_code AS ITEM_CODE,
    stock_reg.descr AS descr,
    RETURN_date as sale_date,stock_reg.GRAND_TOTAL AS GRAND_TOTAL FROM
    SALES_DETAILR,SALES_HEADERR,STOCK_REG
    WHERE SALES_DETAILR.SR_ID = SALES_HEADERR.SR_ID AND
    SALES_DETAILR.ITEM_CODE = STOCK_REG.ITEM_CODE(+) AND
    STOCK_REG.COMCODE='C1') S,
    (select level as dayno
    from dual
    connect by level <= 31) d
    where d.dayno = to_char(s.sALE_date, 'DD') AND TO_DATE(S.SALE_DATE) BETWEEN '&FROMDATE' AND '&TODATE'
    GROUP BY S.ITEM_CODE,S.DESCR,S.GRAND_TOTAL

    well my query running successfully just the quesion was that i wanted to bring some changes in the query to retrieve the complete record which has no transaction in sales
    for exmple
    if i write the quey
    select dept.deptno,sum(sal) from emp,dept
    where dept.deptno = emp.deptno
    group by dept.deptno
    the recult comes as
    DEPTNO SUM(SAL)
    10 8750
    20 10875
    30 9400
    though there is another deptno which is deptno no 40
    have no sal
    and when i use this query
    select dept.deptno,sum(sal) from emp,dept
    where dept.deptno = emp.deptno(+)
    group by dept.deptno
    it shows the dept no 40 also
    DEPTNO SUM(SAL)
    10 8750
    20 10875
    30 9400
    40
    so to get this i posted query which was to long to understand easily.
    i accept that i sholud post short query to make other understand
    so check out this
    select STOCK_rEG.item_code AS ITEM_CODE,SUM(qty) as qty
    FROM
    SALES_DETAILR,SALES_HEADERR,STOCK_REG
    WHERE SALES_DETAILR.SR_ID = SALES_HEADERR.SR_ID AND
    SALES_DETAILR.STOCKCODE = STOCK_REG.STOCKCODE
    AND RETURN_DATE = '01-APR-08'
    GROUP BY STOCK_rEG.item_code
    ORDER BY TO_NUMBER(ITEM_CODE) ASC
    when i execute this query i get the following result
    ITEM_CODE QTY
    84 2
    102 3
    108 3
    116 6
    166 3
    170 3
    thoug there is other items are aalso available in stock which transaction
    yet not been done or not been sold out/
    so when i use the outer join i get the same result
    select STOCK_rEG.item_code AS ITEM_CODE,SUM(qty) as qty
    FROM
    SALES_DETAILR,SALES_HEADERR,STOCK_REG
    WHERE SALES_DETAILR.SR_ID = SALES_HEADERR.SR_ID AND
    SALES_DETAILR.STOCKCODE(+) = STOCK_REG.STOCKCODE
    AND RETURN_DATE = '01-APR-08'
    GROUP BY STOCK_rEG.item_code
    ORDER BY TO_NUMBER(ITEM_CODE) ASC
    ITEM_CODE QTY
    84 2
    102 3
    108 3
    116 6
    166 3
    170 3
    hope i tried to make u understand on better way

Maybe you are looking for

  • Why does iPhone 5 not work with wifi?, Why does iPhone 5 not work with wifi?

    I have been having very high data usage.  My iPhone 5 will not stay connected to wifi or will totally not work on wifi. Provider is AT&T.

  • Indesign CS5 won't print specific pages within document

    I'm working on Indesign CS5. The issue is with a specific document, and just started happening on version 11. All previous versions of the file have printed with no problems. I have so far determined that it is a document level problem as I can print

  • Ipod Video Scratches

    I really get desperate about the scratches on my Ipod video. I have a problem with my Ipod video 60 GB it is very vulnerable for scratches. After 2 days I had so many scratches that I brought it back to the interdiscount branch in Vevey. When your in

  • Firefox does not function correctly when validating payments with HSBC bank

    When HSBC bank security is invoked by a website within an inline page the confirmed page is presented within the inline subpage in such a way that one cannot continue with the transaction confirmation, consequently the payment verification fails. Goo

  • Enhanced datasource field not replicated

    Hi All, I enhanced 0employe_attr datasource with one custom field. I appened the structure and I wrote user exit and activated . But when i replicate to BW the new field is not replicated. I unchecked the hide field in the datasource and made it to s