<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.talis.com/tdn" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>Talis Developer Network - Inserting email details via script - Comments</title>
 <link>http://www.talis.com/tdn/node/1679</link>
 <description>Comments for &quot;Inserting email details via script&quot;</description>
 <language>en</language>
<item>
 <title>Cheers Brian</title>
 <link>http://www.talis.com/tdn/node/1679#comment-416</link>
 <description>&lt;p&gt;Thank you ever-so much Brian.&lt;br /&gt;
Looks like just the thing we need to get us started.&lt;/p&gt;
&lt;p&gt;Wonderful!&lt;br /&gt;
Rich&lt;/p&gt;
</description>
 <pubDate>Tue, 28 Nov 2006 10:27:50 +0000</pubDate>
 <dc:creator>richardl</dc:creator>
 <guid isPermaLink="false">comment 416 at http://www.talis.com/tdn</guid>
</item>
<item>
 <title>example SQL for CONTACT table</title>
 <link>http://www.talis.com/tdn/node/1679#comment-414</link>
 <description>&lt;p&gt;As an example the following SQL would insert a row in the CONTACT table.  However this is in no way a script that would work as written for what you want but it does give a starting point. &lt;/p&gt;
&lt;p&gt;It is just for a specified borrower id and reports the CONTACT_ID used for checking in the db.  As I said in my earlier posting there are a lot more questions that would need to be considered for a robust script.  Another check would be has a row already been inserted.  This script would just keep inserting a row for a borrower everytime it was run which would not be a godd idea.&lt;/p&gt;
&lt;p&gt;As always run this on your MIS server and not your live system.  The script returns the CONTACT_ID so you can check the inserted row in the CONTACT table.&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
isql -Usa -P&lt;&lt;-END&lt;/p&gt;
&lt;p&gt;use prod_talis&lt;br /&gt;
go&lt;/p&gt;
&lt;p&gt;	declare @contact_id ID,&lt;br /&gt;
		@borrower_id ID,&lt;br /&gt;
		@address OBJNAME&lt;/p&gt;
&lt;p&gt;	select @borrower_id = 11111&lt;/p&gt;
&lt;p&gt;	select @address = &quot;mailto:&quot; + REGISTRATION_NUMBER + &quot;@bradfordcollege.ac.uk&quot;&lt;br /&gt;
	from BORROWER&lt;br /&gt;
	where BORROWER_ID = @borrower_id&lt;/p&gt;
&lt;p&gt;        begin tran&lt;/p&gt;
&lt;p&gt;        update  CONTACT_RID&lt;br /&gt;
        set CONTACT_ID = CONTACT_ID + 1&lt;/p&gt;
&lt;p&gt;        select @contact_id = CONTACT_RID.CONTACT_ID&lt;br /&gt;
        from CONTACT_RID&lt;/p&gt;
&lt;p&gt;        insert  into CONTACT&lt;br /&gt;
                (CONTACT_ID        ,&lt;br /&gt;
                 CONTACT_TYPE      ,&lt;br /&gt;
                 TARGET_ID         ,&lt;br /&gt;
                 TARGET_TYPE       ,&lt;br /&gt;
                 PREFERRED         ,&lt;br /&gt;
                 DISPLAY_VALUE     ,&lt;br /&gt;
                 CONTACT_NAME      ,&lt;br /&gt;
                 START_DATE        ,&lt;br /&gt;
                 END_DATE          ,&lt;br /&gt;
                 NOTE&lt;br /&gt;
                )&lt;br /&gt;
        values&lt;br /&gt;
                (@contact_id,&lt;br /&gt;
                 0,&lt;br /&gt;
                 @borrower_id,&lt;br /&gt;
                 0,&lt;br /&gt;
                 &#039;T&#039;,&lt;br /&gt;
                 @address,&lt;br /&gt;
                 &#039;Email&#039;,&lt;br /&gt;
                 &#039;Jan 1 1970&#039;,&lt;br /&gt;
                 &#039;Jan 1 1970&#039;,&lt;br /&gt;
                 &#039;&#039;&lt;br /&gt;
                )&lt;/p&gt;
&lt;p&gt;        if @@rowcount != 1&lt;br /&gt;
        begin&lt;br /&gt;
                select 0&lt;br /&gt;
                raiserror 20001 &#039;insert failed&#039;&lt;br /&gt;
        end&lt;/p&gt;
&lt;p&gt;        else&lt;br /&gt;
        begin&lt;br /&gt;
                select @contact_id&lt;br /&gt;
        end&lt;/p&gt;
&lt;p&gt;        commit tran&lt;/p&gt;
&lt;p&gt;go&lt;br /&gt;
END&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Brian Crampton&lt;br /&gt;
Developer, Talis&lt;/p&gt;
</description>
 <pubDate>Tue, 21 Nov 2006 16:03:47 +0000</pubDate>
 <dc:creator>Brian Crampton</dc:creator>
 <guid isPermaLink="false">comment 414 at http://www.talis.com/tdn</guid>
