Can I preserve carriage returns in a string variable from SQL Server?

I have an OLE data source that pulls data from sql server via a SELECT query.  One of the fields is an NVARCHAR(max) which goes into a string variable which is later used in an expression.  I am noticing that in the expression, carriage returns
/ line breaks in this field are being lost.  Does anyone know how I can preserve these in the expression?

Thanks everyone for the suggestions.  I am certain there are both \r and \n in the database as when I print the field and then copy/paste to textedit to show the hidden characters, I can see both the CR and LF's.  
I have implemented a workaround that is by no means elegant, but it gets the job done.
I found that \r and \n will evaluate in an expression but if they are part of another string variable, SSIS escapes them. My workaround was to change my OLE_DB select statement (which fetches the custom SQL query) to explicitly change the hidden characters
to '\r' and '\n' respectively:
SELECT REPLACE(REPLACE([CUSTOM_SQL],char(13),'\r'),char(10),'\n')
Then, in my SSIS expression, I de-escaped these characters:
REPLACE(REPLACE(@[User::vAlertCustomSQL],"\\r","\r"),"\\n","\n")
Now when the expression is executed, the SQL is formatted correctly and oddly placed comments in the query no longer break the query.  

Similar Messages

  • Need to return CLOB as String type from SQL query

    I have a table that contains a CLOB column, which should be accessible to a JDBC client (JReports) that does not understand how to extract CLOB from a result set.
    A possible workaround would be to translate the CLOB type into a normal string on the database side as part of the SQL query (or a view), so that the client can handle it. For that to work, we would need a type conversion within the query itself.
    Rather then
    SELECT clob_column FROM my_table
    we would need something like
    SELECT to_char(clob_column) FROM my table
    Unfortunately to_char does not work, but possibly there are other ways to achieve it.
    null

    Hi Christo
    Works fine. Just had to change the parameter order:
    DBMS_LOB.substr(clob_column,4000,1) converts the CLOB to a VARCHAR
    Thanks a lot,
    Thomas
    null

  • Blank values returned from SQL Server Convert to Query Template

    I am attempting to migrate Query Templates from Oracle to SQL Server. In the Oracle version I am using TO_CHAR to convert a date to a particular string format. To return the same string format in SQL Server I have to use CONVERT. The TO_CHAR returns a value which is displayed by the Query Template Test function. However, in the case of the CONVERT a blank is returned even though it works perfectly well when I run the same query in SQL Server Management Studio. Can anyone tell me why is this happening or suggest a fix? Thanks. John.

    John,
    Glad that did the trick.
    Native client tools like SQLPlus, Toad, Query Analyzer, etc. will often not care about column names, sometimes labelling the column as the full messy expression and sometimes calling it Expr1, but when doing aggregate expression or conversion type columns in an MII query you should adopt the habit of aliasing the columns in the query. 
    What a better way to control the situation than to dictate it in your request
    Regards,
    Jeremy

  • Looking for a better way to determine string variable from multiple options

    Hi,
    I trying to figure out a better way to determine a string variable from multiple options.
    Say i have five pictures each with a different filename: img1 - img5...these file names could be named anything really but for this example i will keep them as img1, img2, img3, img4 and img5.
    I want to display a messagebox with the string depending on what a certain variable is.
    So for example, we have the number X, if X = 1 then i want the messagebox to show "img1" as the message
    Essentially the way I have been doing it so far is:
    Private Sub WhichImage()
    Dim ImageName As String = ""
    Dim i as integer
    If i = 0 Then
    ImageName = "img1"
    End If
    If i = 1 Then
    ImageName = "img2"
    End If
    If i = 2 Then
    ImageName = "img3"
    End If
    If i = 3 Then
    ImageName = "img4"
    End If
    If i = 4 Then
    ImageName = "img5"
    End If
    MessageBox.show(imagename, "Name of image", MsgBox.Style.OkOnly, MsgBoxResult.Ok)
    end
    Up until now, this has been fine, but what if I have 50 images, do I have to do this for all 50 images? or is there an easier way like putting the image names into a text file and have it read from the file depending on what the variable i equals? If so,
    how do I go about this? Does each image name go on a separate line? can it just be separated by a comma instead? or is there a better way?
    Please note that i know that i have declared "i" above in my code and not intialised it with anything, in reality "i" comes from somewhere else in the program so please ignore that part, it is not what I am concerned with.
    Thanks
    Mersec

    Does each image name go on a separate line? can it just be separated by a comma instead? or is there a better way?
    Arrays are useful for this.
    Dim imagenames() As String = {"img1", "img2", "img3", "img4", "img5"}
    Dim imagename As String = imagenames(i)
    MessageBox.Show(imagename, "Name of image")
    Any sort of collection will do instead of an array, and may be simpler to manage. There are many other options - the most suitable one probably depends on where the names originally come from.  For instance, if you are getting them from a folder
    using the FileSystem.GetFiles method, then they are already in a collection.
    If the files names never change then you may as well include them in the program code, using something like the code above.  If they can change, then you could use a text file, but that means you need a file update routine.  If that is required
    then the way you store the names will dictate how you access them.

  • I want to query oracle database from sql server can anyone tell steps 2 fo

    i want to query oracle database from sql server can anyone tell steps 2 followed
    i tried with linked servers but it is throwing errors can anyone hepl in this regard
    The operation could not be performed because the OLE DB provider 'MSDAORA' was unable to begin a distributed transaction.
    OLE DB error trace [OLE/DB Provider 'MSDAORA' ITransactionJoin::JoinTransaction returned 0x8004d01b].

    First of all - you are in the wrong forum.
    Look either for the Database general or search for Transparant / Heterogenous Gateways.
    cu
    Andreas

  • I want to query oracle database from sql server can anyone tell steps 2 fol

    i want to query oracle database from sql server can anyone tell steps 2 followed
    i tried with linked servers but it is throwing errors can anyone hepl in this regard
    The operation could not be performed because the OLE DB provider 'MSDAORA' was unable to begin a distributed transaction.
    OLE DB error trace [OLE/DB Provider 'MSDAORA' ITransactionJoin::JoinTransaction returned 0x8004d01b].

    First of all - you are in the wrong forum.
    Look either for the Database general or search for Transparant / Heterogenous Gateways.
    cu
    Andreas

  • Msg 0, Sev 0, State 1: Unknown token received from SQL Server [SQLSTATE HY000] String data, right truncation [SQLSTATE 01004] [SQLSTATE 08S01] error

    I'm looking for some general guidance on this complete error:
    Msg 0, Sev 0, State 1: Unknown token received from SQL Server [SQLSTATE HY000]
    String data, right truncation [SQLSTATE 01004]
    Msg 16389, Sev 16, State 1: The connection is no longer usable because the server response for a previously executed statement was incorrectly formatted. [SQLSTATE 08S01]
    This error is caused by a SQL Agent Job, but it does not always occur. I understand this could be an issue with SQL dropping the connection, but what is the best way to troubleshoot this?
    Thanks,
    Phil

    Hi philliptackett77,
    It would be more helpful for troubleshooting the issue if you post the SQL Server error log and SQL Server version. Additionally, please state what purpose of using the agent job.
    Based on my research, [SQLSTATE 08S01] error means communication link failure. If the executed statement returns invalid value in the job, the connection between server and client will fail. This error could be caused by the error of [SQLSTATE HY000] and
    [SQLSTATE 01004]. I’d like to share my knowledge about these errors as below.
    Quote: String data, right truncation [SQLSTATE 01004]
    This error could occur when passing data whose length is larger than the received object,and the passed value is truncated, and returns invalid value. So please check if the data type of the objects are identical and the length of passed value is not larger
    than the received object.
    Quote: Msg 0, Sev 0, State 1: Unknown token received from SQL Server [SQLSTATE HY000]
    The error could occur in the two cases below.
    1. If you use SQL Server version 6.50, and execute the cursor in the job step, set the statement options to use a server-side cursor and prepare a select statement on a SQL Server system table. The first execution of the select creates the cursor successfully.
    After you close this cursor, if you execute the prepared statement again, the error could occur.
    I recommend you to apply the latest service pack firstly. If the error still occurs, you could change your code by using a forward-only cursor instead of a static, keyset, or dynamic cursor on the system tables. If a forward-only cursor is unacceptable,
    prepare the select statement again on the system table and execute it to create a server-side cursor. For more information about the process, please refer to the article:
    http://support.microsoft.com/kb/151693/en-us
    2. The TDS stream from the server is invalid when transfer data between a database server and a client. This error is typically caused by a problem on the server. For more information about errors above, please refer to the article:
    http://technet.microsoft.com/en-us/library/aa937531(v=sql.80).aspx
    Regards,
    Michelle Li

  • How can I migrate data from SQL Server 6,5 to Oracle 8?

    We have a web site based on Microsoft SQL Server 6.5.Now we plan
    to migrate the database to Oracle 8.
    We have redesigned the tables structure and created tables under
    Oracle 8, so we only need to migrate data from SQL Server.
    We've exported data from SQL Server to text files.
    How can we import data from files and restore to Oracle tables.
    Is there a solution which let us to import data for particular
    table columns,not all columns?
    We'll be appreciated if somene can give suggestions.
    Regards
    Michael
    null

    Thank you for your reply.
    I'll try the Oracle sqlloader utility first.
    Regards
    Micahel
    Oracle Migration Workbench Team wrote:
    : Michael,
    : Oracle sqlloader is user for this sort of operation, see
    : Oracle8i Utilities
    : Release 8.1.5
    : A67792-01
    : available online through Oracle Technology Network.
    : The Oracle Migration Workbench can be used to create bcp and
    : sqlloader scripts, though since you have altered the schema
    these
    : scripts would need to be altered by hand after generation.
    : Some thought has been put into redesigning table structures in
    : the Oracle Migration Workbench, but currently it looks like
    this
    : reengineering will be left to be done by other tools, eg
    Oracle
    : Designer, once the SQLServer database has been duplicated with
    as
    : little change as possible onto Oracle.
    : Hope that helps,
    : Turloch
    : Oracle Migration Workbench Team
    : Michael (guest) wrote:
    : : We have a web site based on Microsoft SQL Server 6.5.Now we
    : plan
    : : to migrate the database to Oracle 8.
    : : We have redesigned the tables structure and created tables
    : under
    : : Oracle 8, so we only need to migrate data from SQL Server.
    : : We've exported data from SQL Server to text files.
    : : How can we import data from files and restore to Oracle
    tables.
    : : Is there a solution which let us to import data for
    particular
    : : table columns,not all columns?
    : : We'll be appreciated if somene can give suggestions.
    : : Regards
    : : Michael
    : Oracle Technology Network
    : http://technet.oracle.com
    null

  • Can you replicate databases from SQL Server 2014 Enterprise Edition to SQL Server 2014 Standard edition?

    Hello,
    Can you replicate databases from SQL Server 2014 Enterprise Edition to SQL Server 2014 Standard edition? 
    Thanks. 

    Yes, you can replicate from Enterprise edition to Standard edition.  The only caveat is Peer-to-Peer Replication requires all nodes to be Enterprise Edition.
    Brandon Williams (blog |
    linkedin)

  • How to put a carriage return in a String

    I am creating an error message on my class which is called and displayed on my JSP page.
    In my string I want it to do a Carriage return. I used a \n however it just ignores it when displayed in JSP using scriplets.
    Class declaration:
    -- Want this line to start on the next line..
    /** Used for the Error message for a text box. */
    private final String TEXTBOX_ERROR_MSG = "\n NOTE: The text box characters left count may not be accurate.";
    Used in getDBErrors() method:
    --errors is an array of error records displayed in the JSP
    if(this.notes != null && this.notes.length() > 4000)
         errors.add("Notes Tab: Notes section cannot be greater than 4000 characters." +  this.TEXTBOX_ERROR_MSG);
    JSP Page code:
    --Get the list of Errors from the class
    List pbrDBErrors = editBean.getDBErrors();     
    -- Display errors:
    for(int l=0; l<pbrDBErrors.size(); l++)
    %>
    <li>
        ----------- Display ERROR Message Here
        <%= (String)pbrDBErrors.get(l) %>
    </li>
    <%
    } %>++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    All the code works great - Its just the TEXTBOX_ERROR_MSG is displayed on the same line as the rest of the message and it scrolls off the page.
    How do it get it to do a cariage return?? \n does not seem to work.
    Thanks

    I learned something new today.. I guess I can go home :)
    I am creating an error message on my class which is
    called and displayed on my JSP page.
    In my string I want it to do a Carriage return. I
    used a \n however it just ignores it when displayed
    in JSP using scriplets.
    Class declaration:
    -- Want this line to start on the next line..
    /** Used for the Error message for a text box.
    private final String TEXTBOX_ERROR_MSG = "\n NOTE:
    The text box characters left count may not be
    accurate.";
    Used in getDBErrors() method:
    --errors is an array of error records displayed in
    the JSP
    if(this.notes != null && this.notes.length() >
    4000)
    errors.add("Notes Tab: Notes section cannot be
    ot be greater than 4000 characters." +
    this.TEXTBOX_ERROR_MSG);
    JSP Page code:
    --Get the list of Errors from the class
    List pbrDBErrors = editBean.getDBErrors();     
    -- Display errors:
    for(int l=0; l<pbrDBErrors.size(); l++)
    %>
    <li>
    ----------- Display ERROR Message Here
    <%= (String)pbrDBErrors.get(l) %>
    </li>
    <%
    } %>++++++++++++++++++++++++++++++++++++++++++++++++++++++
    ++
    All the code works great - Its just the
    TEXTBOX_ERROR_MSG is displayed on the same line as
    the rest of the message and it scrolls off the page.
    How do it get it to do a cariage return?? \n does not
    seem to work.
    ThanksThanks the <br> worked great....

  • Interactive Report: how can I display carriage returns?

    Hello everybody.
    Here is my problem: I created a table containing a field COMMENT varchar2(4000) and using APEX 4.1 I built an interactive report on it.
    Users can fill the field COMMENT with sentences on different rows, ex:
    " this is the first line
    this is the second line
    this is the third line"
    This is correctly managed in the FORM, where I defined the field COMMENT as 'Text Area', but in the REPORT I wasn't able to set it in a way which permits to see it whit the carriage returns: the content is displayed on one row only : "this is the first linethis is the second linethis is the third line".
    I tried and set all the possible field types, but I found no ways to display the content exactly as it is (with carriage returns).
    Obviously I cannot use HTML
    , since I cannot ask users to digit it when inserting their text.
    Could someone suggest me how to reach this result? In need to use the interactive report because the searching/filtering tool is fundamental.
    Thanks in advance,
    Daniele

    >
    Please update your forum profile with a real handle instead of "user9211286".
    Here is my problem: I created a table containing a field COMMENT varchar2(4000) and using APEX 4.1 I built an interactive report on it.
    Users can fill the field COMMENT with sentences on different rows, ex:
    " this is the first line
    this is the second line
    this is the third line"
    This is correctly managed in the FORM, where I defined the field COMMENT as 'Text Area', but in the REPORT I wasn't able to set it in a way which permits to see it whit the carriage returns: the content is displayed on one row only : "this is the first linethis is the second linethis is the third line".
    I tried and set all the possible field types, but I found no ways to display the content exactly as it is (with carriage returns).
    Obviously I cannot use HTML
    , since I cannot ask users to digit it when inserting their text.
    Could someone suggest me how to reach this result? In need to use the interactive report because the searching/filtering tool is fundamental.Use a CSS style sheet with attribute selectors. Put this in the page HTML Header, replacing the <tt>T_EMP_NAME</tt> etc selectors with the actual <tt>id</tt> attributes of your column headers:
    <style type="text/css">
    .apexir_WORKSHEET_DATA td[headers="T_EMP_NAME"] {
      white-space: pre;
    </style>
    Interactive Report Control Break disregards HTML Header style.

  • How do you insert a carriage return into a string ?

    Hi,
    I don't know how to insert a carriage return, \n ,into a string
    without the carriage return being interpeted. I am trying to build
    a string called queryVariable from the file below so that it equates
    to the necessary format for JDBC to execute the query.
    SQL script file:
    declare @x datetime
    select @x = null
    exec OSVBAK01...demand_dump PRODUCT,FULL,@x
    go     
    required string format for query:
    "declare @x datetime\n"+"select @x = null\n"+
    "exec OSVBAK01...demand_dump PRODUCT,FULL,@x";     
    void Readfile(String path, String infilename) {
    try {
    File file = new File(path + infilename);
         if (!file.exists()) {
         System.err.println("File not found");
         BufferedReader in = new BufferedReader
    (new FileReader(file));
         String str;
         String queryVariable = "";
         StringBuffer sb = new StringBuffer();
         while ((str = in.readLine()) != null) {
         sb.append("\"").append(str).append("\n\"")
    .append("+");                              
         in.close();
         queryVariable = sb.toString();
         System.out.println(queryVariable);
    } catch (IOException e) {
         System.err.println(e.getCause());
    queryVariable equates to the following after running the code above:
    "declare @x datetime
    "+"select @x = null
    "+"exec OSVBAK01...demand_dump PRODUCT,FULL,@x
    "+"go     
    "+
    Any assistance anyone could provide would be greatly appreciated.
    Thanks for your time,
    YAM-SSM

    Interesting... that would mean, of course, that in the case of concatenating string literals (outside of loops, as they say), the compiler is optimizing the code to avoid the need for using StringBuffers internally. Actually, it's good to know this, as I wasn't aware of this optimization.
    However, the post wasn't meant to be serious... I hoped that was obvious. Everyone's spouting off nearly the same thing for adding strings and line separators and whatever.

  • LiveCycle DS , can't get the return value of fill( arg) from Assembler class

    Hi all!
    I'm a have small problem , can any one help me? Please
    I make a project which very similar to Product project(in
    example).
    1) Have Assembler class: I work correctly
    package flex.samples.stock;
    import java.util.List;
    import java.util.Collection;
    import java.util.Map;
    import flex.data.DataSyncException;
    import flex.data.assemblers.AbstractAssembler;
    public class StockAssembler extends AbstractAssembler {
    public Collection fill(List fillArgs) {
    StockService service = new StockService();
    System.out.print(fillArgs.size());
    return service.getStocks();
    public Object getItem(Map identity) {
    StockService service = new StockService();
    return service.getStock(((Integer)
    identity.get("StockId")).intValue());
    public void createItem(Object item) {
    StockService service = new StockService();
    service.create((Stock) item);
    public void updateItem(Object newVersion, Object
    prevVersion, List changes) {
    StockService service = new StockService();
    boolean success = service.update((Stock) newVersion);
    if (!success) {
    int stockId = ((Stock) newVersion).getStockId();
    throw new DataSyncException(service.getStock(stockId),
    changes);
    public void deleteItem(Object item) {
    StockService service = new StockService();
    boolean success = service.delete((Stock) item);
    if (!success) {
    int stockId = ((Stock) item).getStockId();
    throw new DataSyncException(service.getStock(stockId),
    null);
    some require class is ok.
    2) I configure in data-management-config.xml
    <destination id="stockinventory">
    <adapter ref="java-dao" />
    <properties>
    <source>flex.samples.stock.StockAssembler</source>
    <scope>application</scope>
    <metadata>
    <identity property="StockId"/>
    </metadata>
    <network>
    <session-timeout>20</session-timeout>
    <paging enabled="false" pageSize="10" />
    <throttle-inbound policy="ERROR" max-frequency="500"/>
    <throttle-outbound policy="REPLACE"
    max-frequency="500"/>
    </network>
    </properties>
    </destination>
    3) My client app:
    I use :
    <mx:ArrayCollection id="stocks"/>
    <mx:DataService id="ds" destination="stockinventory"/>
    ds.fill(stocks); --> Problem here
    When I run this app, The StockAssembler on the server work
    correctly (i use printout to debug) . But variable stocks can't get
    the return value,it is a empty list.
    Please help me!

    Hi,                                                             
    The executeQueryAsync method is “asynchronous, which means that the code will continue to be executed without waiting for the server to
    respond”.
    From the error message “The collection has not been initialized”, which suggests that the object in use hadn’t been initialized after the execution of the executeQueryAsync method.
    I suggest you debug the code in browser to see which line of code will throw this error, then you can reorganize the logic of the code to avoid using the uninitialized object.
    A documentation from MSDN about Using the F12 Developer Tools to Debug JavaScript Errors
    for your reference:
    http://msdn.microsoft.com/en-us/library/ie/gg699336(v=vs.85).aspx
    Best regards
    Patrick Liang
    TechNet Community Support

  • Can Mail preserves the mail which had been deleted on the server?

    The space in my mail server is limited, so I must delete some mails from the server. But I want to presenve them in the Mail client. How can I do? I cannot find any configuration can do this.

    Have no idea what you mean. IMAP or Exchange accounts are server based and messages are always on the server until completely deleted from the trash. Your provider might have an archive feature to preserve emails outside of the main mailboxes on the server, but there are no other settings to delete messages from the server and keep them in the main mailboxes on the computer. Only other option is to move them to local mailboxes.
    When you look at IMAP mailboxes, you are only looking at images of what is on the server. When you move or delete a message from a mailbox, the computer sends a message to the server and makes the changes. The changes get relayed back to the computer and you see the change.
    You have an option to keep them local for offline viewing, but they will be deleted when deleted from all imap mailboxes.

  • How can I get the data array from SQL Server Database?

    Hi,
    I can write a data array(2D)into a table of my SQL Server Database. The data array was writen to a column with image type. I know a data array is transformed a binary string when writing into database, but I dont know how to get the data array when I fetch the binary string from database.
    My question is:
    How to transform the binary string into data array? which vi's should I use? I have tried unflatten from string but failed.
    Any response is appriciated.
    Red

    happyxh0518 wrote:
    > I can write a data array(2D)into a table of my SQL Server Database.
    > The data array was writen to a column with image type. I know a data
    > array is transformed a binary string when writing into database, but I
    > dont know how to get the data array when I fetch the binary string
    > from database.
    >
    > My question is:
    > How to transform the binary string into data array? which vi's should
    > I use? I have tried unflatten from string but failed.
    In order to use Unflatten from string you first need to Flatten it
    before writing it. Also depending on the database driver, the returned
    data may actually not be binary but Hexadecimal encoded ASCII which you
    would first have to decode to binray.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

Maybe you are looking for