Tel. +44(0)208 4716864
info@softstuff-consulting.com
Follow us on Twitter  http://www.twitter.com/softstuffc
Softstuff Home Knowledgebase Home Contact Us Blog
GoldMine CRM SQL Server QuoteWerks Microsoft Excel Microsoft Word C# Windows XP Microsoft Dynamics CRM HEAT Sage CRM
Getting a snapshot of Contact2 data

Recently I came across a situation where the customer wanted to go through all
the custom fields that had been added since the system was first installed
years ago, and decide what was still relevant and what could be removed.

Fortunately they had upgraded to SQL Server, a while ago otherwise it would
have been a real pain in dBase to do the same thing.

I decided the best way to approach this was to get an output in the form of

 
FieldName Screen Name Blanks Sample Data
U24HRM 24 Hr Maintenance Man 34037 NO,NO,NO,NO,NO,NO,NO,NO,,NO,
U24HRP 24 Hour Security Person 34036 NO,NO,NO,NO,NO,NO,NO,NO,,NO,


So we could see what the field was called, how many records didn't have any
data, and what sort of data was actually in the fields.

The first step was to create a temporary table to hold the results.
 
Create table ibResultstemp(fld varchar(50),fldname varchar(100),blanks int, samples varchar(1000))


Next I created a small SQL procedure to find the field names from
information_schema.columns and then query each one in turn to find
out how many were blank, and also to find 10 records that were populated
as an example of the data.

 
declare @t varchar(100)
declare @sql varchar(1000)
declare @line varchar(1000)
declare c cursor for select column_name from information_schema.columns
where table_name = 'Contact2'
open c
fetch c into @t
while @@fetch_status=0
begin

set @sql='insert into ibresultstemp(fld,fldname,blanks,samples)
select '''+@t+''','''',count(*),'''' from contact2 where '+@t+' is null'
exec(@sql)

set @sql='update ibresultstemp set fldname=fielddesc from ibresultstemp
join
contudef on fld=field_name where dbfname=''Contact2'' and
field_name='''+@t+''''

exec(@sql)


set @sql='declare @line varchar(5000);'
set @sql=@sql+'set @line='''';'
set @sql=@sql +'select top 10 @line=cast('+@t+' as varchar)+'',''+@line
from contact2 where '+@t+' is not null;'
set @sql=@sql + 'update ibresultstemp set samples=left(@line,1000)
where fld='''+@t+''''
exec (@sql)

fetch next from c into @t
end
close c
deallocate c

select * from ibresultstemp


The results were then copied from the results grid into Excel and
presented to the customer.

This idea was to quickly get the Contact2 fields, but it could quickly
and easily be adapted for other tables.









24 November 2009  IB      GoldMine CRM


Back To List

Did this article answer your question

 Yes

 No

 



 

Search our knowledgebase

Look In   For  
Enter a word or phrase to search for. eg. shrink

Enter your Email Address to receive the latest knowledgebase items delivered direct to your inbox.

Subscribe to the knowledgebase in your favourite RSS reader:   Plain RSS 2.0 Feed   Add to Google  Add to My Yahoo!

Note:
Softstuff accepts no responsibility for the use of information contained within this item. No warranties are implied or provided and it is advised that you have a working knowledge of the technologies contained, and we will not be held liable for system downtime, or data loss caused, unless we have specifically advised in writing to you that this is the case during the course of a support issue raised and accepted by us.
 

Copyright Softstuff Consulting 2007-2009