</item>
<item>
 <title>adding CONTACT table rows</title>
 <link>http://www.talis.com/tdn/node/1679#comment-413</link>
 <description>&lt;p&gt;The CONTACT_RID update is probably the easier part of a script.&lt;/p&gt;
&lt;p&gt;The logic would be&lt;/p&gt;
&lt;p&gt;        update  CONTACT_RID&lt;br /&gt;
        set CONTACT_ID = CONTACT_ID + 1&lt;/p&gt;
&lt;p&gt;        select CONTACT_RID.CONTACT_ID&lt;br /&gt;
        from CONTACT_RID&lt;/p&gt;
&lt;p&gt;Although the challenging side is creating the email address.  I assume that the college id is taken from the data in the ID field which is held in the BORROWER.REGISTRATION_NUMBER attribute.  &lt;/p&gt;
&lt;p&gt;Concatening this between the &quot;mailto:&quot; and &quot;@bradfordcollege.ac.uk&quot; is straightforward but the problem will be if you want any validation or checking of borrowers.  At its most basic this is checking if there is a value at all for a borrower in the REGISTRATION_NUMBER attribute but it could be more complicated if you want to do more checking e.g. where there is a number of characters or that the id data starts with a particular string.  To a large extent it depends on the data in your database.&lt;/p&gt;
&lt;p&gt;If you don&#039;t do any checks then you run the risk of &quot;dodgy&quot; emails being entered.  As with most scripts the complex bit is the checks that make sure something unexpected doesn&#039;t happen. &lt;/p&gt;
&lt;p&gt;Brian Crampton&lt;br /&gt;
Developer, Talis&lt;/p&gt;
</description>
 <pubDate>Tue, 21 Nov 2006 15:21:15 +0000</pubDate>
 <dc:creator>Brian Crampton</dc:creator>
 <guid isPermaLink="false">comment 413 at http://www.talis.com/tdn</guid>
</item>
<item>
 <title>Cheers Brian... so not as</title>
 <link>http://www.talis.com/tdn/node/1679#comment-412</link>
 <description>&lt;p&gt;Cheers Brian... so not as easy as we might have hoped then (curses).&lt;br /&gt;
I don&#039;t suppose anyone can offer any ideas can they?  Essentially we need to update two tables then - the CONTACT_RID table (which just seems to be a container for CONTACT_ID) and then the rest of the details in the CONTACT table.&lt;br /&gt;
sounds messy!&lt;/p&gt;
&lt;p&gt;Any thoughts gratfully received!&lt;br /&gt;
Rich&lt;/p&gt;
</description>
 <pubDate>Mon, 20 Nov 2006 11:00:04 +0000</pubDate>
 <dc:creator>richardl</dc:creator>
 <guid isPermaLink="false">comment 412 at http://www.talis.com/tdn</guid>
</item>
<item>
 <title>CONTACT table</title>
 <link>http://www.talis.com/tdn/node/1679#comment-405</link>
 <description>&lt;p&gt;The CONTACT table contains the attribute CONTACT_ID which is the unique identifer for each row and so cannot be NULL which it would be in your SQL as it does not specify the value.&lt;/p&gt;
&lt;p&gt;The CONTACT_ID is taken from the CONTACT_RID table.  The value is incremented and then selected for use.&lt;/p&gt;
&lt;p&gt;Any process for inserting records in the CONTACT table needs to take account of the CONTACT_RID table.  If you don&#039;t you will get into issues with the on-line as well.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Brian Crampton&lt;br /&gt;
Developer, Talis&lt;/p&gt;
</description>
 <pubDate>Fri, 10 Nov 2006 15:42:51 +0000</pubDate>
 <dc:creator>Brian Crampton</dc:creator>
 <guid isPermaLink="false">comment 405 at http://www.talis.com/tdn</guid>
</item>
<item>
 <title>Inserting email details via script</title>
 <link>http://www.talis.com/tdn/node/1679</link>
 <description>&lt;p&gt;Hi - apologies for the long post.....&lt;/p&gt;
&lt;p&gt;This year we were hoping to import borrower email addresses with the normal import script.  I understand that there is a problem with this script so we are trying to roll our own solution.  Student email addresses this year take the form of COLLEGE_ID_NUMBER@bradfordcollege.ac.uk so we assumed that it would be a fairly painless process to cobble together a script which would fill in the email details based on the student ID.&lt;br /&gt;
The nub of the script performs the following sql&lt;br /&gt;
INSERT into CONTACT&lt;br /&gt;
(CONTACT_TYPE, TARGET_ID, TARGET_TYPE, PREFERRED, DISPLAY_VALUE, CONTACT_NAME)&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.talis.com/tdn/node/1679&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://www.talis.com/tdn/node/1679#comments</comments>
 <category domain="http://www.talis.com/tdn/taxonomy/term/60">Talis Library System</category>
 <pubDate>Fri, 10 Nov 2006 14:49:27 +0000</pubDate>
 <dc:creator>richardl</dc:creator>
 <guid isPermaLink="false">1679 at http://www.talis.com/tdn</guid>
</item>
</channel>
</rss>
