There's a number of offerings on the app exchange for connecting SQL server to Salesforce. One of the well regarded ones is dbamp - there's full details of their offering at:
You could also achieve this via an ODBC driver - again there are a few providers - here's one example:
The problem is that you already have status by select * (status was already present in the table). I would advise you either don't use the select * or change the alias of the case function e.g. Substatus.
If you target de has a primary key, we could speed this alot by Setting the Write Mode to Update and doing this:
I've used it earlier and it calculates itself based on the days in the month. So, it does not default to 30 days and adjusts based on the days in the month (I believe it handles leap year as well). You can run a quick test to verify it before you automate it.
Unfortunately, this is not very well documented in SFMC guides.
I think the differences between SQL and SOQL would limit the usefulness of SQL Server Management Studio. You would probably be better off with a tool that directly builds SOQL.
Some options include:
Workbench SOQL Query
FuseIT SFDC Explorer (Disclosure - this is a free tool from my current employer)
If you really want to use SQL Server ...
Adding to the above answer a very good tool which is also open source is Talend that can connect sfdc and SQL servers
Talend provides outofbox connectors and drivers and you will need to just handle the mappings more like informatica on demand .Informatica is paid tool while basic version of Talend is open ...
Salesforce does not use SQL Server, so you can't just connect from SQL Server Management Studio. A quick Google search found at least one product that claims to allow you to connect from Management Studio: https://www.devart.com/news/2015/odbc-salesforce.html.
I've also used a product called DBAmp to connect to Salesforce from SQL Server, but I don't think ...
Date data types in SFMC are DateTime (or DateTime2) data types behind the scenes, so the time is always included. It's best to use AMPscript to format these, as you can't dictate the format stored in the data extension unless you store them as Text.
I generally just use the formatDate() function in AMPscript:
set @date_field = ...
No. Query Activities can only be Select statements.
Here is what's supported:
The SQL support for the Query Activity is based on SQL Server 2005
Only SELECT statements to data extension or data views in an account
or in the parent account
You can use Tracking Data Extracts and FTP them wherever you need.
The result of these extracts is a ZIP file that contains individual files for each of the options (e.g. Sent.txt, SendJobs.txt) for the date range you've configured. Whatever process on your side is consuming these files will need to unzip to a temporary directory and import.
Here are the ...
Boolean values can be represented with 1 or 0. Assuming the there's not always going to be a match in 4DaySend, I'd do something like this:
, M.PersonHasOptedOutOfEmail PersonHasOptedOutOfEmail
FROM MasterSubscriberDE M
LEFT JOIN [4DaySend] F ON (M.SubscriberKey = F.SubscriberKey)
WHERE m.PersonHasOptedOutOfEmail = 0
Typically if Query Activities fail, it's one of these 6 things:
Primary key violation -- your query results in duplicate rows not allowed by the primary key
Inserting a null value into a non-nullable field
Inserting a value too long for the field (truncation)
Timeout -- if your query doesn't complete within the 30-minute timeout window, it'll error out.
I've had passed success at using both Gaurav's ampscript approach and Arvind's SQL approach.
You can use Case statements to make Arvind's SQL query more fault tolerant.
WHEN CHARINDEX('-',linkname) > 0 THEN Substring(linkname,1,CHARINDEX('-', linkname)-1)
END as HEREISVALUE1
Rather than handling this in the query itself, you can use the ampscript utility functions
IndexOf("Your String", "-") will give you the indices of the hyphens
Then use those indices with
Substring("Your String", "-") to get the 2 relevant sub-strings
Based on the example above
IndexOf("APPLE-ORANGES-52", "-") will return 6
I'm told that you can request Marketing Cloud Support to index specific fields in a specific Data Extension, which may help you here, or it may not.
The real issue is that Marketing Cloud simply isn't designed to process hundreds of millions of records. If it was, you wouldn't be running into this problem in the first place.
I have a client with 160 ...
If it's just summing column values of the records between two dates, here's a simpler approach:
, sum(t2.record) record
from table1 t1
inner join table2 t2 on t1.code = t2.code
where t1.mydate >= convert(date, getDate()-1)
and t1.myDate < convert(date, getDate())
This just sums the t2.record ...
In SFMC, you can use an OUTER APPLY. That should work for your scenario:
WHEN '' THEN 'N/A'
END AS SurveyResponse
, (CONVERT(DECIMAL(3, 1), COUNT(*) * 100.0 / (x.totalCount) )) AS ResponsePercentage
, x.totalCount AS TotalUnsubscribes
FROM DEName AS de1
OUTER APPLY (
I would write your query like this. The IsUnique = 1 will limit it only unique opens by a subscriber for a specific send.
IsUnique = 1
and TriggeredSendCustomerKey in ('Trigger_Name','Trigger_Name_B')
The System Data View schemas can be found on this page on the SFMC ...
Late to the party with this answer but hope it helps others...
Salesforce - SQL integration has been a key part of my job for the last 9 years for both on premise backups to SQL of Salesforce and SSIS packages to run adhoc / scheduled uploads to and extracts from Salesforce via SQL / SSIS.
...by Sesame Software has been very effective ...
Here is an article on how to create data extensions. This may help, but it is not that easy of a task to do what you are looking to do unless you are fairly technically savvy.
SELECT Owner.Name FROM Account WHERE ...
Any time you've got a standard field which is a lookup, you can just remove 'Id' from the end and add '.Name' (or whatever other field you want). If you're dealing with a custom field (ending in __c), you can do the same with '__r.Name'
The error is kind of misleading, but you're missing a quote:
and opp.first_mkt_medium not in ('partner', inbound_outbound')
and opp.first_mkt_medium not in ('partner', 'inbound_outbound')
The syntax highlighting in the question (at least on my device), revealed the error.
In the future, I suggest using something like Programmer's Notepad in ...
Your constructor accepts startDatetime and endDatetime as String parameters, but you are trying to pass in Datetime values. You have two options:
Change the parameter types to Datetime.
Pass in the values as String data.
I would prefer option 1. You can still put them into the map as strings in a variety of ways, the simplest of which is to call Datetime....
Unfortunately at this time the only method to debug failing queries is to open a support case and advise support of which Automation the Query Activity is used in. Support can then check the logs to see what the error is.
FYI, in the near future Automation Studio will show you the actual error message for failed Activities in an Automation (yay!) — refer ...
There is a hidden, indexed field in every data called _customObjectKey and it's fast. While it seems counter-intuitive, you can leverage it in your queries that are timing out by adding an additional join:
, isnull(sl.ListID,0) ListID
, isnull(sl.BatchID,0) BatchID
, isnull(sl.SubID,0) SubID
, isnull(sl.TriggeredSendID,'') ...
You can find those records containing multi-byte characters by converting the First Name field to a single-byte data type and then comparing against the First Name for equality:
FirstName != cast(FirstName as varchar(1000))
If you're specifically interested in locating records that contain the ...
Because you are only interested in distinct leads I would use this:
Row_Number() Over(PARTITION BY EmailAddress ORDER BY CreatedDate DESC) AS Row
FROM ent._ListSubscribers L
where l.ListID in (20798913, 20757098, 20828774, 20233021, 20551644, ...
There are many samples in the official page.
You should be able to query
// SOAP_CLIENT_BASEDIR - folder that contains the PHP Toolkit and your WSDL
// $USERNAME - variable that contains your Salesforce.com username (must be in the form of an email)
// $PASSWORD - variable that ...