I have this working with the Sage 300 company database but need to read from another SQL database.
Does anyone have some sample code to get me started?
Any and All advice greatly appreciated,
Dana
I have this working with the Sage 300 company database but need to read from another SQL database.
Does anyone have some sample code to get me started?
Any and All advice greatly appreciated,
Dana
As long as the account that Sage uses to connect to the database can access the other database you just specify the database in your query:
SELECT SomeField, SomeOtherField FROM [OTHERDB].dbo.[SomeTable]
Just be mindful of other database field types if the other database isn't a Sage database.
If it's on the same server, use the CS0120 view.
So would this work?
SELECT SomeField, SomeOtherField FROM CRM.dbo.Lead
or do I have to specify the server name too? It is the same server
Dana
Perfect! If it's on the same server, just fully qualify the reference.
FWIW, CRM..Lead will work, too. The 'dbo' is implied, so it's less typing for us SQL programmers.
Thanks Jay, my fingers get tired with all this typing.
To simplify further, you can also add your CRM or other database values to the current database using a view.
This is part of my code. It's not working
What have I missed?
Dim SQLStr As String
Dim csTemp As AccpacCOMAPI.AccpacView
Set mComLink = OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)
mComLink.OpenView "CS0120", csTemp
SQLStr = "SELECT Comp_IdCust, Comp_Name, Comp_Status FROM CRM.Company WHERE Comp_Status = Active ORDER BY Comp_IdCust"
csTemp.Browse SQLStr, True '<<< Fails on this line - Method 'Browse' of object 'IAccpavView' failed
csTemp.InternalSet (256)
A period between CRM and Company. You can use two periods instead of .dbo.
SELECT Comp_IdCust, Comp_Name, Comp_Status FROM CRM..Company WHERE Comp_Status = Active ORDER BY Comp_IdCust
Okay, I got it reading the CRM data but I now have an issue with the format of the variables for the date fields. After the SQL read I use Fetch to assign the data to variables like below
o While csTemp.Fetch = True
mCRMSalesPerson = csTemp.Fields.FieldByName("Lead_AssignedUserID").Value
mLeadDate = csTemp.Fields.FieldByName("Lead_CreatedDate").Value
mSoldDate = csTemp.Fields.FieldByName("lead_companysolddate").Value
mSource = csTemp.Fields.FieldByName("lead_companysource").Value
I have mLeadDate and mSoldDate dimensioned as 'Date'. This doesn't work. I thought I'd try Dim as String but that doesn't work either.
What should I be using?
*Community Hub is the new name for Sage City