SQL: HOW to concatenate two fields using trigger,

  • Joe Torre - Tuesday, June 20, 2017 9:37 AM

    You can use WinRar

    I'd rather use 7-zip, but that's not the point.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Joe Torre - Tuesday, June 20, 2017 9:37 AM

    You can use WinRar

    No, actually, I can't.   That requires installation of a product that unzips a file type I'm never ever going to be willing to download from the internet, and therefore, is a security hole a mile wide.   No thanks.   That's probably very similar to Luis' reason for telling you "that's not the point".   You're on a public forum with volunteer's helping you out.   Don't expect them to take COMPLETELY UNNECESSARY RISKS just because you do.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • Sorry for the confusion, Sgmunson, you are right I have to be a lot more specific, your query is working fine, but I want it to work with my table and update the records to my original table as seen in my screenshot, or hoe to copy the results to my original table and to update this record automatically when a new records is inserted.

    Thank you for your understanding.
    You can find my mdf here: http://www.mediafire.com/file/xdkmmb1k7nb5nmi/s1.mdf
    And the s1_log: http://www.mediafire.com/file/6o2asn1242w8isw/s1_log.ldf
    Best,
    Majdoleen

  • I'm going to presume that's a SQL Server 2016 database, but as I don't actually have a 2016 instance I can play with, I still have no means of easily consuming your information.   As downloading an entire database is asking an awful lot of a volunteer (some of us have limited internet bandwidth as well, or are at work and that level of involvement is a tad much), we really need you to post the table create statements for the tables involved.

    Also, I don't think you realize that your "desired design" is a rather bad idea.   If you construct a trigger to compute this, then what you may not realize is that such a design would REQUIRE you to insert one, and ONLY one, record at a time.  There's no functional way it will work correctly consistently if you don't.   And then you'll wonder what is going on, and start doubting SQL Server itself.   The truth is, that in order to let a query run against existing data, that data has to be a fixed set of information.   So when you go to insert multiple records that have the same value that you are aggregating the string result on, you've got a problem.   Mind you, a cursor could do the job, but trust me when I tell you that having to navigate every single record in the database one by one for every single insert to your database is a VERY BAD THING!

    You need to compute that value when you need the value.   The idea of updating on insert is just not practical, as any sizable number of records in the table will make it unmaintainable.   You're going to have to re-think what you were planning on doing.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • You still didn't post the code that you're using.
    That's a horrible design and a bad idea. It reminds me of a db horror story that you can check in here: https://www.simple-talk.com/opinion/opinion-pieces/bad-carma/

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Thank you all, I do agree with you that it is a bad idea, but unfortunitly, this is the only way which I found that may resolve my main issue which is:
    We already purchased an asset management software which called (cityworks), and all its data are stored in SQL tables, and we want to Add the Child WO IDs to the “grdWO” on the SR template, (attached)


    In my case, I have child work orders and would like to display the IDs of these child WOs on the SR template as shown in my attached. Is that available?
    unfortunately, there is no table at the level of SQL that shows the parent WO and its children on the same row.

    What is the best practical to implement this?

    Thank you in advance.

    Best,
    Majdoleen

  • Any suggestion is appreciated.

    Thank you
    Best,
    Majdoleen

  • m.awadallah92 - Monday, July 3, 2017 4:34 AM

    Any suggestion is appreciated.

    Thank you
    Best,
    Majdoleen

    I suggest that you post your data in a consumable format. 😉

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • m.awadallah92 - Monday, July 3, 2017 4:34 AM

    Any suggestion is appreciated.

    Thank you
    Best,
    Majdoleen

    To be honest, we've given you the same suggestion any number of times, but you keep refusing to post your code in a readily consumable format.   If you want an answer, you're going to have to make some level of effort.   Failing that, you'll be stuck pounding sand, 'cause that's probably what the rest of the folks normally willing to help you are likely to want to tell you to go do at this point, even if they don't actually say so...

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

Viewing 9 posts - 16 through 24 (of 24 total)

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