How do I update multiple characters at specified positions in a string while avoiding looping?

DECLARE @mytestvar NVARCHAR(MAX) = '2,3,4,5,6'
UPDATE tblMessageState
SET UserFilingCategoryStatus = STUFF(UserFilingCategoryStatus,CONVERT(INT,a.Value),1,'0')
FROM dbo.udtfSplit(@mytestvar, ',') a
WHERE MessageID = 1
This is the farthest I have gotten. This only updated the character in position 2 ...I also want it to update the character in position 3 and 4 etc... or whatever positions I input. Is there some CROSS APPLY trickery I could use ? I really want to avoid looping.
Paul Mauriello

ALTER FUNCTION dbo.fnparseAndreplaceString
@vSplitStr varchar(1000),
@vChangePosStr varchar(100)
RETURNS varchar(100)
AS
BEGIN
Declare @vMyString varchar(100) = @vSplitStr
Declare @vChangeStr varchar(100) = @vChangePosStr
Declare @vResult varchar(100) = ''
Declare @vTable Table (ID int, val nvarchar(100))
;With wcte as (
Select Row_Number()over(Order by name) ID from sys.columns
) --Insert into @vTable
Select @vResult = (Select '' + Case when b.value is Not Null then '1' else Right(SubString(@vMyString,1,ID),1) end
from wcte a
Left Outer Join dbo.fnSplit(@vChangePosStr,',') b on b.value = a.ID
where ID <= Len(@vMyString)
For XML Path(''))
--),1,1,'')
RETURN @vResult
END
GO
Create the function as above and then you can use it in your UPDATE query;
Declare @vMyString varchar(100) = '4567899243'
Declare @vChangeStr varchar(100) = '2,4,8' -- I will replace these positions with 1.
Declare @vTableTest Table (ID int, val varchar(10))
Insert into @vTableTest
Select 1, '123456789' Union All
Select 2, '456783457'
Select *, dbo.fnparseAndreplaceString (val,@vChangeStr) from @vTableTest
Update @vTableTest
Set val = dbo.fnparseAndreplaceString (val,@vChangeStr)
Select * from @vTableTest
Technically you will need two functions in your code. One is above and the other one is dbo.fnSplit. I hope you have the split function that splits the string on the basis of a given character.
Please visit my Blog for some easy and often used t-sql scripts
My BizCard

Similar Messages

  • How do you update multiple items in a JSP that are only checked...

    I have list of items in my jsp pages and that are being generated by the following code
    and I want to be able to update multiple records that have a checkbox checked:
    I have a method to update the status and employee name that uses hibernate that takes the taskID
    as a paratmeter to update associated status and comments, but my issue is how to do it with multiple records:
    private void updateTaskList(Long taskId, String status, String comments) {
    TaskList taskList = (TaskList) HibernateUtil.getSessionFactory()
                   .getCurrentSession().load(TaskList.class, personId);
    taskList.setStatus(status);
    taskList.setComment(comments);
    HibernateUtil.getSessionFactory().getCurrentSession().update(taskList);
    HibernateUtil.getSessionFactory().getCurrentSession().save(taskList);
    <table border="0" cellpadding="2" cellspacing="2" width="98%" class="border">     
         <tr align="left">
              <th></th>
              <th>Employee Name</th>
              <th>Status</th>
              <th>Comment</th>
         </tr>
         <%
              List result = (List) request.getAttribute("result");
         %>
         <%
         for (Iterator itr=searchresult.iterator(); itr.hasNext(); )
              com.dao.hibernate.TaskList taskList = (com.dao.hibernate.TaskList)itr.next();
         %>     
         <tr>
              <td> <input type="checkbox" name="taskID" value=""> </td>
              <td>
                   <%=taskList.empName()%> </td>           
              <td>          
                   <select value="Status">
                   <option value="<%=taskList.getStatus()%>"><%=taskList.getStatus()%></option>
                        <option value="New">New</option>
                        <option value="Fixed">Fixed</option>
                        <option value="Closed">Closed</option>
                   </select>          
    </td>
              <td>               
                   <input type="text" name="Comments" MAXLENGTH="20" size="20"
                   value="<%=taskList.getComments()%>"></td>
         </tr>
    <%}%>
    _________________________________________________________________

    org.hibernate.exception.GenericJDBCException: could not load an entity: [com.dao.hibernate.WorkList#2486]
    org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
    org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
    org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    org.hibernate.loader.Loader.loadEntity(Loader.java:1799)
    org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:93)
    org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:81)
    org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730)
    org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
    org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
    org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
    org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:161)
    org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
    org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:889)
    org.hibernate.impl.SessionImpl.load(SessionImpl.java:808)
    org.hibernate.impl.SessionImpl.load(SessionImpl.java:801)
    com.web.UpdateWorkListAction.execute(Unknown Source)
    org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    before I was running a single update as below and it worked fine:
    session.beginTransaction();
    int taskId = Integer.parseInt(request.getParameter("taskId"));
    String action_taken = request.getParameter("action_taken");
    WorkListErrors worklistErrors
    = (WorkListErrors) session.load(WorkListErrors.class, new Integer(taskId));
    worklistErrors.setAction_taken(action_taken);
    session.update(worklistErrors);
    session.save(worklistErrors);
    session.getTransaction().commit();
    but when I try an an update on multiple records it does work when I have a check box checked :
    session.beginTransaction();
    int taskId = Integer.parseInt(request.getParameter("taskId"));
    String action_taken = request.getParameter("action_taken");
    WorkListErrors worklistErrors
    = (WorkListErrors) session.load(WorkListErrors.class, new Integer(taskId));
    worklistErrors.setAction_taken(action_taken);
    session.update(worklistErrors);
    session.save(worklistErrors);
    session.getTransaction().commit();
    session.beginTransaction();
    String[] tickedTaskId = request.getParameterValues("tickedTaskId");
    String[] taskId = request.getParameterValues("taskId");
    String[] action_taken = request.getParameterValues("action_taken");
    for(int i=0; i<tickedTaskId.length; i++) {
    for(int j = 0; j < taskId.length; j++) {
    if(tickedTaskId.equals(taskId[j])) {
    WorkListErrors worklistErrors
    = (WorkListErrors) session.load(WorkListErrors.class, tickedTaskId[i]);
    worklistErrors.setAction_taken(action_taken[j]);
    session.update(worklistErrors);
    session.save(worklistErrors);
    session.getTransaction().commit();
    /*Close session */
    session.close();

  • How do I update multiple apple products to my gmail account address?

    I have multiple apple IDs and passwords for various products.  How do I update apple ID to my current gmail address?

    You can authorize more than one account.
    iTunes Store: Authorize or deauthorize your Mac or PC

  • How can I update multiple rows?

    Hi all,
    How can I realize an Update on multiple rows? An Update statement would look like this
    UPDATE table SET value = oldvalue + x WHERE condition_field > y;My problem is: How can I execute such a statement with BC4J? I don't linke to step through the complete result set row by row.
    Thanks,
    Axel

    Get your application module object and issue this statement:
    am.getTransaction().executeCommand(<string>);This should be what you're looking for.

  • How can I update multiple rows in table using a single form button and checkboxes

    I have a project where the visitors can select multiple productos and once the click on the PURCHAS button it updates the selected records.

    You have not mentioned the programming language that you are using, but here's a link that could help you if you are using ASP.
    http://csharpdotnetfreak.blogspot.com/2009/05/edit-multiple-records-gridview-checkbox.html
    Also, have a look at this discussion thread
    http://forums.asp.net/t/1470882.aspx

  • How can i update multiple row in a advance table

    Dear all,
    hope you are well enough.
    suppose i have a table in a OA page where there are several transactions.
    i would like to add a check box in front of every row.
    when i check the transactions(rows of OA pages) and submit then one column of a table will be updated in database.
    how can i implement that.
    Please explain
    Regards,
    Mofizur

    Hi,
    Refer below code for iteration:
    OAViewObject appVO = (OAViewObject)am.findViewObject("ApprovalsWVO1");
    OARow row = (OARow)appVO.first();
    for(int i=0;i<appVO.getRowCount();i++)
    String appStatus=appVO.getCurrentRow().getAttribute("ApprovalStatus").toString();
    if(appStatus.equalsIgnoreCase("NEW"))
    newRow.setAttribute("appTrans",Boolean.FALSE);
    else
    newRow.setAttribute("appTrans",Boolean.TRUE);
    System.out.println(appStatus);
    row = (OARow)appVO.next();
    Regards
    Meher Irk

  • How do we update multiple versions of acrobat (full) & reader?

    Dear Adobe Forum,
    We have multiple versions of adobe acrobat and reader (versions, 6, 7, 8, & 9) installed throughout our company and we are trying to find an easier way to update these multiple versions for when security or other updates are issued? Any clue? Is there a way to do all four versions via group policy? At present we have to walk around to each computer and ask the person to log-off so we can perform the update and that is just not economical from a time perspective or a customer perspective. Any help that would allow us to find a simple solution to this would be appreciated. Thanks.
    Jeff

    Post your question in the forum for Adobe Reader.

  • How do I update multiple addresses at once?

    I have a about 2 dozen entries in my address book for a particular company. Is there a way to update the address for all of the employees of that company at one time? It is very time consuming to go to each entry and type the address over and over again. The same would go for the fax number

    If you are not familiar with Applescript the simplest is probably to select them all (eg by putting the company name in the search box and selecting all found) export the selection as a vCard then delete the selection. Open the vCard in a text editor, do a global find/replace on the affected data, then import the vCard again.
    AK

  • How can I update multiple IOS devices from one computer without downloading IOS each time

    My company is on a VERY slow internet connection, and at the moment we are using a cellular modem to increase our bandwidth.  This connection is a metered connection.  The 1 Gb download for IOS 7 will kill all of my purchased bandwidth, and has a potential to both take a while and/or cost a fortune.  I need a way to update 58 iPhone 4's, 4S's and 5's to IOS 7 while only downloading IOS for each device type once.  We are using iTunes to do this update as the update utility on the phone has caused 3 of our units to crash and lose all their data.  2 of which were bricked and had to be replaced by applecare.  We had a utility for that when I worked for apple a few years ago that used iTunes in this manner, but I am not sure this exists on the consumer side.  Does anyone know where i can look for this solution?

    - Since you have iOS 4.x, the only way to update the iPod is to connect the iPod to a computer and update via iTunes. See:
    iOS 4: Updating your device to iOS 5 or later
    - If you following these instructions you can update the iPod without losing anything.  WHen you restore from backup as the article says the iPod will also be updated.
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive: Apple Support Communities

  • How do you update multiple files in P6?

    I have 4 project schedule files to update, all of them are part of the same project. Each file is one area of the project. There are relationships within each file, but there are also relationships among the files. So, if for example you update an activity and press F9, it may affect an activity that is on another file. What is the the best approach to update a project schedule like this in P6? Do you open each file, update it and then press F9? or, do you open all of the files, update and then press F9 with all the files open? Thanks.

    I have 4 project schedule files to update, all of them are part of the same project. Each file is one area of the project. There are relationships within each file, but there are also relationships among the files. So, if for example you update an activity and press F9, it may affect an activity that is on another file. What is the the best approach to update a project schedule like this in P6? Do you open each file, update it and then press F9? or, do you open all of the files, update and then press F9 with all the files open? Thanks.

  • How can i update multiple records at same time in psa

    Hi,
    i need to modify certain column's value in psa. for one of InfoObject  fix value i need to change to some other value, can i write some routine or any other way to do so quickly.
    thnx

    If you are in prod, its tough to write code to manipulate PSAs. First of all, you need to transport your Program. Also, if you make a mistake, you can potentially change other PSAs.
    If you insist, get the name of the PSA. Go to RSA1, PSA tab. THere, right click on your infosource and select Delete PSA. DON'T DELETE anything in this screen. Just copy the Table name (look around, you will find it there). Now, go to SE16 and lok at the table contennts. If you give Req, data pack, etc, you can access multiple records. Now, write the program "carefully"  to access and change records in this table.
    There is another way, but this will work-out for you.
    Uday-Ram Chamarthy

  • How can I update multiple rows based on comparison of fields table1 and 2

    I create the following SQL to test what I thought was a method to update those records where the fields below match, but what ends up happening is that the update functions works the first time, and then basically updates everything to null. I am not understanding what I am doing wrong. New at this.
    UPDATE SLS_HDR B
    SET ( B.ORD_DT, B.SHIP_ADD_CD, B.INV_ADD_CD, B.LOB, B.STATUS,
    B.ORD_TYPE, B.HDR_ROUTE, B.PRICE_LIST, B.CUST_ORDER, B.REF_A, B.REF_B,
    B.ORD_REF, B.ORD_DISC, B.SREP, B.SREP2, B.PLAN_DEL_DT, B.TXTA, B.TXTB,
    B.INV_CONTACT, B.SHIP_CONTACT, B.SOLD_CONTACT, B.PAY_CONTACT, B.ORD_AMT,B.UPDATED_DT )
    = (SELECT
    A.ORD_DT, A.SHIP_ADD_CD, A.INV_ADD_CD, A.LOB, A.STATUS,
    A.ORD_TYPE, A.HDR_ROUTE, A.PRICE_LIST, A.CUST_ORDER, A.REF_A, A.REF_B,
    A.ORD_REF, A.ORD_DISC, A.SREP, A.SREP2,A.PLAN_DEL_DT, A.TXTA, A.TXTB,
    A.INV_CONTACT, A.SHIP_CONTACT, A.SOLD_CONTACT,A.PAY_CONTACT, A.ORD_AMT, SYSDATE
    FROM
    SLS_HDR_TEMP A
    WHERE
    A.FIN_COMP = B.FIN_COMP AND
    A.LOG_COMP = B.LOG_COMP AND
    A.ORD_NO = B.ORD_NO AND
    A.TRANS_DT = B.TRANS_DT AND
    A.BP_TYPE = B.BP_TYPE AND
    A.STATUS <> B.STATUS);
    Can anyone advise?
    Thank you,
    Edited by: 903292 on Dec 19, 2011 1:15 PM

    you donot have where clause in your update so un-matched rows will be updated with null values
    UPDATE SLS_HDR B
    SET ( B.ORD_DT, B.SHIP_ADD_CD, B.INV_ADD_CD, B.LOB, B.STATUS,
    B.ORD_TYPE, B.HDR_ROUTE, B.PRICE_LIST, B.CUST_ORDER, B.REF_A, B.REF_B,
    B.ORD_REF, B.ORD_DISC, B.SREP, B.SREP2, B.PLAN_DEL_DT, B.TXTA, B.TXTB,
    B.INV_CONTACT, B.SHIP_CONTACT, B.SOLD_CONTACT, B.PAY_CONTACT, B.ORD_AMT,B.UPDATED_DT )
    = (
              SELECT
              A.ORD_DT, A.SHIP_ADD_CD, A.INV_ADD_CD, A.LOB, A.STATUS,
              A.ORD_TYPE, A.HDR_ROUTE, A.PRICE_LIST, A.CUST_ORDER, A.REF_A, A.REF_B,
              A.ORD_REF, A.ORD_DISC, A.SREP, A.SREP2,A.PLAN_DEL_DT, A.TXTA, A.TXTB,
              A.INV_CONTACT, A.SHIP_CONTACT, A.SOLD_CONTACT,A.PAY_CONTACT, A.ORD_AMT, SYSDATE
              FROM
              SLS_HDR_TEMP A
              WHERE
              A.FIN_COMP = B.FIN_COMP AND
              A.LOG_COMP = B.LOG_COMP AND
              A.ORD_NO = B.ORD_NO AND
              A.TRANS_DT = B.TRANS_DT AND
              A.BP_TYPE = B.BP_TYPE AND
              A.STATUS= B.STATUS
    WHERE EXISTS
         select null from SLS_HDR_TEMP A
         WHERE
         A.FIN_COMP = B.FIN_COMP AND
         A.LOG_COMP = B.LOG_COMP AND
         A.ORD_NO = B.ORD_NO AND
         A.TRANS_DT = B.TRANS_DT AND
         A.BP_TYPE = B.BP_TYPE AND
         A.STATUS= B.STATUS
    )OR using Merge
    Merge into SLS_HDR B
    using SLS_HDR_TEMP A
    on (A.FIN_COMP = B.FIN_COMP AND
    A.LOG_COMP = B.LOG_COMP AND
    A.ORD_NO = B.ORD_NO AND
    A.TRANS_DT = B.TRANS_DT AND
    A.BP_TYPE = B.BP_TYPE AND
    A.STATUS= B.STATUS)
    when matched then update set (B.ORD_DT, B.SHIP_ADD_CD, B.INV_ADD_CD, B.LOB, B.STATUS,
    B.ORD_TYPE, B.HDR_ROUTE, B.PRICE_LIST, B.CUST_ORDER, B.REF_A, B.REF_B,
    B.ORD_REF, B.ORD_DISC, B.SREP, B.SREP2, B.PLAN_DEL_DT, B.TXTA, B.TXTB,
    B.INV_CONTACT, B.SHIP_CONTACT, B.SOLD_CONTACT, B.PAY_CONTACT, B.ORD_AMT,B.UPDATED_DT ) = (A.ORD_DT, A.SHIP_ADD_CD, A.INV_ADD_CD, A.LOB, A.STATUS,
    A.ORD_TYPE, A.HDR_ROUTE, A.PRICE_LIST, A.CUST_ORDER, A.REF_A, A.REF_B,
    A.ORD_REF, A.ORD_DISC, A.SREP, A.SREP2,A.PLAN_DEL_DT, A.TXTA, A.TXTB,
    A.INV_CONTACT, A.SHIP_CONTACT, A.SOLD_CONTACT,A.PAY_CONTACT, A.ORD_AMT, SYSDATE)HTH...
    Thanks

  • How can I save multiple data coming in from my data string

    I am a newbie at labview. I have a scale connected to my RS 232 and made a VI to display the changing scale. I am trying to save the multiple changes as my weight varies but have been only able to save the last value. Is there a simple way to save all the values I see in my VI to a file for later plotting? I have done one before using indexing but the case this time is that I am receiving a character string and not a numeric array. Any examples or advice would be great!!! Thanks
    Gerald

    Hi Gerald,
    What you need to do is write to a file continuously, i.e. after each point you collect.  You can do so by opening a new/existing file, write to it inside your while loop, and close it once you are done collecting and writing data points, i.e. outside the loop.
    I believe the following example is a good demonstration of that operation.
    Best of luck,
    AG
    Attachments:
    write to file.vi ‏33 KB

  • Workflow - how to update multiple list items

    Is it possible to update up to 3 list items with the same information using a workflow?  My scenario is where a company vehicle (registration number) has up to three drivers assigned to it - Driver Name 1, Driver Name 2 and Driver Name 3.   I
    have two separate lists - one for vehicles (fleet list) and one for drivers (driver database).  In my workflow when an item is created or changed in the fleet list, I would like the current vehicle registration to be updated in all three driver records
    in the driver database.  I am not sure if I can do this as I am unsure of what my unique look up would be as I need to be able to tie a vehicle registration to a driver name. Any advice would be much appreciated.
    Thanks

    Hi,
    Refer to the following threads about how to update multiple list items simultaneously.
    http://social.technet.microsoft.com/Forums/en-US/936d05ba-6e86-4f44-bbdb-b3c5c12b2c68/how-do-i-update-multiple-list-items-at-once-in-a-sharepoint-list
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/2d342b01-1978-40c9-a203-303d145b331e/how-to-update-mulitple-list-items-at-same-time
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/8d5b7424-58dc-470b-8142-90755dbdeaae/sharepoint-workflow-change-multiple-items-in-other-list
    Thanks.
    Tracy Cai
    TechNet Community Support

  • Update multiple rows based on two columns in same row

    I have a 1000 rows in a table I would like to update with a unique value. This unique value is a cocatenation of two columns in teh same row.
    Each row has a (i) date and a (ii) time and a (iii) date_time column. I would like to update the date_time (iii) column with a cocatenation of the (i) date and (ii) time columns.
    I know how I would update a single row but how can I update multiple rows with a cocatenation of each of the two columns - i.e put a different value into the date_time column for each row?

    this?
    update table tab_name
    set date_time =date||time
    where your_condition

Maybe you are looking for

  • Chat history displayed correctly in Outlook, not showing in Lync 2013 client

    Morning all, It seems like I have an un-searchable issue with many hits returning that conversation history flat out doesn't work, which isn't the situation here... The backend consists of Exchange 2007 with Lync server 2013. Clients (a mix of Lync 2

  • Why doesn't tmobile work at ORD?

    Since upgrading to OS X 10.7.3, logging onto wifi networks has been much more difficult. At ORD, at least in the United Club, it is impossible using the T-Mobile network. Whenever I connect to the tmobile network, it opens the new (supposedly-quasi-a

  • Reconciliation

    I am using SBO 2004 2b. In reconciliation how to import external bank statement in sbo. in pdf file of help on reconciliation it is shown that import button is there on "Process External Bank Statement". but in the version which i am using that butto

  • FLV that won't display

    I created a DW CS5.5 file, (code is below) I embedded an FLV that won't play once the page is on the webserver, although in DW Liveview mode it plays fine. Please advise what I need to change to make this play on the server. The live page link:  www.

  • Where is the restore option in the Itunes? i have to do this to unlock my iphone, then i need to syncronise it

    where is the restore option in the Itunes? i have to do this to unlock my iphone, then i need to syncronise it. It says: Use the "restore" option within iTunes (located at the bottom of iTunes not the top) But i cant find it.