Capturing Campaign through Ampscript in email giving duplicate records - salesforce-marketing-cloud

Our requirement is to capture campaign information during send time through Ampscript. ask is to capture data extension name, jobid and publication list for every campaign(unique DE-Jobid pair). I am able to populate DE with details, however we see duplicate records with same DE-Jobid pair. find the snippet below
SET #Job_Id = jobid
SET #DE = _DataSourceName
SET #Publication_List = AttributeValue("_listname")
SET #Campaign_Name = emailName_
set #date = NOW()
set #campaign_found = LookupRows("Campaign_Details_CDT","Job_ID", #Job_Id,"Segment_Name", #DE)
set #rowcount = rowcount(#campaign_found)
IF(#rowcount == 0) THEN
InsertDE("Campaign_Details_CDT", "Job_ID", #Job_Id, "Campaign_Name", #Campaign_Name, "Segment_Name", #DE, "Sent_Date", #date, "Publication_List", #Publication_List)
ENDIF
]%%````
I will appreciate your help to find reason for this.

Related

SSRS email to only user with browser rights

Is there a way for to trigger sending the emails on demand by a user who only has Browser rights? Is there something within SSRS to control that feature.
This answer is a lot of guessing as you don't provide much info. If this answer is not helpful, please edit your question and describe your current workflow and where SSRS currently sits in that workflow.
If you are using a report as part of your workflow, in this hypothetical situation:
User submits and invoice somehow
Invoice gets printed via SSRS report and at this point is deemed 'processed'
Invoice "submitted by" user gets an email says their invoice has been processed
Now lets a assume you have a simple Invoice header table something like
InvoiceID Amount SubmittedBy Processed ProcessedBy
12345 456.78 dave#company.org NULL NULL
Assuming the Report to generate in the invoice has a dataset something like
SELECT * FROM InvoiceHeader h
JOIN InvoiceDetail d on h.InvoiceID = d.InvoiceID
WHERE h.InvoiceID = #InvoiceID
At the end of the dataset query we can simply add some extra code to update the header table and email the recipient (assumes dbmail is configured on the SQL Server)
So we will end up with a final dataset query that looks like this
SELECT * FROM InvoiceHeader h
JOIN InvoiceDetail d on h.InvoiceID = d.InvoiceID
WHERE h.InvoiceID = #InvoiceID
IF EXISTS(SELECT * FROM InvoiceHeader WHERE InvoiceID = #InvoiceID and Processed IS NULL) -- checks in case the Invoice is being printed for a 2nd time
BEGIN
-- update the header table
UPDATE InvoiceHeader SET Processed=1, ProcessedBy = CURRENT_USER WHERE InvoiceID = #InvoiceID
-- send en email
DECLARE #to varchar(100)
DECLARE #body varchar(1000)
SELECT
#to = SubmittedBy,
#body = 'Your invoice ' + #InvoiceID + ' for the amount of ' + CAST(Amount as varchar(30)) + ' has been processed by ' + #ProcessedBy
FROM InvoiceHeader WHERE InvoiceID = #InvoiceID
EXEC msdb.dbo.sp_send_dbmail
#recipients = #to,
#subject = 'Invoice processed',
#body = #body
END
NOTE: This is not tested as I've done this off the top of my head so there may be some silly errors but you should get the idea.

Update database record by selected id and reset the initial record

Please how do i update all record to 0 and set only the selected ID to 1
UPDATE address SET default_addr = 1
WHERE addr_id = 100 AND user = 'peter'
The above query will update the selected address to 1 which is good, but i want to set other address or the old selected default to 0 with one query
In MySQL, you can do:
UPDATE address
SET default_addr = (addr_id = 100 AND user = 'peter');
(This shorthand uses the fact that MySQL treats booleans as numbers in a numeric context, with "0" for false and "1" for true.)
If you want only one default address for the user named Peter, then use a where:
UPDATE address
SET default_addr = (addr_id = 100)
WHERE user = 'peter';
I suspect this is the logic that you really want.
use a conditional update using case statement
update address set default_address = case when addr_id = 100 and user = 'peter' then 1 else 0 end
here is a functional example
I built a sample schema. These are often helpful to provide in your future questions.

Update 500+ field records to include an increment value + attribute value

Im looking to update 500+ records in my mysql database so that the fields will be a value combination of an $incremental_value+db_user_first_name+#some_static_text. An example of the wished outcome:
1_firstname#staticstring.com, 2_george#staticstring.com, 3_johnny#staticstring.com etc.
I've been playing around with some approach as the following, but that naturally doesn't work (modified for hopefully better clarification).
UPDATE user
SET email = (($incremental_value+1)+(user.first_name))"#staticstring.com"
WHERE email = "empty#empty.com"
The correct syntax for string concatenation in MySQL is the concat() function:
UPDATE user cross join
(select #i = VALUETOSTART) var
SET email = concat(#i := #i + 1, '_', user.first_name, '#staticstring.com')
WHERE email = 'empty#empty.com';

Basic logic in MySQL

Our current mysql script that connects our Invoicing software to our website updates stock levels and what not, but there is a field in our products table which dictates if the product is visible or not which the script does not address. I want to introduce some IF logic to set the prodvisible column to 1 IF the stock level it's being updated with is > 0.
In my research, it appears that IF's cannot appear outwith functions, sadly something I have no experience of and despite my best efforts I can't get it to work.
The current script we have which works succesfully to update stock levels is as follows...
update isc_products p
set
p.prodcurrentinv =[{Level_LessOrderBook}]
where p.prodcode = '[{ItemNumber}]' and p.prodinvtrack=1
--GO;--
update isc_product_variation_combinations pvc
set
pvc.vcstock = [{Level_LessOrderBook}]
where pvc.vcsku='[{ItemNumber}]'
I want to integrate something into the first section that does something like the following
If [{Level_LessOrderBook}] > 0
p.prodvisible = 1 where p.prodcode = '[{ItemNumber}]'
ENDIF
I don't want it to set the product to invisible if it it's out of stock, just visible if it's in stock.
Thanks for any help.
You should be able to do this without an IF statement:
update isc_products p
set p.prodvisible = 1
where p.prodcode = '[{ItemNumber}]'
and [{Level_LessOrderBook}] > 0
Or, if you were asking about doing it in one statement:
update isc_products p
set
p.prodcurrentinv = [{Level_LessOrderBook}],
p.prodvisible = IF([{Level_LessOrderBook}] > 0, 1, p.prodvisible)
where p.prodcode = '[{ItemNumber}]' and p.prodinvtrack=1
Finally, how about this?
update
isc_products p
set
p.prodcurrentinv = [{Level_LessOrderBook}],
p.prodvisible = case when [{Level_LessOrderBook}] > 0 then 1 else p.prodvisible end
where
p.prodcode = '[{ItemNumber}]'
and p.prodinvtrack = 1
--GO;--
update
isc_product_variation_combinations pvc
set
pvc.vcstock = [{Level_LessOrderBook}]
where
pvc.vcsku='[{ItemNumber}]'
I formatted everything in exactly the same way as the rest of your existing script. Are you sure that the column prodvisible exists, is spelled correctly, and takes a numeric or bit value?

How do I update a table with fields selected from another table?

Although there are many questions similar to this, such as
"Updating a record from another table", but i could not get this working.
I have a query that selects and updates table sem_stdexamfinresmark. The select subquery returns multiple rows of data whose size may not be equal to the table being updated, but the update is now working.
The query looks like :
update sem_stdexamfinresmark sr,
(select
se.currsession,
str.studentid,
str.classid,
str.subjectid,
str.aggScore*(select gbtp.percentage from gb_termpercentage gbtp where gbtp.termname = se.examtype)/100 as aggPer,
str.aggGrade
from
sem_stdexamtermresr str,
sem_exam se
where
str.examid=se.examid and
se.examtype = 'Second Term' and
se.currsession =1 and classid='8'
) s
set
sr.SecondTermMark = s.aggPer and
sr.SecondTermGrade = s.aggGrade
where
sr.studentid=s.studentid and
sr.subjectid=s.subjectid and
s.currsession = s.currsession and
sr.classid='8';
EDIT:
update sem_stdexamfinresmark
set
sr.SecondTermMark = s.aggPer and
sr.SecondTermGrade = s.aggGrade
from
(select
se.currsession,
str.studentid,
str.classid,
str.subjectid,
str.aggScore*(select gbtp.percentage from gb_termpercentage gbtp where gbtp.termname = se.examtype)/100 as aggPer,
str.aggGrade
from
sem_stdexamtermresr str,
sem_exam se
where
str.examid=se.examid and
se.examtype = 'Second Term' and
se.currsession = 1 and classid='8'
) s
where
sr.studentid=s.studentid and
sr.subjectid=s.subjectid and
s.currsession =1 and
sr.classid='8';
select * from sem_exam;
update sem_exam set currsession =1;
try something that looks more like:
update foo
set col = bar.col
from bar
where ...
This is what happens when one loses sleep :( I just did a silly mistake here and added "and"