Tags

CRM & Technology Management


Sales and Marketing Advisor


Sign Up For the Newsletter

Login

Welcome to the Technology Advisors Blog!!

A short description about your blog
Jun 21
2011

Concatenating Multiple Rows in SQL

Posted by: Ingrid Keyser in MyBlog

Tagged in: Tips & Tricks

Ingrid Keyser

SQL is often overlooked for programming capabilities. The concatenation function below saved me a lot of time in application programming to simplify presenting a 1-Many data relationship.  This function has been extremely useful for me in report writing, data presentation , etc.

 
The function takes a group of related records and returns a csv of the multiple rows
 
Example…
 
 
Account(Parent Table) ParentID     Name
1    ABC
2    DEF
 
 
Contacts(1-Many Child Table)
ParentID    ContactID    LastName
1    1    Johnson
1    2    Doe
2    3    Smith
2    4    Adams
2    4    Jones
 
Query using the function…
Select Name, ConcatContacts(ParentID) as Contacts from Account
 
Returns
Name    Contacts
ABC    Johnson, Doe
DEF    Smith, Adams, Jones
 
 
 
SQL Script to create function
 
/********Script Function Begin***********/
 
USE [CMRX_SLX626Prod_JM]
GO
 
/****** Object:  UserDefinedFunction [dbo].[ConcatContacts]    Script Date: 06/17/2011 14:48:01 ******/
SET ANSI_NULLS ON
GO
 
SET QUOTED_IDENTIFIER ON
GO
 
 
 
CREATE FUNCTION [SYSDBA].[ConcatContacts](@ID CHAR(12))
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @Output VARCHAR(8000)
SET @Output = ''
 
SELECT @Output =        CASE @Output WHEN '' THEN LastName ELSE @Output + ', ' + LastName
END
FROM CONTACTS
WHERE PARENTID = @ID ORDER BY CONTACTID
 
RETURN @Output
END
 
 
 
GO
 
 
/********Script Function End***********/

Apr 15
2011

SalesLogix How to Track Entity Change for 1-1 Extension Table

Posted by: Ingrid Keyser in MyBlog

Tagged in: SalesLogix

Ingrid Keyser

I recently had to implement this change for a client that needed to track if a property on an extension table changed and apply a business rule based on the original and new value.  My first response was yes, that can be easily done since SalesLogix has provided this functionality in the framework.  It took a bit of digging around to get it working but I finally was able to implement it successfully.  I have included 2 examples below for reference (the first one does not work).  Code has only been tested in 7.5.1
 
I used the code below...but change is always coming back null.
Sage.Platform.ChangeManagement.IChangedState state = Account as Sage.Platform.ChangeManagement.IChangedState;
Sage.Platform.ChangeManagement.EntityPropertyChange change = state.GetChangedState().FindMemberChange<Sage.Platform.ChangeManagement.EntityPropertyChange>("ExtensionTableName");
        if (change != null && change.OldEntity != null)
        {
            Sage.Entity.Interfaces.IExtensionTableName oldext = (Sage.Entity.Interfaces.IExtensionTableName)change.OldEntity.GetReferencedEntity();
            Sage.Entity.Interfaces.IExtensionTableName newext = (Sage.Entity.Interfaces.IExtensionTableName)change.NewEntity.GetReferencedEntity();
            if (oldext.PropertyName != newext.PropertyName)
            {
                //Process Data here
            }
        }
 
 
Code below works...
Sage.Platform.ChangeManagement.IChangedState state = Account as Sage.Platform.ChangeManagement.IChangedState;
if (state != null)
{
Sage.Platform.ChangeManagement.ChangeSet changedState = state.GetChangedState();
EntityChange changeext = changedState.FindMemberChange<EntityChange>("ExtensionTableName");
if (changeext != null)
{
ChangeSet[] changeextmembers = changeext.GetChildChangeSets();
foreach (ChangeSet member in changeextmembers)
{
Sage.Platform.ChangeManagement.PropertyChange prop = member.FindPropertyChange("PropertyName");
if (prop != null)
{
//Process Data here
}
            }
}
}