Script task to convert output from a sql query into send mail task body formatting

SSIS 2008R2 Version
Code from script task
   Microsoft SQL Server Integration Services Script Task
   Write scripts using Microsoft Visual C# 2008.
   The ScriptMain is the entry point class of the script.
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
namespace ST_29dd6843bd6c4aee9b1656c1bbf55ba8.csproj
    [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
        #region VSTA generated code
        enum ScriptResults
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        #endregion
        public void Main()
            Variables varCollection = null;
            string header = string.Empty;
            string message = string.Empty;
            Dts.VariableDispenser.LockForWrite("User::gsEmailMessage");
            Dts.VariableDispenser.LockForWrite("User::gsWebserviceName");
            Dts.VariableDispenser.LockForWrite("User::gsNoOfCallsInADay");
            Dts.VariableDispenser.LockForWrite("User::gsCalledBySystem");
            Dts.VariableDispenser.GetVariables(ref varCollection);
            //Set the header message for the query result
            if (varCollection["User::gsEmailMessage"].Value == string.Empty)
                header = "Hi, Count is greater then 50 :\n\n";
                //header = "Execute SQL task output sent using Send Email Task in SSIS:\n\n\n";
                header += "----------------------------------------------------------------------------------------------------------------------" + "\n";
                header += string.Format("{0}\t\t\t\t{1}\t\t{2}\n", "WebService Name", "No Of Calls In A Day", "Called By System");
                header += "----------------------------------------------------------------------------------------------------------------------" + "\n";
                varCollection["User::gsEmailMessage"].Value = header;
            //Format the query result with tab delimiters
                 message = String.Format("<HTML><BODY><P>{0}</P><P>{1}</P><P>{2}</P></BODY></HTML>",
                                        varCollection["User::gsWebserviceName"].Value,
                                        varCollection["User::gsNoOfCallsInADay"].Value,
                                        varCollection["User::gsCalledBySystem"].Value);
            varCollection["User::gsEmailMessage"].Value = varCollection["User::gsEmailMessage"].Value + message + "\n";
            Dts.TaskResult = (int)ScriptResults.Success;
Above code will return data in below format and then i send this output in aemail using send mail task.
Hi, count is greater then 50 :
WebService Name                                                         
No Of Calls In A Day                        Called By System
WebServiceone                                                     1                             
Internetbutiken
WebServiceGetdetailstwo                                                  1                             
Internetbutiken
Servicenamethree                                                            2                             
MOB
As you can see above code is not in align as if we service name is shorter then 2nd column get disallign and its not look good.I need output should be like below.
Hi, count is greater then 50 :
WebService Name                                                         
No Of Calls In A Day                        Called By System
WebServiceone                                                              1                             
Internetbutiken
WebServiceGetdetailstwo                                              1                             
Internetbutiken
Servicenamethree                                                          2                             
MOB
Please suggest something...
Thanks 
SR_MCTS

See code explained here
http://microsoft-ssis.blogspot.in/2013/08/sending-mail-within-ssis-part-2-script.html
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
This will not help.As I am not creating smtp connectin ,send from ,send to in script task.I am just creating email body from sql output.

Similar Messages

  • Input result from a SQL-query into a Variable in ProcessFlow

    I am trying to select a value from a table with file names.
    This file name should be input to an ftp function. I use a owb function to read the file name then I try to asign the result to a variable.
    The function GET_FILENAME looks like
    f_name varchar2(30);
    BEGIN
    select distinct FILENAME_SOURCE into f_name from CTL_SOURCE_FILES
    where FILEID = (select min(FILEID) from CTL_SOURCE_FILES where status is null);
    RETURN f_name;
    END;
    When running it as a SQL-script it returns only one row/name.
    When I am running it in the ProcessFlow the following message is found:
    RPE-02040: Internal error: GET_FILENAME cannot be converted to a constant value.

    Let me talk about this in context of a mapping:
    create a mapping :
    use a function within a mapping
    assign the output of the mapping to a mapping input variable"
    use this mapping within your process flow and see if it works.
    if you are directly going to use the output of a function in a process flow , the FTP should be able to accept the filename from the outparam of the function which i am not sure how it works.
    try using the first approach as it is relatively simple and straightforward.

  • Answer from a sql query into a java variable ?

    Hey!
    Got a simple question :
    String dml = ("INSERT INTO student " +
                                         "VALUES ( SELECT MAX(id) +1 FROM student "  +
                                         "','" + student.getFornavn() +
                                         "','" + student.getEtternavn() +
                                         "','" + student.getKlasse() + "')");This sql syntax would work in sql+ , but for some reason not in java.. Need to add 1 to max id every time new student are added , or is there any way i could make sql add a new unique nubmer when id = NULL ?
    The other solution could be to get the answer from SELECT MAX (id) + 1 into a java variable and use that number value in insert query ?
    Or maybe the best would be to make a procedure ?

    Thanks!
    How would the syntax be to execute this procedure in java :
    CREATE OR REPLACE PROCEDURE legg_til_student (p_fnavn student.fornavn%TYPE, p_enavn student.etternavn%TYPE, p_klasseid student.klasseid%TYPE) IS
    v_id student.id%TYPE;
    BEGIN
         SELECT MAX(id) +1 INTO v_id
         FROM student;     
         IF p_klasseid > 3 THEN
         DBMS_OUTPUT.PUT_LINE ('Ugyldig klasseid');
         ELSE
         INSERT INTO student VALUES (v_id, p_fnavn, p_enavn, p_klasseid);
         END IF;
    END;
    /Only this into a stmt sentence ? :
    exec legg_til_student ('Test', 'Test', 2); ? thanks :)

  • Copying SQL Script from Oracle SQL Developer into Excel with formatting

    I need to copy a SQL Script into Excel in order to develop some VBA code. Is there any nice way that I can copy SQL Script from Oracle SQL Developer into Excel and retain its formatting? I am a stickler for having legible, readable SQL and like to have all my columns lined up and aliases lined up. When we used to use SQL Navigator, the tab formatting seemed to copy and paste just fine. Now that we have migrated to Oracle SQL Developer, the formatting seems to get all messed up.
    And suggestions are greatly appreciated and Thanks in advance for your review and am hopeful for an answer.
    Thanks.
    PSULionRP

    I suppose you want a real tabulator instead of spaces. You can configure this in the preferences (SQL Formatter - Oracle). You have to apply it then to your existing code (e.g. CTRL-F7), but new code should get it right from the start.
    Hope that helps,
    K.

  • Script fails when passing values from pl/sql to unix variable

    Script fails when passing values from pl/sql to unix variable
    Dear All,
    I am Automating STATSPACK reporting by modifying the sprepins.sql script.
    Using DBMS_JOB I take the snap of the database and at the end of the day the cron job creates the statspack report and emails it to me.
    I am storing the snapshot ids in the database and when running the report picking up the recent ids(begin snap and end snap).
    From the sprepins.sql script
    variable bid number;
    variable eid number;
    begin
    select begin_snap into :bid from db_snap;
    select end_snap into :eid from db_snap;
    end;
    This fails with the following error:
    DB Name DB Id Instance Inst Num Release Cluster Host
    RDMDEVL 3576140228 RDMDEVL 1 9.2.0.4.0 NO ibm-rdm
    :ela := ;
    ERROR at line 4:
    ORA-06550: line 4, column 17:
    PLS-00103: Encountered the symbol ";" when expecting one of the following:
    ( - + case mod new not null &lt;an identifier&gt;
    &lt;a double-quoted delimited-identifier&gt; &lt;a bind variable&gt; avg
    count current exists max min prior sql stddev sum variance
    execute forall merge time timestamp interval date
    &lt;a string literal with character set specification&gt;
    &lt;a number&gt; &lt;a single-quoted SQL string&gt; pipe
    The symbol "null" was substituted for ";" to continue.
    ORA-06550: line 6, column 16:
    PLS-00103: Encountered the symbol ";" when expecting one of the following:
    ( - + case mod new not null &lt;an identifier&gt;
    &lt;a double-quoted delimited-identifier&gt; &lt;a bind variable&gt; avg
    count current exists max min prior sql stddev su
    But when I change the select statements below the report runs successfully.
    variable bid number;
    variable eid number;
    begin
    select '46' into :bid from db_snap;
    select '47' into :eid from db_snap;
    end;
    Even changing the select statements to:
    select TO_CHAR(begin_snap) into :bid from db_snap;
    select TO_CHAR(end_snap) into :eid from db_snap;
    Does not help.
    Please Help.
    TIA,
    Nischal

    Hi,
    could it be the begin_ and end_ Colums of your query?
    Seems SQL*PLUS hs parsing problems?
    try to fetch another column from that table
    and see if the error raises again.
    Karl

  • Re: How to converting from PL/SQL query to T-SQL query

    How to converting from PL/SQL query to T-SQL query... Its Urgent

    Download the
    SQL Server Migration Assistant for Oracle.  It will convert whole Oracle databases, or single queries or PL/SQL stored procedures.
    With caution that If your database is using Collation which is case sensitive SSMA will not work.SSMA doesnt guarantees 100% for conversion of Queries/stored proc /database if it fails to do so for some queries you will have to do it manually.
    But you can try
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • Can I put a SQL query into a bind variable and then use it to output report

    Hi,
    Can I put a SQL query into a bind variable and then use it to output report?
    I want to create a report and an item "text area" (say P1_TEXT) which can let user to input a SQL query(they are all technical users and knows SQL very well). Then, I use a bind variable (that text area) to store the SQL statement. Then, I add a submit button and I want to use the following to output the report:
    select * from (:P1_TEXT);
    Do you think it is possible to do that? Any known limitations for APEX in this area?
    Thanks a lot,
    Angela

    You can, but make sure it's what you really want to do. Make sure you are VERY familiar with SQL Injection. Most people who know what it is, go out of their way to prevent SQL Injection. You're going out of your way to allow it.
    You can try using &P1_TEXT. instead of bind variable syntax. Bind variables are one of the best ways to prevent SQL Injection, which is why it's not working for you.
    Once again, I strongly urge you to consider the implications of your app, but this suggestion should get it working.
    Tyler

  • Facing challenges during creation of replica of .IDF file/Pdf output from 4.7 system into of Adobe forms in ECC 6.0 system

    Facing challenges during creation of replica of .IDF file/Pdf output from 4.7 system into of Adobe forms in ECC 6.0 system.
    If anybody has easy way to make those forms...
    Please suggest...

    Hi Shabeer,
    the first thing is that you are running on a very very low RAM.
    For ECC 6.0 with dual stack SAP System to run you should have atleast 4 GB of RAM.
    For your Dispatcher issue kindly check the status of your Oracle database and the connection from SAP To Database.
    You can check the oracle status using brtools utility.
    Regards,
    Prem

  • Get Number of rows from a sql query.

    I am reading data from a sql query in a BLS transaction and I would like to know the number of rows returned.
    Is there an easy way to do this without looping through the table?
    Thanks Jasper

    Hi Jasper,
    You can use the XPATH count function similar to  this:
    GetTagList.Results{count(/Rowsets/Rowset/Row)}
    Kind Regards,
    Diana Hoppe

  • Retreiving a value from and SQL query

    If anyone can give me sample code or pointers to retreive a value from an sql query, I'd be greatful.
    Source code I've muddled together so far:
    Class seqNumType = Class.forName(nameOfClass);
    Constructor theConstructor = seqNumType.getConstructor(null);
    Object seqNumInstance = theConstructor.newInstance(null);
    String theStatement = "SELECT value INTO v_seqnum FROM DUAL;";
    OracleCallableStatement ocs = (OracleCallableStatement)conn.prepareCall(theStatement);
    ocs.registerOutParameter( 1, OracleTypes.NUMBER, 0);
    Method method = seqNumInstance.getClass().getMethod("getORADataFactory", null);
    seqNumInstance = ocs.getORAData(1, (ORADataFactory)method.invoke(null,null));
    ocs.execute();
    Problem with this seems to be the ORADataFactory isn't a method of the class, but as I'm thumbling around in the dark here a little, I've no idea where to go from here. Is this just generally overkill anyway?
    Suggestions?
    Cheers for any help.

    Like this:
                ResultSet resultSet=statement.executeQuery("SELECT * FROM TEST");
                while(resultSet.next())
                    for(int i=0;i<resultSet.getMetaData().getColumnCount();i++)
                        System.out.print(resultSet.getObject(i+1).toString()+" ");
                    System.out.println();

  • My computer is converting downloads from a ppt file into a pps?

    How do I stop my computer from converting downloads from a ppt file into a pps? When I download PowerPoint presentations from online for class my computer is converting the ppt files into a pps, even though I have PowerPoint. It used to download ppt files fine until recently.

    Yep, this happens. I have not found a way to keep the files from downloading as a ,pps. So I use a work around. Find where you have the downloaded file. It should look something like "slides.ppt.pps." Click on the file name to edit and erase the .pps. You'll see a dialog box that asks you if you really want to eliminate the .pps. Say yes and it will be removed from the name and you can then load into PowerPoint. Hope it works for you.
    DLS

  • Help with SQL query into Crystal

    Afternoon all,
    I am trying to convert the following SQL query into Crystal by using the tables given in the query however the relationship given in the query is bit awkward, in a sense that I cannot create a relationship under Crystal desgin.
    Here is the query
    select count(order_progressed.order_no),reason_code
    from order_progressed,lab_reasons, rework_groups
    where
    order_progressed.date_created=Today
    and (order_progressed.order_status=from_gate
    and lab_reasons.reason_code between from_reason and to_reason)
    group by lab_reasons.reason_code
    order by 2
    We have three tables
    1: Order_Progressed
    2: Lab Reasons
    3: Rework_Groups
    Order_progressed can be linked with rework_group by Status (if you see the line order_progressed.order_status=from_gate)
    However how to link the following line?
    lab_reasons.reason_code between from_reason and to_reason
    I mean when I try to link it by Lab Reasons.Reason Code to From_reason, to reason, it doesn't seem to work.
    The report is grouped by Lab Reasons. Reason Code, so I really have to some how create a relationship between Lab Reasons table and Rework_Group table.
    This is what I get when I run the same query into Crystal using the relationship
    SELECT lab_reasons.reason_code, order_progressed.date_created, order_progressed.order_no
    FROM   maxmast.lab_reasons lab_reasons, kevin.order_progressed order_progressed,
    roger.rework_groups rework_groups
    WHERE  (order_progressed.order_status=rework_groups.from_gate) AND
    ((lab_reasons.reason_code=rework_groups.from_reason) AND
    (lab_reasons.reason_code=rework_groups.to_reason)) AND (order_progressed.date_created>={ts
    '2008-01-01 00:00:00'} AND order_progressed.date_created<={ts '2008-12-17 00:00:00'})
    Any ideas?
    Many thanks
    Kind Regards
    Jehanzeb

    Sastry I didn't understand why did you use Lab_reasons.reason_code twice in your SQL.
    What I have done since I posted this thread,
    I created a command like this
    Select *
    from rework_groups,lab_reasons
    where
    lab_reasons.reason_code between from_reason and to_reason
    Then I took out the lab_reasons table and rework_groups table, then I linked the order_status from Order_progressed table to From_gate of the newly created table (I called it Reason_Code).
    This made the report running but it is crunching quite allot of numbers. I wonder if I made a mistake somewhere?
    Oh and please note, I'd like to create an SQL (if need be) without the date entry which was done in the original SQL because I'd like to setup my own date range within Crystal Reports instead of getting passed by SQL itself.
    This is how it looks like in Crystal now.
    sae1_live
    SELECT order_progressed.date_created, order_progressed.order_no, order_progressed.order_status
    FROM   kevin.order_progressed order_progressed
    WHERE  (order_progressed.date_created>={ts '2008-01-01 00:00:00'} AND
    order_progressed.date_created<={ts '2008-12-17 00:00:00'})
    EXTERNAL JOIN order_progressed.order_status={?sae1_live: Reason_Code.from_gate}
    sae1_live
    Select *
    from rework_groups, lab_reasons
    where lab_reasons.reason_code between from_reason and to_reason
    EXTERNAL JOIN Reason_Code.from_gate={?sae1_live: order_progressed.order_status}
    Regards
    Jehanzeb

  • Printing Long text in Send Mail Task

    Hi All,
    My requirement is to print the long text of particular error message in the send mail task, which will be sent to outlook.
    for this i have an activity beforr the mail task, where i have filled the multiline parameter called 'TEXT' and this is exported to workflow also.
    In my send mail task, in the body of the message, using insert expression i have inserted the multiline container 'TEXT' with the option of line break, so it came &TEXT##&.
    But once the WF is executed , i checked the WF log and found that the mail is sent and i have checked the container 'TEXT' in my previous activity where the TEXT container has 10 lines.
    But when i checked the mail in SOST the contents of TEXT is not getting printed.
    What will be the issue?
    Thanks and Regards,
    Swaminathan

    @Rick
    How is TEXT defined in the container? Is it passed in via the binding?
    I think if at all you want to use the container element in the mail then binding is not necessary from workflow to task.
    @Swaminathan PJ 
    the multiline container 'TEXT' with the option of line break, so it came &TEXT##&.
    Try to print the entire text continuosly with out line breaks then it works.

  • Send Mail Task runnig OK but doont send the mail

    Hi Experts,
    My workflow is running OK, the Send Mail task is OK without erros but in SOST there are no items.
    It was working until July 14, after this day no more entries in SOST.
    Can Anyone help-me ?

    Hello,
    Could it be a problem with the mail system? Are you sure mails haven't arrived - it could be that your search in SOST is having problems. I think there's a checkbox for "Transmitted" which is unchecked by default.
    Check in the workflow log (SWI1) whether the SendMail steps after July 14th had any errors.
    Check ST22 for any matching dumps.
    What happens if you send a mail manually from SBWP, does it work?
    regards
    Rick Bakker
    hanabi technology

  • SQL QUERY into PROCEDURE

    Hi! I am a newbie in PL/SQL..
    Can somebody teach me on how to make this SQL QUERY into a PROCEDURE?
    TABLE 1: LOGS
    TABLE 2: MASTER LIST
    Logs = records the logs
    Master list = list of all registered name.
    select * from table1
    where not exists
    select host, user, name
    from table2
    where table2.host = table1.host and
    table2.user = table1.user and
    table2.name = table1.name
    TABLE 1
    HOST | USER | NAME
    ==============
    1 | A | A1
    1 | A | A1
    1 | A | A1
    1 | A | D1
    TABLE 2
    HOST | USER | NAME
    =============
    1 | A | A1
    1 | A | B1
    1 | A | C1
    Result:
    HOST | USER | NAME
    ===============
    1 | A | D1
    Thanks. :)

    QKWS wrote:
    Hi! I am a newbie in PL/SQL..
    Can somebody teach me on how to make this SQL QUERY into a PROCEDURE?
    TABLE 1: LOGS
    TABLE 2: MASTER LIST
    Logs = records the logs
    Master list = list of all registered name.
    select * from table1
    where not exists
    select host, user, name
    from table2
    where table2.host = table1.host and
    table2.user = table1.user and
    table2.name = table1.name
    TABLE 1
    HOST | USER | NAME
    ==============
    1 | A | A1
    1 | A | A1
    1 | A | A1
    1 | A | D1
    TABLE 2
    HOST | USER | NAME
    =============
    1 | A | A1
    1 | A | B1
    1 | A | C1
    Result:
    HOST | USER | NAME
    ===============
    1 | A | D1
    Thanks. :)Hi,
    Question is not clear, really.
    Do you want that, I don't sure?
    CREATE TABLE t1 ( CHOST NUMBER,  CUSER VARCHAR2(10), CNAME VARCHAR2(10));
    INSERT INTO t1 VALUES(1,'A','A1');
    INSERT INTO t1 VALUES(1,'A','A1');
    INSERT INTO t1 VALUES(1,'A','A1');
    INSERT INTO t1 VALUES(1,'A','D1');
    Commit;
    CREATE TABLE t2 AS  SELECT *  FROM t1;
    INSERT INTO t2 VALUES(1,'A','A1');
    INSERT INTO t2 VALUES(1,'A','B1');
    INSERT INTO t2 VALUES(1,'A','C1');
    commit;
    select * from t1  table1
    WHERE NOT EXISTS
    ( SELECT 1 FROM t2 table2
       WHERE table2.chost = table1.chost
         AND table2.cuser = table1.cUSER
         AND table2.cNAME = table1.cNAME
    DECLARE
    P_HOST T1.CHOST%TYPE;
    P_USER T1.CUSER%TYPE;
    P_NAME T1.CNAME%TYPE;
    BEGIN
    select CHOST, CUSER,CNAME INTO P_HOST,P_USER, P_NAME
    from t1  table1
    WHERE NOT EXISTS
    ( SELECT 1 FROM t2 table2
       WHERE table2.chost = table1.chost
         AND table2.cuser = table1.cUSER
         AND table2.cNAME = table1.cNAME
    dbms_output.put_line('HOST | USER | NAME  : '|| TO_CHAR(P_HOST)||' | '||P_USER||' | '||P_NAME);
    END;
    /Regards
    Mahir M. Quluzade

Maybe you are looking for

  • Problem while creating metadata files

    I created metadata files to add styles to Photoshop Elements 8 (in Windows 7) and included them in the C:\Program Data\Adobe\Photoshop Elements\8.0\Photo Creations\layer styles folder.  The first several worked great and successfully showed up in the

  • Video in Photoshop CS6

    Sorry if this is the wrong place to ask but I have just started to try something using video in CS6. I have 82 sequential images and I am trying to string them together as a sort of stop motion film (think the intro to the Monkeys). I have done the f

  • ME22N Enhancements

    Hi Requirement is that when we change the 'item delivery date' in ME22N, a pop-up should be displayed saying that ' Do you want to change the statistical delivery date also'. After  clicking 'yes' the 'statistical delivery date' should be modified wi

  • Has anyone else had the problem of apps or videos supposedly taking up more room than they say they do?

    Hey, I've been having this problem for a while. Whenever I try to add a new app that's relatively large, or a new video at all, iTunes says there's not enough room on my iPod. Most recently, this happened when adding a video. Said video is 1.05 GB. i

  • Iphoto/MobileMe request to server failed

    In attempting to publish an iPhoto album (Life '09) on MobileMe after loading the thumbnails, I receive a message that it cannot publish that album "request to server failed". I have Life '09 version of iPhoto and my MobileMe account is working well