0

If my answer is in another post, I've not found it. A post I thought might have my answer was "I want to concatenate 2 strings from 2 textareas and insert them into a column in my table."

I am converting some data. Other database has text that is stored in the same table, different fields. each field (x.description_plain_text has a sequence number as illustrated in the script. As you can maybe see with my attempt, I would like to bring both of the text lines into one (varchar(8000)) field and separate with a line or two. I don't know if I am allowed to tag a second objective, but if/after I get these separate lines from the other database into one field in my new database I then want to be able to put an identifier next to each ... as I am trying to show in the 2nd illustration ...

1st illustration

--select x.description_plain_text, x.SEQ_NO
update MIC.dbo.Item  set CustomerDocumentNote = 
case 
when x.SEQ_NO = 1 then cast(x.description_plain_text as varchar(8000))
when x.SEQ_NO = 2 then cast(x.description_plain_text as varchar(8000))
END
-- x.description_plain_text + CHAR(13) + CHAR(10) + cast(x.description_plain_text as varchar     (8000))
from MIC.dbo.Item a
inner join in_item_xdesc x on x.item_id = a.itemid
where (a.ItemNumber = '14661')--(IS_PRINT_ACKNOW = 'Y' and SEQ_NO = 2)

2nd illustration ... need a SQL query that will give me just the description with P_A ... P_A is merely an identifier ... can be anything ... just a way to say If P_A then print but IF P_PT_PO THEN print ...

P_A - Heater with 1.5" OD flange at 2.5", 48" mica leads with 36" SS braid exiting 90° from sheath, single clip support. 800 Watts & 240 Volts.  For Gala pellitizer. 

+ CHAR(13) +

P_PT_PO - Stamp "MIC #14661" on OD of heater. Silicone over Cement at lead ends.
Zombo
  • 1
  • 62
  • 391
  • 407
TRow
  • 11
  • 1
  • The first part seems clear (more or less) and solvable. Cannot quite get my head around the other part of the question, however. The identifiers are added at the beginning of every fragment before the fragments are concatenated – is that correct? Where are the identifiers supposed to come from and how is each of them related to the corresponding fragment it is going to stick to? – Andriy M Feb 11 '13 at 18:27
  • I thought my second part might not be real clear. My 2nd illustration is listing an inventory item's extended description. There can be more than one extended description for an item where the data is coming from. That is why they store it as Sequence 01, 02 etc. In the other database/system, they allow each extended description to be identified to print on different documents such as a pick ticket, an acknowledgement, invoice form etc. In the new database that I am converting the data to, I would like to find a way to bring the different sequences into a single varchar(8000) note field. – TRow Feb 11 '13 at 23:16
  • ... and have each sequence clearly identified. So the first sequence would be P_A where my script would then take all of the extended description related to P_A and print on a pick ticket and an Acknowledgement form. This way they can maintain their extended descriptions in one note and the script on each form would know which extended descriptions to print. If I can get them into a single note, I then need to figure out what the script is to print one or more "groups" of extended description. – TRow Feb 11 '13 at 23:23
  • @AndriyM ... Following is an example of what I have to this point. P_A - Heater with 1.5" OD flange at 2.5", 48" mica leads with 36" SS braid exiting 90° from sheath, single clip support. 800 Watts & 240 Volts. For Gala pellitizer. P_PT_PO - Stamp "MIC #14661" on OD of heater. Silicone over Cement at lead ends. I am not sure what the scipt is to extract the text that goes with just P_A and not P_PT_PO or the other way ... this gets alll ... select CustomerDocumentNote from item where customerDocumentNote LIKE '%[P_A]%' – TRow Feb 12 '13 at 02:15
  • If I understand this correctly, you probably don't need to concatenate the values until just before printing. But you do need to supply the identifiers you are talking about: `P_A`, `P_PT_PO` etc. (as a separate column, most likely). That way, at the time of printing, you would be able to filter the rows you need to print (for that's what table have got *rows* for, so that you can easily apply filters to them), *then* concatenate them and print. The technique of concatenation of rows in SQL Server can be found in [this question](http://stackoverflow.com/questions/451415/). – Andriy M Feb 13 '13 at 06:09

0 Answers0