Extra line depending on input for mailing in Word - ms-word

I have an Excel sheet with company names, contacts, address,... used for a mailing document in
Word. Ideally the address at the top should be:
{MERGEFIELD «company»}
to {MERGEFIELD «contact»}
{MERGEFIELD «street»}
{MERGEFIELD «city»}
But it's possible that there's no "contact" person known up there and then the address should be:
{MERGEFIELD «company»}
{MERGEFIELD «street»}
{MERGEFIELD «city»}
I wanted to use the "if" statement where it would be something like:
if ( {MERGEFIELD «contact»} <> "")
{MERGEFIELD «company»} + "\b" + "to "+ {MERGEFIELD «contact»}
else
{MERGEFIELD «company»}
But I can't get it working, I don't understand how Word splits the if-statement.
this works:
{ IF {MERGEFIELD «company»} <> "" {MERGEFIELD «contact»} {MERGEFIELD «company» }}
but if I add "to" it's not working anymore (and I don't know the newline tag neither)
Thanks for your time.

That's as simple as:
{MERGEFIELD «company»}{MERGEFIELD «contact» \b "¶
to "}
{MERGEFIELD «street»}
{MERGEFIELD «city»}
where the ¶ is a real paragraph break or line break.

Related

CASE expression in WHERE clause Postgresql

I have been struggling to figure out how to put a CASE expression in the WHERE clause using PostgreSQL. I need to convert the string to a date (as seen in line 3). This works fine. When I try to pull CURRENT_DATE in the WHERE clause I run into errors. Is this the best way to do this? Any suggestions would be very much welcomed.
SELECT
CASE WHEN
multi_app_documentation.nsma1_code = 'DATE' THEN TO_DATE(multi_app_documentation.nsma1_ans, 'MMDDYYYY') END AS "Procedure Date",
' ' AS "Case Confirmation Number",
ip_visit_1.ipv1_firstname AS "Patient First",
ip_visit_1.ipv1_lastname AS "Patient Last",
visit.visit_sex AS "Patient Gender",
TO_CHAR(visit.visit_date_of_birth, 'MM/DD/YYYY') AS "DOB",
visit.visit_id AS "Account Number",
visit.visit_mr_num AS "MRN",
' ' AS "Module",
' ' AS "Signed off DT",
CASE WHEN
multi_app_documentation.nsma1_code = 'CRNA' THEN multi_app_documentation.nsma1_ans END AS "Primary CRNA",
' ' AS "Secondary CRNA",
' ' AS "Primary Anesthesiologist",
' ' AS "Secondary Anesthesiologist",
' ' AS "Canceled Yes/No"
FROM
multi_app_documentation
INNER JOIN ip_visit_1 ON multi_app_documentation.nsma1_patnum = ip_visit_1.ipv1_num
INNER JOIN visit ON ip_visit_1.ipv1_num = visit.visit_id
WHERE
CASE
WHEN ( multi_app_documentation.nsma1_code = 'DATE' AND TO_DATE( multi_app_documentation.nsma1_ans, 'MMDDYYYY' ) = CURRENT_DATE END )
AND multi_app_documentation.nsma1_ans IS NOT NULL
ORDER BY
ip_visit_1.ipv1_lastname ASC
Your parentheses are unbalanced. Also, you don't even need a CASE expression in the WHERE clause. Use this version:
WHERE
multi_app_documentation.nsma1_code = 'DATE' AND
TO_DATE(multi_app_documentation.nsma1_ans, 'MMDDYYYY') = CURRENT_DATE
In addition, it is undesirable to store text dates in the nsma1_ans column. It would be better to use a bona-fide date column. If you must store the dates as text, then at least use the format YYYY-MM-DD, which then could simply be cast to date using nsma1_ans::date.

Change font and size in database field

I'm trying to mailmerge from word referencing to excel as database. However, I'm not exactly sure how I can change the font and the size of the field. e.g. I would like to change the font of [Person First Name] to font Arial with size 8. Kindly advice.
{DATABASE \d "{FILENAME \p}/../personnel.xlsx" \s " SELECT [Person First Name], [Person Last Name], [ID], [Title] FROM [Sheet1$] WHERE [ID] = {MERGEFIELD ID} ORDER BY [Title] " \l "15" \b "49" \h}

Suppressing text and mail merge fields in Word based on another mail merge field

Our Student Information System (SIS) uses Word's mail merge functionality to create custom documents. I'm attempting to recreate a state-supplied form, and need some help.
In the document I've got six "sources": for each one there's a checkbox, a static text description, and a description field. I want to display the six as separate rows, but if the checkbox for that row is unchecked I don't want that row to display at all; I also don't want the checkbox to actually display here (it'll be displayed in a different place). The effect I'm looking for is a table where each row's visibility is controlled by the checkbox, and empty rows collapse.
When I create the document, the SIS creates a starter document with all of the fields referenced. After a little massaging, here's what I have:
{ MERGEFIELD TableStart:REV_DATA_ROOT/StudentDocument \*MERGEFORMAT}
{ MERGEFIELD #CogS1??TYPE=CHECKBOX} Source 1 { MERGEFIELD #CogS1Desc}
{ MERGEFIELD #CogS2??TYPE=CHECKBOX} Source 2 { MERGEFIELD #CogS2Desc}
{ MERGEFIELD #CogS3??TYPE=CHECKBOX} Source 3 { MERGEFIELD #CogS3Desc}
{ MERGEFIELD #CogS4??TYPE=CHECKBOX} Source 4 { MERGEFIELD #CogS4Desc}
{ MERGEFIELD #CogS5??TYPE=CHECKBOX} Source 5 { MERGEFIELD #CogS5Desc}
{ MERGEFIELD #CogS6??TYPE=CHECKBOX} Source 6 { MERGEFIELD #CogS6Desc}
{ MERGEFIELD TableEnd:REV_DATA_ROOT/StudentDocument \*MERGEFORMAT}
So if only the checkboxes for Source 1 and Source 5 were checked, only those two lines would display:
Source 1 Et ultrices neque ornare aenean euismod elementum nisi quis.
Source 5 Ultricies tristique nulla aliquet enim tortor at auctor urna.
(if the description wraps to the next line I'll play with the tabs and the hanging indent to mimic an actual table)
What I specifically want to avoid is having a blank line where unchecked checkboxes are. Is this possible?
Edit: When I print #CogS1, etc., by itself without setting the type to checkbox, it prints either True or False, so it should be possible to use this in an IF statement, but I'm not getting it to work. Also, in the original code above I had typed a single question mark just before "TYPE=CHECKBOX"; it's actually two question marks, and the code has been updated to reflect this.
To solve my problem I needed to use IF merge fields with a carriage return embedded in the "True" results; I also needed to have no carriage returns between the six IF merge fields. Based on the example I gave originally, here's what I ended up doing:
{IF {MERGEFIELD #CogS1} = "true" "Source 1: {MERGEFIELD #CogS1Desc}
"}{IF {MERGEFIELD #CogS2} = "true" "Source 2: {MERGEFIELD #CogS2Desc}
" ""}{IF {MERGEFIELD #CogS3} = "true" "Source 3: {MERGEFIELD #CogS3Desc}
" ""}{IF {MERGEFIELD #CogS4} = "true" "Source 4: {MERGEFIELD #CogS4Desc}
" ""}{IF {MERGEFIELD #CogS5} = "true" "Source 5: {MERGEFIELD #CogS5Desc}
" ""}{IF {MERGEFIELD #CogS6} = "true" "Source 6: {MERGEFIELD #CogS6Desc}
" ""}

Postgres make spaces with ''::text statement

Does anyone know why Postgresql 9.3.17 do this with concat() function ?
If I do :
SELECT concat(tab.a::text, ' '::text, tab.b::text) AS field FROM schem.tab
I'll have "a b" with 3 spaces (one in the ' ' and two added by Postgres)
If I do:
SELECT concat(concat(tab.a::text, ' '::text), tab.b::text) AS field FROM schem.tab
I'll have "a b" with my only space

Using a field from tablestart in another tablestart MS Word merge

I am setting up a mail merge document with an object data source that has an object containing this structure:
id, firstName, lastName, address, donationText, donations
donations is an object itself with the following attributes:
donationType, donationAmount, donationDate
The mail merge document uses the mergefield TableStart and TableEnd to control the object data to use. For example, to use the firstName and lastName fields you have to use TableStart like this.
{MERGEFIELD TableStart:person}
{MERGEFIELD firstName} {MERGEFIELD lastName}
{MEREFIELD TableEnd:person}
Since donations is an object, you have to use it using TableStart/TableEnd to access those fields.
{MERGEFIELD TableStart:person}
{MERGEFIELD firstName} {MERGEFIELD lastName}
{MERGEFIELD TableStart:donation}
{MERGEFIELD donationType}
{MERGEFIELD TableEnd:donation}
{MERGEFIELD TableEnd:person}
You cannot use fields from person inside the TableStart/TableEnd for donation or vice-versa. What I need to do is to be able to check the donationType and if it is CHK or ECHECK then insert the donationText. I figured out you can use an IF statement like this:
{MERGEFIELD TableStart:person}
{MERGEFIELD firstName} {MERGEFIELD lastName}
{IF "{MERGEFIELD TableStart:donation}{MERGEFIELD donationType}{MERGEFIELD TableEnd:donation}" = "CHK" "{MERGEFIELD donationText}" ""}
{IF "{MERGEFIELD TableStart:donation}{MERGEFIELD donationType}{MERGEFIELD TableEnd:donation}" = "ECHECK" "{MERGEFIELD donationText}" ""}
{MERGEFIELD TableEnd:person}
I can get this statement to work if each IF statement is in a separate line. I need them to be in the same line to prevent blank lines from appearing. I also tried embedding one IF statement in the other but then neither of the IF statements work.
I am using MS Word 2010.
I figured out a solution. In order to embed one IF statement in the other, you have to add a newline before the embedded IF statement.
{MERGEFIELD TableStart:person}
{MERGEFIELD firstName} {MERGEFIELD lastName}
{IF "{MERGEFIELD TableStart:donation}{MERGEFIELD donationType}{MERGEFIELD TableEnd:donation}" = "CHK" "{MERGEFIELD donationText}" {
IF "{MERGEFIELD TableStart:donation}{MERGEFIELD donationType} {MERGEFIELD TableEnd:donation}" = "ECHECK" "{MERGEFIELD donationText}" ""}}
{MERGEFIELD TableEnd:person}
Adding the newline allows TableStart to work, otherwise you get an error since two TableStart tags cannot be in the same line.