<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://dbshelp.devio.at/index.php?action=history&amp;feed=atom&amp;title=Dbo.ufnGetContactInformationfunction</id>
		<title>Dbo.ufnGetContactInformationfunction - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://dbshelp.devio.at/index.php?action=history&amp;feed=atom&amp;title=Dbo.ufnGetContactInformationfunction"/>
		<link rel="alternate" type="text/html" href="http://dbshelp.devio.at/index.php?title=Dbo.ufnGetContactInformationfunction&amp;action=history"/>
		<updated>2026-05-03T14:15:11Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://dbshelp.devio.at/index.php?title=Dbo.ufnGetContactInformationfunction&amp;diff=2548&amp;oldid=prev</id>
		<title>Bot: New page: == wikibot ==  {| border=&quot;1&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse:collapse&quot; |- valign=&quot;top&quot; | '''Function | dbo.ufnGetContactInformation |- valign=&quot;top&quot; | '''Description ...</title>
		<link rel="alternate" type="text/html" href="http://dbshelp.devio.at/index.php?title=Dbo.ufnGetContactInformationfunction&amp;diff=2548&amp;oldid=prev"/>
				<updated>2010-06-23T22:07:37Z</updated>
		
		<summary type="html">&lt;p&gt;New page: == wikibot ==  {| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; style=&amp;quot;border-collapse:collapse&amp;quot; |- valign=&amp;quot;top&amp;quot; | &amp;#039;&amp;#039;&amp;#039;Function | dbo.ufnGetContactInformation |- valign=&amp;quot;top&amp;quot; | &amp;#039;&amp;#039;&amp;#039;Description ...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== wikibot ==&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; style=&amp;quot;border-collapse:collapse&amp;quot;&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| '''Function&lt;br /&gt;
| dbo.ufnGetContactInformation&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| '''Description&lt;br /&gt;
| Table value function returning the first name, last name, job title and contact type for a given contact.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Source ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE FUNCTION [dbo].[ufnGetContactInformation](@ContactID int)&lt;br /&gt;
RETURNS @retContactInformation TABLE &lt;br /&gt;
(&lt;br /&gt;
    -- Columns returned by the function&lt;br /&gt;
    [ContactID] int PRIMARY KEY NOT NULL, &lt;br /&gt;
    [FirstName] [nvarchar](50) NULL, &lt;br /&gt;
    [LastName] [nvarchar](50) NULL, &lt;br /&gt;
    [JobTitle] [nvarchar](50) NULL, &lt;br /&gt;
    [ContactType] [nvarchar](50) NULL&lt;br /&gt;
)&lt;br /&gt;
AS &lt;br /&gt;
-- Returns the first name, last name, job title and contact type for the specified contact.&lt;br /&gt;
BEGIN&lt;br /&gt;
    DECLARE &lt;br /&gt;
        @FirstName [nvarchar](50), &lt;br /&gt;
        @LastName [nvarchar](50), &lt;br /&gt;
        @JobTitle [nvarchar](50), &lt;br /&gt;
        @ContactType [nvarchar](50);&lt;br /&gt;
&lt;br /&gt;
    -- Get common contact information&lt;br /&gt;
    SELECT &lt;br /&gt;
        @ContactID = ContactID, &lt;br /&gt;
        @FirstName = FirstName, &lt;br /&gt;
        @LastName = LastName&lt;br /&gt;
    FROM [Person].[Contact] &lt;br /&gt;
    WHERE [ContactID] = @ContactID;&lt;br /&gt;
&lt;br /&gt;
    SET @JobTitle = &lt;br /&gt;
        CASE &lt;br /&gt;
            -- Check for employee&lt;br /&gt;
            WHEN EXISTS(SELECT * FROM [HumanResources].[Employee] e &lt;br /&gt;
                WHERE e.[ContactID] = @ContactID) &lt;br /&gt;
                THEN (SELECT [Title] &lt;br /&gt;
                    FROM [HumanResources].[Employee] &lt;br /&gt;
                    WHERE [ContactID] = @ContactID)&lt;br /&gt;
&lt;br /&gt;
            -- Check for vendor&lt;br /&gt;
            WHEN EXISTS(SELECT * FROM [Purchasing].[VendorContact] vc &lt;br /&gt;
                    INNER JOIN [Person].[ContactType] ct &lt;br /&gt;
                    ON vc.[ContactTypeID] = ct.[ContactTypeID] &lt;br /&gt;
                WHERE vc.[ContactID] = @ContactID) &lt;br /&gt;
                THEN (SELECT ct.[Name] &lt;br /&gt;
                    FROM [Purchasing].[VendorContact] vc &lt;br /&gt;
                        INNER JOIN [Person].[ContactType] ct &lt;br /&gt;
                        ON vc.[ContactTypeID] = ct.[ContactTypeID] &lt;br /&gt;
                    WHERE vc.[ContactID] = @ContactID)&lt;br /&gt;
&lt;br /&gt;
            -- Check for store&lt;br /&gt;
            WHEN EXISTS(SELECT * FROM [Sales].[StoreContact] sc &lt;br /&gt;
                    INNER JOIN [Person].[ContactType] ct &lt;br /&gt;
                    ON sc.[ContactTypeID] = ct.[ContactTypeID] &lt;br /&gt;
                WHERE sc.[ContactID] = @ContactID) &lt;br /&gt;
                THEN (SELECT ct.[Name] &lt;br /&gt;
                    FROM [Sales].[StoreContact] sc &lt;br /&gt;
                        INNER JOIN [Person].[ContactType] ct &lt;br /&gt;
                        ON sc.[ContactTypeID] = ct.[ContactTypeID] &lt;br /&gt;
                    WHERE [ContactID] = @ContactID)&lt;br /&gt;
&lt;br /&gt;
            ELSE NULL &lt;br /&gt;
        END;&lt;br /&gt;
&lt;br /&gt;
    SET @ContactType = &lt;br /&gt;
        CASE &lt;br /&gt;
            -- Check for employee&lt;br /&gt;
            WHEN EXISTS(SELECT * FROM [HumanResources].[Employee] e &lt;br /&gt;
                WHERE e.[ContactID] = @ContactID) &lt;br /&gt;
                THEN 'Employee'&lt;br /&gt;
&lt;br /&gt;
            -- Check for vendor&lt;br /&gt;
            WHEN EXISTS(SELECT * FROM [Purchasing].[VendorContact] vc &lt;br /&gt;
                    INNER JOIN [Person].[ContactType] ct &lt;br /&gt;
                    ON vc.[ContactTypeID] = ct.[ContactTypeID] &lt;br /&gt;
                WHERE vc.[ContactID] = @ContactID) &lt;br /&gt;
                THEN 'Vendor Contact'&lt;br /&gt;
&lt;br /&gt;
            -- Check for store&lt;br /&gt;
            WHEN EXISTS(SELECT * FROM [Sales].[StoreContact] sc &lt;br /&gt;
                    INNER JOIN [Person].[ContactType] ct &lt;br /&gt;
                    ON sc.[ContactTypeID] = ct.[ContactTypeID] &lt;br /&gt;
                WHERE sc.[ContactID] = @ContactID) &lt;br /&gt;
                THEN 'Store Contact'&lt;br /&gt;
&lt;br /&gt;
            -- Check for individual consumer&lt;br /&gt;
            WHEN EXISTS(SELECT * FROM [Sales].[Individual] i &lt;br /&gt;
                WHERE i.[ContactID] = @ContactID) &lt;br /&gt;
                THEN 'Consumer'&lt;br /&gt;
        END;&lt;br /&gt;
&lt;br /&gt;
    -- Return the information to the caller&lt;br /&gt;
    IF @ContactID IS NOT NULL &lt;br /&gt;
    BEGIN&lt;br /&gt;
        INSERT @retContactInformation&lt;br /&gt;
        SELECT @ContactID, @FirstName, @LastName, @JobTitle, @ContactType;&lt;br /&gt;
    END;&lt;br /&gt;
&lt;br /&gt;
    RETURN;&lt;br /&gt;
END;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== References ===&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; style=&amp;quot;border-collapse:collapse&amp;quot;&lt;br /&gt;
|- style=&amp;quot;background:silver&amp;quot;&lt;br /&gt;
| '''Dependency Type&lt;br /&gt;
| '''Object Type&lt;br /&gt;
| '''Referenced Object&lt;br /&gt;
&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| Select&lt;br /&gt;
| Table&lt;br /&gt;
| [[HumanResources.Employee_(table)|HumanResources.Employee]]&lt;br /&gt;
&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| Select&lt;br /&gt;
| Table&lt;br /&gt;
| [[Person.Contact_(table)|Person.Contact]]&lt;br /&gt;
&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| Select&lt;br /&gt;
| Table&lt;br /&gt;
| [[Person.ContactType_(table)|Person.ContactType]]&lt;br /&gt;
&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| Select&lt;br /&gt;
| Table&lt;br /&gt;
| [[Purchasing.VendorContact_(table)|Purchasing.VendorContact]]&lt;br /&gt;
&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| Select&lt;br /&gt;
| Table&lt;br /&gt;
| [[Sales.Individual_(table)|Sales.Individual]]&lt;br /&gt;
&lt;br /&gt;
|- valign=&amp;quot;top&amp;quot;&lt;br /&gt;
| Select&lt;br /&gt;
| Table&lt;br /&gt;
| [[Sales.StoreContact_(table)|Sales.StoreContact]]&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Bot</name></author>	</entry>

	</feed>