t-sql 2012 update statment

  • In a sql server 2012 database, I have a called that is declared as varchar(max) where the column is called stringtemplate.

    I want to update the value in the column with the value listed below, however the update statement does not work. There is a problem with the set statement. The double quotes or single quotes around the entire value does not stay.

    Thus can you tell me what I can do to make the following sql work:

    update a

    set stringtemplate = '

    <p>&CUR_DATE.EVAL</p>

    <br />

    <br />

    <br />

    <p>

    </p>

    <p>To the &PAR_NAME.EVAL of &STU_FNAME.EVAL &STU_LNAME.EVAL &PERMNUM</p>

    <span id="ADDR_BEG"></span>

    <p>&PAR_ADDR.EVAL</p>

    <span id="ADDR_NEXT"></span>&PAR_CITY.EVAL, &PAR_STATE.EVAL &PAR_ZIP.EVAL<span id="ADDR_END"></span><br />

    <br />

    <br />

    <br />

    Dear &PAR_NAME.EVAL and &STU_FNAME.EVAL &STU_LNAME.EVAL:<br />

    <br />

    <br />

    This letter is to inform you that &STU_FNAME.EVAL has the equivalent of 5 or more unexcused absences this school year. <span style="color: black; font-family: arial,sans-serif; font-size: 10pt;"><span style="font-family: arial; font-size: 14px;">We believe student attendance in school is a key component to school success, so it is very important for all children to develop habits of good attendance. Poor attendance contributes to failing grades, decreased learning opportunities, lower academic achievement and may limit your child's opportunities to be involved with school activities.</span><br />

    <br />

    </span><br />

    <p><span style="color: black; font-family: arial,sans-serif;">(Option 1)</span></p>

    <p><span style="color: black; font-family: arial,sans-serif;">Please call me at <em>PHONE NUMBER</em> to discuss these absences. During this phone conference we will address concerns and issues that may be contributing to the absences, and develop a collaborative plan to try to improve attendance. </span></p>

    <p><span style="color: black; font-family: arial,sans-serif;"> </span></p>

    <p><span style="color: black; font-family: arial,sans-serif;">(Option 2)</span></p>

    <p style="margin: 10pt 0in;"><span style="color: black; font-family: arial,sans-serif;">I have scheduled an attendance review on <em>DATE</em> at <em>TIME</em>. We will meet at <em>PLACE</em> located at <em>ADDRESS</em>. Please check in at the main office upon your arrival. During this meeting we will address concerns and issues that may be contributing to the absences, and develop a collaborative plan to try to improve attendance. The student and parent should attend this review. If you cannot attend this meeting please contact me at PHONE #. </span></p>

    <br />

    <p>

    </p>

    <p>We are notifying you so that together we can address all issues that may be contributing to these absences. Communication between the home and school is very important and we request that parents call the school each and every day that a student is going to be absent. Let us work as partners to make your child successful in school.</p>http://www.sqlservercentral.com/Forums/Skins/Classic/Images/RichTextBoxTable/tbl_bottomleft.gif

    <br />

    Sincerely,<br />

    <br />

    <br />

    &SPA_NAME.EVAL<br />

    <p>

    School Support Liaison/ Attendance Designee</p>

    <p>&SCHOOLNAME.EVAL</p>'

    from test.dbo.customer a

    where a.custid=6789

  • Your text contains a single quote that hasn't been properly escaped. You need to use two single quotes in your text to get one single quote, so child's should be child''s (that's two single quotes, not one double quote).

    There is another option, but I think it's ugly, so I'll leave it to other people to suggest it.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • See the .WRITE syntax here:

    https://msdn.microsoft.com/en-us/library/ms177523.aspx

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

  • The .write statement is used was an nvarchar(max) column. I am using a varchar(max) column. Will the write statement work with a varchar(max) column?

    Also if you have a chance, would you give me an example of how to use the .write statement?

  • wendy elizabeth (11/29/2016)


    The .write statement is used was an nvarchar(max) column. I am using a varchar(max) column. Will the write statement work with a varchar(max) column?

    Also if you have a chance, would you give me an example of how to use the .write statement?

    Did you reference the link I provided in my reply? Apparently not. I suggest you do so.

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply