Stored Procedure: Pivot With Dynamic Columns

Following is a stored procedure in aims to improve Microsoft built-in function of PIVOT in SQL Server. To use PIVOT, one must know exact number and name of columns after pivot, which does not meet the real world’s need. What we need is the pivot function works with dynamic pivot columns. To use this stored procedure, you would need to create a temporary table first with name of “Temp_Transform_Input”. Following is the structure of the this table:

Column 1, can be any name and data type. It would remain intact as it was after pivot.
Column 2, must be named as “Pivot_Column” and should be VARCHAR data type. Its contents after automatically distinct would be pivoted as column titles after execute this procedure.
Column 3, must be named as “Content_Column” and should be INT data type. It would be summed up after pivot. If the purpose is to count, put 1 here for every record.

To use it, just type EXECUTE P_Transform GO. The result will be automatically saved into 7 temporary tables. You do not need to manage the garbage collection for these two temporary tables, this procedure will manage them for you.

Why use temporary table instead of use Multi-statement Table-Valued Function as output method? Since you are dealing with the dynamic columns, it is impossible to declare the return table in Multi-statement Table-Valued Function.

CREATE PROCEDURE P_Transform
AS
BEGIN
IF EXISTS( SELECT *
FROM SYS.TABLES
WHERE NAME = 'Temp_Transform_Row_Largest'
)
DROP TABLE dbo.Temp_Transform_Row_Largest
IF EXISTS( SELECT *
FROM SYS.TABLES
WHERE NAME = 'Temp_Transform_Row_Sum'
)
DROP TABLE dbo.Temp_Transform_Row_Sum
IF EXISTS( SELECT *
FROM SYS.TABLES
WHERE NAME = 'Temp_Transform_Column_Largest'
)
DROP TABLE dbo.Temp_Transform_Column_Largest
IF EXISTS( SELECT *
FROM SYS.TABLES
WHERE NAME = 'Temp_Transform_Column_Sum'
)
DROP TABLE dbo.Temp_Transform_Column_Sum
IF EXISTS( SELECT *
FROM SYS.TABLES
WHERE NAME = 'Temp_Transform_Both_Largest'
)
DROP TABLE dbo.Temp_Transform_Both_Largest
IF EXISTS( SELECT *
FROM SYS.TABLES
WHERE NAME = 'Temp_Transform_Both_Sum'
)
DROP TABLE dbo.Temp_Transform_Both_Sum
IF EXISTS( SELECT *
FROM SYS.TABLES
WHERE NAME = 'Temp_Transform_Result'
)
DROP TABLE dbo.Temp_Transform_Result
DECLARE @FirstColumn VARCHAR(128)
DECLARE @Summary VARCHAR(512)
DECLARE @Columns VARCHAR(MAX)
DECLARE @Query VARCHAR(MAX)
SELECT @FirstColumn = COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Temp_Transform_Input'
AND ORDINAL_POSITION = 1
SET @Summary =
'
SELECT ' + @FirstColumn + '
, MAX(Content_Column) AS Largest
INTO Temp_Transform_Row_Largest
FROM Temp_Transform_Input
GROUP BY ' + @FirstColumn + '
ORDER BY MAX(Content_Column) DESC
, ' + @FirstColumn + '
'
EXECUTE(@Summary)
SET @Summary =
'
SELECT ' + @FirstColumn + '
, SUM(Content_Column) AS Total
INTO Temp_Transform_Row_Sum
FROM Temp_Transform_Input
GROUP BY ' + @FirstColumn + '
ORDER BY SUM(Content_Column) DESC
, ' + @FirstColumn + '
'
EXECUTE(@Summary)
SET @Summary =
'
SELECT Pivot_Column
, MAX(Content_Column) AS Largest
INTO Temp_Transform_Column_Largest
FROM Temp_Transform_Input
GROUP BY Pivot_Column
ORDER BY MAX(Content_Column) DESC
, Pivot_Column
'
EXECUTE(@Summary)
SET @Summary =
'
SELECT Pivot_Column
, SUM(Content_Column) AS Total
INTO Temp_Transform_Column_Sum
FROM Temp_Transform_Input
GROUP BY Pivot_Column
ORDER BY SUM(Content_Column) DESC
, Pivot_Column
'
EXECUTE(@Summary)
SET @Summary =
'
SELECT ' + @FirstColumn + '
, Pivot_Column
, MAX(Content_Column) AS Largest
INTO Temp_Transform_Both_Largest
FROM Temp_Transform_Input
GROUP BY ' + @FirstColumn + '
, Pivot_Column
ORDER BY MAX(Content_Column) DESC
, Pivot_Column
'
EXECUTE(@Summary)
SET @Summary =
'
SELECT ' + @FirstColumn + '
, Pivot_Column
, SUM(Content_Column) AS Total
INTO Temp_Transform_Both_Sum
FROM Temp_Transform_Input
GROUP BY ' + @FirstColumn + '
, Pivot_Column
ORDER BY SUM(Content_Column) DESC
, ' + @FirstColumn + '
, Pivot_Column
'
EXECUTE(@Summary)
SELECT @Columns = COALESCE( @Columns + ',[' + CAST(LTRIM(RTRIM(Pivot_Column)) AS VARCHAR) + ']'
, '[' + CAST(LTRIM(RTRIM(Pivot_Column)) AS VARCHAR)+ ']'
)
FROM
(
SELECT DISTINCT Pivot_Column
FROM Temp_Transform_Input
) AS Base_Q
SET @Query =
'
SELECT *
INTO Temp_Transform_Result
FROM
(
SELECT *
FROM Temp_Transform_Input
) AS Inner_Q
PIVOT
(
SUM(Content_Column)
FOR Pivot_Column IN (' + @Columns + ')
) AS Pivot_Q
'
EXECUTE(@Query)
IF EXISTS( SELECT *
FROM SYS.TABLES
WHERE NAME = 'Temp_Transform_Input'
)
DROP TABLE dbo.Temp_Transform_Input
END
GO

It is very important the length of each contents in Pivot_Column must be less 30 characters, because the contents will become the column name after transpose. Else, it won't work properly.


http://www.paladn.com/component/content/article/40-sql-server/122-udf-forms.html

Pivot Large Table With Dynamic Columns

In general, it is recommended to use SUM(CASE) GROUP BY method to pivot rows into columns. For details why recommended such, please refer to http://koncordpartners.blogspot.com/2010/03/pivot-turning-rows-into-columns.html. However, in two circumstances SUM(CASE) GROUP BY method does not work:

1. The column numbers are too many. By using SUM(CASE) GROUP BY method, one must know every column’s name.

2. The column names are unknown when generate queries. Usually this could be happened with column names are result from another SELECT statement.

In fact, these two circumstances do always emerge together. In this situation, built-in PIVOT function in Oracle and SQL Server is the only option. In Ms Access, it is TRANSFORM, which is even better in comparison to Oracle and SQL Server, because it accept the list of column names directly from the SELECT statement. Following example is using T-SQL, and the scenario is to draw a matrix table summarizing the total air ambulance flights between airports within a state for past ten year. The involved records are around 500,000.

The PIVOT function is easy:

SELECT *
FROM
(
SELECT sendport AS Sending_Airport
, receiveport AS Receiving_Airport
, 1 AS InterimCounter
FROM dw_Legs
) AS Inner_Q
PIVOT
(
SUM(InterimCounter)
FOR Receiving_Airport IN ([The list of receiving airport])
) AS Pivot_Q

The problem is “The list of receiving airport” must be selected from airport table, and very unfortunately, T-SQL does not accept it as an outcome of SELECT statement. So, dynamic query is the only option left. We human just make our life so miserable by disallow this and disallow that.

Another issue is not all airports receive planes from every rest airports, which means “The list of receiving airport” should not be directly from airport table, rather is should be from the intermediate queries. So, for presentation purpose, a temporary table is the best solution, which is also in accordance with the design of SQL Server.

Step 1

CREATE VIEW V_Airport_Matrix
AS
SELECT sendport AS Sending_Airport
, receiveport AS Receiving_Airport
, 1 AS InterimCounter
FROM dw_Legs
GO

Step 2

Prepare dynamic queries:

DECLARE @columns VARCHAR(MAX)
SELECT @columns = COALESCE(@columns + ',[' + CAST(LTRIM(RTRIM(Receiving_Airport)) AS VARCHAR) + ']', '[' + CAST(LTRIM(RTRIM(Receiving_Airport)) AS VARCHAR)+ ']')
FROM
(
SELECT DISTINCT Receiving_Airport
FROM V_Airport_Matrix
) AS base_Q

Why LTRIM(RTRIM()) is needed? Because the length of the VARCHAR string becomes critical since VARCHAR(MAX) does have limit. And very often, VARCHAR(MAX) does not meet our need here. And, the text, ntext, and image data types are invalid for local variables. Following is the send part of Step 2:

DECLARE @query VARCHAR(MAX)
SET @query =
'
SELECT *
FROM
(
SELECT *
FROM V_Airport_Matrix
) AS Inner_Q
PIVOT
(
SUM(InterimCounter)
FOR Receiving_Airport IN (' + @columns + ')
) AS Pivot_Q
'

What about your query does exceed the VARCHAR(MAX) limit? You will need to shorten the query by cutting them into pieces:

DECLARE @columns VARCHAR(MAX)
SELECT @columns = COALESCE(@columns + ',[' + CAST(LTRIM(RTRIM(Receiving_Airport)) AS VARCHAR) + ']', '[' + CAST(LTRIM(RTRIM(Receiving_Airport)) AS VARCHAR)+ ']')
FROM
(
SELECT DISTINCT Receiving_Airport
FROM V_Airport_Matrix
WHERE Receiving_Airport LIKE 'A%'
OR Receiving_Airport LIKE 'B%'
OR Receiving_Airport LIKE 'C%'
OR Receiving_Airport LIKE 'D%'
OR Receiving_Airport LIKE 'E%'
OR Receiving_Airport LIKE 'F%'
OR Receiving_Airport LIKE 'G%'
OR Receiving_Airport LIKE 'H%'
OR Receiving_Airport LIKE 'I%'
OR Receiving_Airport LIKE 'J%'
OR Receiving_Airport LIKE 'K%'
OR Receiving_Airport 'L%'
) AS base_Q

Then, execute one by one before union together.

Step 3

To execute the queries:

EXECUTE(@query)


http://blog-mstechnology.blogspot.com/2010/06/t-sql-pivot-operator-with-dynamic.html

sign() in PL/SQL

Nothing special. This function is too easy to be forgeten, for so many times. Just record here:

This function returns either -1, 0 or 1.


http://www.techonthenet.com/oracle/functions/sign.php

Terms of Services

Terms of Services
1.1 Koncord Partners Ltd ("Koncord Partners") provides its service to you, subject to the following Terms of Service ("TOS"), which may be updated by us from time to time without notice to you, the terms of a legal agreement between you and Koncord Partners. “Koncord Partner” means Koncord Partners Ltd, whose principal place of business is at Auckland, New Zealand. You can review the most current version of the TOS at any time at this web page. In addition, when using particular Koncord Partners’ services, you may be subject to guidelines or rules or additional terms (which may be posted from time to time) applicable to such services and which are incorporated by reference into the TOS. All such guidelines or rules are hereby incorporated by reference into the TOS. Koncord Partners may also offer other services that are governed by different Terms of Service.
1.2 Unless otherwise agreed in writing with Koncord Partner, your agreement with Koncord Partners will always include, at a minimum, the terms and conditions set out in this document. These are referred to below as the “Universal Terms”.
1.3 Your agreement with Koncord Partners will also include the terms of any Legal Notices applicable to the Services, in addition to the Universal Terms. All of these are referred to below as the “Additional Terms”. Where Additional Terms apply to a Service, these will be accessible for you to read either within, or through your use of, that Service.
1.4 The Universal Terms, together with the Additional Terms, form a legally binding agreement between you and Koncord Partners in relation to your use of the Services. It is important that you take the time to read them carefully. Collectively, this legal agreement is referred to below as the “Terms”.
1.5 If there is any contradiction between what the Additional Terms say and what the Universal Terms say, then the Additional Terms shall take precedence in relation to that Service.
2. Accepting the Terms
2.1 In order to use the Services, you must first agree to the Terms. You may not use the Services if you do not accept the Terms.
2.2 You can accept the Terms by:
(A) Clicking to accept or agree to the Terms, where this option is made available to you by Koncord Partners in the user interface for any Service; or
(B) By actually using the Services. In this case, you understand and agree that Koncord Partners will treat your use of the Services as acceptance of the Terms from that point onwards.
2.3 You may not use the Services and may not accept the Terms if (a) you are not of legal age to form a binding contract with Koncord Partner, or (b) you are a person barred from receiving the Services under the laws of the United States, Australia, New Zealand or other countries including the country in which you are resident or from which you use the Services.
2.4 Before you continue, you should print off or save a local copy of the Universal Terms for your records.
2.5 You are responsible for obtaining access to the Service and that access may involve third party fees (such as Internet service provider or airtime charges). You are responsible for those fees, including fees associated with the display or delivery of advertisements. In addition, you must provide and are responsible for all equipment necessary to access the Service.
2.6 Please be aware that Koncord Partners has created certain areas on the Service that contain adult or mature content. You must have attained the age of majority in the province or territory in which you live to access such areas on the Service.
3. Language of the Terms
3.1 Where Koncord Partners has provided you with a translation of the English language version of the Terms, then you agree that the translation is provided for your convenience only and that the English language versions of the Terms will govern your relationship with Koncord Partners.
3.2 If there is any contradiction between what the English language version of the Terms says and what a translation says, then the English language version shall take precedence.
4. Provision of the Services by Koncord Partners
4.1 Koncord Partners may have subsidiaries and affiliated legal entities around the world (“Subsidiaries and Affiliates”). Sometimes, these companies will be providing the Services to you on behalf of Koncord Partners itself. You acknowledge and agree that Subsidiaries and Affiliates will be entitled to provide the Services to you.
4.2 Koncord Partners is constantly innovating in order to provide the best possible experience for its users. You acknowledge and agree that the form and nature of the Services which Koncord Partners provides may change from time to time without prior notice to you.
4.3 As part of this continuing innovation, you acknowledge and agree that Koncord Partners may stop (permanently or temporarily) providing the Services (or any features within the Services) to you or to users generally at Koncord Partners' sole discretion, without prior notice to you. You may stop using the Services at any time. You do not need to specifically inform Koncord Partners when you stop using the Services.
4.4 You acknowledge and agree that if Koncord Partners disables access to your account, you may be prevented from accessing the Services, your account details or any files or other content which is contained in your account.
4.5 You acknowledge and agree that while Koncord Partners may not currently have set a fixed upper limit on the number of transmissions you may send or receive through the Services or on the amount of storage space used for the provision of any Service, such fixed upper limits may be set by Koncord Partners at any time, at Koncord Partners' discretion.
5. Use of the Services by you
5.1 You understand that all materials, including without limitation, information, data, text, software, music, sound, photographs, graphics, video, and email messages or other kinds of messages ("Content"), whether publicly posted or privately transmitted, are the sole responsibility of the person from which such Content originated. This means that you, and not Koncord Partners, are entirely responsible for all Content that you upload, post, email, transmit, or otherwise make available via the Service. Koncord Partners does not control the Content posted via the Service and, as such, does not guarantee the accuracy, integrity or quality of such Content. You understand that by using the Service, you may be exposed to Content that is offensive, indecent or objectionable. Under no circumstances will Koncord Partners be liable in any way for any Content, including, but not limited to, for any errors or omissions in any Content, or for any loss or damage of any kind incurred as a result of the use of or reliance upon any Content posted, emailed, transmitted, or otherwise made available via the Service. In order to access certain Services, you may be required to provide information about yourself (such as identification or contact details) as part of the registration process for the Service, or as part of your continued use of the Services. You agree that any registration information you give to Koncord Partners will always be accurate, correct and up to date.
5.2 You agree to use the Services only for purposes that are permitted by (a) the Terms and (b) any applicable law, regulation or generally accepted practices or guidelines in the relevant jurisdictions (including any laws regarding the export of data or software to and from the United States, Australia, New Zealand or other relevant countries).
5.3 You agree not to access (or attempt to access) any of the Services by any means other than through the interface that is provided by Koncord Partner, unless you have been specifically allowed to do so in a separate agreement with Koncord Partners. You specifically agree not to access (or attempt to access) any of the Services through any automated means (including use of scripts or web crawlers) and shall ensure that you comply with the instructions set out in any robots.txt file present on the Services.
5.4 You agree that you will not engage in any activity that interferes with or disrupts the Services (or the servers and networks which are connected to the Services).
5.5 Unless you have been specifically permitted to do so in a separate agreement with Koncord Partner, you agree that you will not reproduce, duplicate, copy, sell, trade or resell the Services for any purpose.
5.6 You agree that you are solely responsible for (and that Koncord Partners has no responsibility to you or to any third party for) any breach of your obligations under the Terms and for the consequences (including any loss or damage which Koncord Partners may suffer) of any such breach.
5.7 You agree that you will not use the Service to:
5.7.1 upload, post, email, transmit, or otherwise make available any Content that is harmful, threatening, abusive, harassing, torturous, defamatory, vulgar, obscene, libelous, invasive of another's privacy, hateful, racially, ethnically or otherwise objectionable or generally unlawful;
5.7.2 Harm minors in any way;
5.7.3 Impersonate any person or entity, including, but not limited to, a Koncord Partners official, forum leader, guide or host, or falsely state or otherwise misrepresent your affiliation with a person or entity;
5.7.4 Forge headers or otherwise manipulate identifiers in order to disguise the origin of any Content transmitted through the Service;
5.7.5 upload, post, email, transmit or otherwise make available any Content that you do not have a right to make available under any law or under contractual or fiduciary relationships (such as inside information, proprietary and confidential information learned or disclosed as part of employment relationships or under nondisclosure agreements);
5.7.6 upload, post, email, transmit or otherwise make available any Content that infringes any patent, trademark, trade secret, copyright or other proprietary rights ("Rights") of any party;
5.7.7 upload, post, email, transmit or otherwise make available any unsolicited or unauthorized advertising, promotional materials, "junk mail," "spam," "chain letters," "pyramid schemes," or any other form of illegal solicitation. You may, however, make legally compliant solicitations in those areas (such as shopping rooms) that are designated for such purpose;
5.7.8 upload, post, email, transmit or otherwise make available any material that contains software viruses or any other computer code, files or programs designed to interrupt, destroy or limit the functionality of any computer software or hardware or telecommunications equipment;
5.7.9 disrupt the normal flow of dialogue, cause a screen to "scroll" faster than other users of the Service are able to type, or otherwise act in a manner that negatively affects other users' ability to engage in real time exchanges;
5.7.10 interfere with or disrupt the Service or servers or networks connected to the Service, or disobey any requirements, procedures, policies or regulations of networks connected to the Service;
5.7.11 intentionally or unintentionally violate any applicable local, provincial, national or international law, including, but not limited to, regulations promulgated by the Ontario Securities Commission, any rules of any national or other securities exchange, including, without limitation, the Toronto Stock Exchange, the Montreal Stock Exchange, the New York Stock Exchange, the American Stock Exchange or the NASDAQ, and any regulations having the force of law;
5.7.12 collect or provide funds, directly or indirectly, in order to carry out terrorist crimes, contribute to or facilitate the activities of a terrorist group, or instruct anyone to carry out a terrorist activity, including doing any of the foregoing in relation to a listed entity under s.83.05 of Part II.1 of the Criminal Code.
5.7.13 "stalk" or otherwise harass another; or
5.7.14 collect or store personal data about other users without their express consent or in connection with the prohibited conduct and activities set forth in paragraphs (a) through (m) above.
6. Your passwords and account security
6.1 You agree and understand that you are responsible for maintaining the confidentiality of passwords associated with any account you use to access the Services.
6.2 Accordingly, you agree that you will be solely responsible to Koncord Partners for all activities that occur under your account.
6.3 If you become aware of any unauthorized use of your password or of your account, you agree to notify Koncord Partners immediately at this web page.
7. Privacy and your personal information
7.1 For information about Koncord Partners' data protection practices, please refer to Koncord Partners' privacy policy. This policy explains how Koncord Partners treats your personal information, and protects your privacy, when you use the Services.
7.2 You agree to the use of your data in accordance with Koncord Partners' privacy policies.
7.3 Registration Data and certain other information about you is subject to our Privacy Policy. You understand that through your use of the Service you consent to the collection, use and disclosure of this information, only as permitted by the Privacy Policy, including the transfer of this information to the United States and/or other countries for storage, processing, and use by Koncord Partners and its affiliates in order to provide the Service to you.
7.4 The Koncord Partners I.D. associated with your account is the property of Koncord Partners or its affiliates, and is not your personal information.
8. Content in the Services
8.1 You understand that all information (such as data files, written text, computer software, music, audio files or other sounds, photographs, videos or other images) which you may have access to as part of, or through your use of, the Services are the sole responsibility of the person from which such content originated. All such information is referred to below as the “Content”.
8.2 You should be aware that Content presented to you as part of the Services, including but not limited to advertisements in the Services and sponsored Content within the Services may be protected by intellectual property rights which are owned by the sponsors or advertisers who provide that Content to Koncord Partners (or by other persons or companies on their behalf). You may not modify, rent, lease, loan, sell, distribute or create derivative works based on this Content (either in whole or in part) unless you have been specifically told that you may do so by Koncord Partners or by the owners of that Content, in a separate agreement.
8.3 Koncord Partners reserves the right (but shall have no obligation) to pre-screen, review, flag, filter, modify, refuse or remove any or all Content from any Service. For some of the Services, Koncord Partners may provide tools to filter out explicit sexual content. In addition, there are commercially available services and software to limit access to material that you may find objectionable.
8.4 You understand that by using the Services you may be exposed to Content that you may find offensive, indecent or objectionable and that, in this respect, you use the Services at your own risk.
8.5 You agree that you are solely responsible for (and that Koncord Partners has no responsibility to you or to any third party for) any Content that you create, transmit or display while using the Services and for the consequences of your actions (including any loss or damage which Koncord Partners may suffer) by doing so.
8.6 The Service may provide, or third parties may provide, links to other World Wide Web sites or resources. Because Koncord Partners has no control over such sites and resources, you acknowledge and agree that Koncord Partners is not responsible for the availability of such external sites or resources, and does not endorse and is not responsible or liable for any Content, advertising, products, or other materials on or available from such sites or resources. You further acknowledge and agree that Koncord Partners is not responsible or liable, directly or indirectly, for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such Content, goods or services available on or through any such site or resource.
9. Proprietary rights
9.1 You acknowledge and agree that Koncord Partners (or Koncord Partners' licensors) own all legal right, title and interest in and to the Services, including any intellectual property rights which subsist in the Services (whether those rights happen to be registered or not, and wherever in the world those rights may exist). You further acknowledge that the Services may contain information which is designated confidential by Koncord Partners and that you shall not disclose such information without Koncord Partners' prior written consent.
9.2 Unless you have agreed otherwise in writing with Koncord Partner, nothing in the Terms gives you a right to use any of Koncord Partners' trade names, trademarks, service marks, logos, domain names, and other distinctive brand features.
9.3 If you have been given an explicit right to use any of these brand features in a separate written agreement with Koncord Partner, then you agree that your use of such features shall be in compliance with that agreement, any applicable provisions of the Terms, and Koncord Partner's brand feature use guidelines as updated from time to time.
9.4 Other than the limited license set forth in Section 11, Koncord Partners acknowledges and agrees that it obtains no right, title or interest from you (or your licensors) under these Terms in or to any Content that you submit, post, transmit or display on, or through, the Services, including any intellectual property rights which subsist in that Content (whether those rights happen to be registered or not, and wherever in the world those rights may exist). Unless you have agreed otherwise in writing with Koncord Partner, you agree that you are responsible for protecting and enforcing those rights and that Koncord Partners has no obligation to do so on your behalf.
9.5 You agree that you shall not remove, obscure, or alter any proprietary rights notices (including copyright and trade mark notices) which may be affixed to or contained within the Services.
9.6 Unless you have been expressly authorized to do so in writing by Koncord Partner, you agree that in using the Services, you will not use any trade mark, service mark, trade name, logo of any company or organization in a way that is likely or intended to cause confusion about the owner or authorized user of such marks, names or logos.
9.7 You acknowledge and agree that the Service and any necessary software used in connection with the Service ("Software") contain proprietary and confidential information that is protected by applicable intellectual property and other laws. You further acknowledge and agree that Content contained in sponsor advertisements or information presented to you through the Service or advertisers is protected by copyrights, trademarks, service marks, patents, or other proprietary rights and laws. Except as expressly authorized by Koncord Partners or advertisers, you agree not to modify, rent, lease, loan, sell, distribute or create derivative works based on the Service or the Software, in whole or in part.
9.8 Koncord Partners grants you a personal, non-transferable and non-exclusive right and license to use the object code of its Software on a single computer; provided that you do not (and do not allow any third party to) copy, modify, create a derivative work of, reverse engineer, reverse assemble, or otherwise attempt to discover any source code, sell, assign, sublicense, grant a security interest in, or otherwise transfer any right in the Software. You agree not to modify the Software in any manner or form, or to use modified versions of the Software, including (without limitation) for the purpose of obtaining unauthorized access to the Service. You agree not to access the Service by any means other than through the interface that is provided by Koncord Partners for use in accessing the Service.
10. License from Koncord Partners
10.1 Koncord Partners gives you a personal, worldwide, royalty-free, non-assignable and non-exclusive license to use the software provided to you by Koncord Partners as part of the Services as provided to you by Koncord Partners (referred to as the “Software” below). This license is for the sole purpose of enabling you to use and enjoy the benefit of the Services as provided by Koncord Partner, in the manner permitted by the Terms.
10.2 You may not (and you may not permit anyone else to) copy, modify, create a derivative work of, reverse engineer, decompile or otherwise attempt to extract the source code of the Software or any part thereof, unless this is expressly permitted or required by law, or unless you have been specifically told that you may do so by Koncord Partner, in writing.
10.3 Unless Koncord Partners has given you specific written permission to do so, you may not assign (or grant a sub-license of) your rights to use the Software, grant a security interest in or over your rights to use the Software, or otherwise transfer any part of your rights to use the Software.
11. Content license from you
11.1 You retain copyright and any other rights you already hold in Content which you submit, post or display on or through, the Services. By submitting, posting or displaying the content you give Koncord Partners a perpetual, irrevocable, worldwide, royalty-free, and non-exclusive license to reproduce, adapt, modify, translate, publish, publicly perform, publicly display and distribute any Content which you submit, post or display on or through, the Services. This license is for the sole purpose of enabling Koncord Partners to display, distribute and promote the Services and may be revoked for certain Services as defined in the Additional Terms of those Services.
11.2 You agree that this license includes a right for Koncord Partners to make such Content available to other companies, organizations or individuals with whom Koncord Partners has relationships for the provision of syndicated services, and to use such Content in connection with the provision of those services.
11.3 You understand that Koncord Partner, in performing the required technical steps to provide the Services to our users, may (a) transmit or distribute your Content over various public networks and in various media; and (b) make such changes to your Content as are necessary to conform and adapt that Content to the technical requirements of connecting networks, devices, services or media. You agree that this license shall permit Koncord Partners to take these actions.
11.4 You confirm and warrant to Koncord Partners that you have all the rights, power and authority necessary to grant the above license.
12. Software updates
12.1 The Software which you use may automatically download and install updates from time to time from Koncord Partners. These updates are designed to improve, enhance and further develop the Services and may take the form of bug fixes, enhanced functions, new software modules and completely new versions. You agree to receive such updates (and permit Koncord Partners to deliver these to you) as part of your use of the Services.
13. Ending your relationship with Koncord Partners
13.1 The Terms will continue to apply until terminated by either you or Koncord Partners as set out below.
13.2 If you want to terminate your legal agreement with Koncord Partner, you may do so by (a) notifying Koncord Partners at any time and (b) closing your accounts for all of the Services which you use, where Koncord Partners has made this option available to you. Your notice should be sent, in writing, to Koncord Partners' address which is set out at the beginning of these Terms.
13.3 Koncord Partners may at any time, terminate its legal agreement with you if:
(A) You have breached any provision of the Terms (or have acted in manner which clearly shows that you do not intend to, or are unable to comply with the provisions of the Terms); or
(B) Koncord Partners is required to do so by law (for example, where the provision of the Services to you is, or becomes, unlawful); or
(C) the partner with whom Koncord Partners offered the Services to you has terminated its relationship with Koncord Partners or ceased to offer the Services to you; or
(D) Koncord Partners is transitioning to no longer providing the Services to users in the country in which you are resident or from which you use the service; or
(E) The provision of the Services to you by Koncord Partners is, in Koncord Partners' opinion, no longer commercially viable.
13.4 Nothing in this Section shall affect Koncord Partners' rights regarding provision of Services under Section 4 of the Terms.
13.5 When these Terms come to an end, all of the legal rights, obligations and liabilities that you and Koncord Partners have benefited from, been subject to (or which have accrued over time whilst the Terms have been in force) or which are expressed to continue indefinitely, shall be unaffected by this cessation, and the provisions of paragraph 20.7 shall continue to apply to such rights, obligations and liabilities indefinitely.
14. EXCLUSION OF WARRANTIES
14.1 NOTHING IN THESE TERMS, INCLUDING SECTIONS 14 AND 15, SHALL EXCLUDE OR LIMIT Koncord Partners' WARRANTY OR LIABILITY FOR LOSSES WHICH MAY NOT BE LAWFULLY EXCLUDED OR LIMITED BY APPLICABLE LAW. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF CERTAIN WARRANTIES OR CONDITIONS OR THE LIMITATION OR EXCLUSION OF LIABILITY FOR LOSS OR DAMAGE CAUSED BY NEGLIGENCE, BREACH OF CONTRACT OR BREACH OF IMPLIED TERMS, OR INCIDENTAL OR CONSEQUENTIAL DAMAGES. ACCORDINGLY, ONLY THE LIMITATIONS WHICH ARE LAWFUL IN YOUR JURISDICTION WILL APPLY TO YOU AND OUR LIABILITY WILL BE LIMITED TO THE MAXIMUM EXTENT PERMITTED BY LAW.
14.2 YOU EXPRESSLY UNDERSTAND AND AGREE THAT YOUR USE OF THE SERVICES IS AT YOUR SOLE RISK AND THAT THE SERVICES ARE PROVIDED "AS IS" AND “AS AVAILABLE.”
14.3 IN PARTICULAR, Koncord Partner, ITS SUBSIDIARIES AND AFFILIATES, AND ITS LICENSORS DO NOT REPRESENT OR WARRANT TO YOU THAT:
(A) YOUR USE OF THE SERVICES WILL MEET YOUR REQUIREMENTS,
(B) YOUR USE OF THE SERVICES WILL BE UNINTERRUPTED, TIMELY, SECURE OR FREE FROM ERROR,
(C) ANY INFORMATION OBTAINED BY YOU AS A RESULT OF YOUR USE OF THE SERVICES WILL BE ACCURATE OR RELIABLE, AND
(D) THAT DEFECTS IN THE OPERATION OR FUNCTIONALITY OF ANY SOFTWARE PROVIDED TO YOU AS PART OF THE SERVICES WILL BE CORRECTED.
14.4 ANY MATERIAL DOWNLOADED OR OTHERWISE OBTAINED THROUGH THE USE OF THE SERVICES IS DONE AT YOUR OWN DISCRETION AND RISK AND THAT YOU WILL BE SOLELY RESPONSIBLE FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR OTHER DEVICE OR LOSS OF DATA THAT RESULTS FROM THE DOWNLOAD OF ANY SUCH MATERIAL.
14.5 NO ADVICE OR INFORMATION, WHETHER ORAL OR WRITTEN, OBTAINED BY YOU FROM Koncord Partners OR THROUGH OR FROM THE SERVICES SHALL CREATE ANY WARRANTY NOT EXPRESSLY STATED IN THE TERMS.
14.6 Koncord Partners FURTHER EXPRESSLY DISCLAIMS ALL WARRANTIES AND CONDITIONS OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
15. LIMITATION OF LIABILITY
15.1 SUBJECT TO OVERALL PROVISION IN PARAGRAPH 14.1 ABOVE, YOU EXPRESSLY UNDERSTAND AND AGREE THAT Koncord Partners AND ITS SUBSIDIARIES, AFFILIATES, OFFICERS, EMPLOYEES, AGENTS, CO-BRANDERS, PARTNERS AND LICENSORS SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL, OR EXEMPLARY DAMAGES, INCLUDING BUT NOT LIMITED TO, DAMAGES FOR LOSS OF PROFITS, GOODWILL, USE, DATA, OR OTHER INTANGIBLE LOSSES (EVEN IF YAHOO HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES), RESULTING FROM: (i) THE USE OR THE INABILITY TO USE THE SERVICE; (ii) THE COST OF PROCUREMENT OF SUBSTITUTE GOODS AND SERVICES RESULTING FROM ANY GOODS, DATA, INFORMATION, OR SERVICES PURCHASED OR OBTAINED OR MESSAGES RECEIVED OR TRANSACTIONS ENTERED INTO THROUGH OR FROM THE SERVICE; (iii) UNAUTHORIZED ACCESS TO OR ALTERATION OF YOUR TRANSMISSIONS OR DATA; (iv) STATEMENTS OR CONDUCT OF ANY THIRD PARTY ON THE SERVICE; OR (v) ANY OTHER MATTER RELATING TO THE SERVICE:
(A) ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL CONSEQUENTIAL OR EXEMPLARY DAMAGES WHICH MAY BE INCURRED BY YOU, HOWEVER CAUSED AND UNDER ANY THEORY OF LIABILITY. THIS SHALL INCLUDE, BUT NOT BE LIMITED TO, ANY LOSS OF PROFIT (WHETHER INCURRED DIRECTLY OR INDIRECTLY), ANY LOSS OF GOODWILL OR BUSINESS REPUTATION, ANY LOSS OF DATA SUFFERED, COST OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR OTHER INTANGIBLE LOSS;
(B) ANY LOSS OR DAMAGE WHICH MAY BE INCURRED BY YOU, INCLUDING BUT NOT LIMITED TO LOSS OR DAMAGE AS A RESULT OF:
(I) ANY RELIANCE PLACED BY YOU ON THE COMPLETENESS, ACCURACY OR EXISTENCE OF ANY ADVERTISING, OR AS A RESULT OF ANY RELATIONSHIP OR TRANSACTION BETWEEN YOU AND ANY ADVERTISER OR SPONSOR WHOSE ADVERTISING APPEARS ON THE SERVICES;
(II) ANY CHANGES WHICH Koncord Partners MAY MAKE TO THE SERVICES, OR FOR ANY PERMANENT OR TEMPORARY CESSATION IN THE PROVISION OF THE SERVICES (OR ANY FEATURES WITHIN THE SERVICES);
(III) THE DELETION OF, CORRUPTION OF, OR FAILURE TO STORE, ANY CONTENT AND OTHER COMMUNICATIONS DATA MAINTAINED OR TRANSMITTED BY OR THROUGH YOUR USE OF THE SERVICES;
(III) YOUR FAILURE TO PROVIDE Koncord Partners WITH ACCURATE ACCOUNT INFORMATION;
(IV) YOUR FAILURE TO KEEP YOUR PASSWORD OR ACCOUNT DETAILS SECURE AND CONFIDENTIAL;
(C) YOUR USE OF THE SERVICE IS AT YOUR SOLE RISK. THE SERVICE IS PROVIDED ON AN "AS IS" AND "AS AVAILABLE" BASIS. Koncord Partners AND ITS SUBSIDIARIES, AFFILIATES, OFFICERS, EMPLOYEES, AGENTS, CO-BRANDERS, PARTNERS AND LICENSORS EXPRESSLY DISCLAIMS ALL WARRANTIES, REPRESENTATIONS AND CONDITIONS OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES, REPRESENTATIONS AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
(D) Koncord Partners AND ITS SUBSIDIARIES, AFFILIATES, OFFICERS, EMPLOYEES, AGENTS, CO-BRANDERS, PARTNERS AND LICENSORS MAKES NO WARRANTY THAT (i) THE SERVICE WILL MEET YOUR REQUIREMENTS, (ii) THE SERVICE WILL BE UNINTERRUPTED, TIMELY, SECURE, OR ERROR-FREE, (iii) THE RESULTS THAT MAY BE OBTAINED FROM THE USE OF THE SERVICE WILL BE ACCURATE OR RELIABLE, (iv) THE QUALITY OF ANY PRODUCTS, SERVICES, INFORMATION, OR OTHER MATERIAL PURCHASED OR OBTAINED BY YOU THROUGH THE SERVICE WILL MEET YOUR EXPECTATIONS, AND (V) ANY ERRORS IN THE SOFTWARE WILL BE CORRECTED.
(E) ANY MATERIAL DOWNLOADED OR OTHERWISE OBTAINED THROUGH THE USE OF THE SERVICE IS DONE AT YOUR OWN DISCRETION AND RISK AND THAT YOU WILL BE SOLELY RESPONSIBLE FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR LOSS OF DATA THAT RESULTS FROM THE DOWNLOAD OF ANY SUCH MATERIAL.
(F) NO ADVICE OR INFORMATION, WHETHER ORAL OR WRITTEN, OBTAINED BY YOU FROM Koncord Partners OR THROUGH OR FROM THE SERVICE SHALL CREATE ANY WARRANTY NOT EXPRESSLY STATED IN THE TOS.
15.2 THE LIMITATIONS ON Koncord Partners' LIABILITY TO YOU IN PARAGRAPH 15.1 ABOVE SHALL APPLY WHETHER OR NOT Koncord Partners HAS BEEN ADVISED OF OR SHOULD HAVE BEEN AWARE OF THE POSSIBILITY OF ANY SUCH LOSSES ARISING.
16. Copyright and trade mark policies
16.1 It is Koncord Partners' policy to respond to notices of alleged copyright infringement that comply with applicable international intellectual property law (including, in the United States, the Digital Millennium Copyright Act) and to terminating the accounts of repeat infringers.
16.2 Your accept Koncord Partners is trade mark of Koncord Partners Ltd.
17. Advertisements
17.1 Some of the Services are supported by advertising revenue and may display advertisements and promotions. These advertisements may be targeted to the content of information stored on the Services, queries made through the Services or other information.
17.2 The manner, mode and extent of advertising by Koncord Partners on the Services are subject to change without specific notice to you.
17.3 In consideration for Koncord Partners granting you access to and use of the Services, you agree that Koncord Partners may place such advertising on the Services.
18. Other content
18.1 The Services may include hyperlinks to other web sites or content or resources. Koncord Partners may have no control over any web sites or resources which are provided by companies or persons other than Koncord Partners.
18.2 You acknowledge and agree that Koncord Partners is not responsible for the availability of any such external sites or resources, and does not endorse any advertising, products or other materials on or available from such web sites or resources.
18.3 You acknowledge and agree that Koncord Partners is not liable for any loss or damage which may be incurred by you as a result of the availability of those external sites or resources, or as a result of any reliance placed by you on the completeness, accuracy or existence of any advertising, products or other materials on, or available from, such web sites or resources.
19. Changes to the Terms
19.1 Koncord Partners may make changes to the Universal Terms or Additional Terms from time to time. When these changes are made, Koncord Partners will make a new copy of the Universal Terms available at this web page and any new Additional Terms will be made available to you from within, or through, the affected Services.
19.2 You understand and agree that if you use the Services after the date on which the Universal Terms or Additional Terms have changed, Koncord Partners will treat your use as acceptance of the updated Universal Terms or Additional Terms.
20. General legal terms
20.1 Sometimes when you use the Services, you may (as a result of, or through your use of the Services) use a service or download a piece of software, or purchase goods, which are provided by another person or company. Your use of these other services, software or goods may be subject to separate terms between you and the company or person concerned. If so, the Terms do not affect your legal relationship with these other companies or individuals.
20.2 The Terms constitute the whole legal agreement between you and Koncord Partners and govern your use of the Services (but excluding any services which Koncord Partners may provide to you under a separate written agreement), and completely replace any prior agreements between you and Koncord Partners in relation to the Services.
20.3 You agree that Koncord Partners may provide you with notices, including those regarding changes to the Terms, by email, regular mail, or postings on the Services.
20.4 You agree that if Koncord Partners does not exercise or enforce any legal right or remedy which is contained in the Terms (or which Koncord Partners has the benefit of under any applicable law), this will not be taken to be a formal waiver of Koncord Partners' rights and that those rights or remedies will still be available to Koncord Partners.
20.5 If any court of law, having the jurisdiction to decide on this matter, rules that any provision of these Terms is invalid, then that provision will be removed from the Terms without affecting the rest of the Terms. The remaining provisions of the Terms will continue to be valid and enforceable.
20.6 You acknowledge and agree that each member of the group of companies of which Koncord Partners is the parent shall be third party beneficiaries to the Terms and that such other companies shall be entitled to directly enforce, and rely upon, any provision of the Terms which confers a benefit on (or rights in favor of) them. Other than this, no other person or company shall be third party beneficiaries to the Terms.
20.7 The Terms, and your relationship with Koncord Partners under the Terms, shall be governed by the laws of the State of California without regard to its conflict of laws provisions. You and Koncord Partners agree to submit to the exclusive jurisdiction of the courts located within the county of Santa Clara, California to resolve any legal matter arising from the Terms. Notwithstanding this, you agree that Koncord Partners shall still be allowed to apply for injunctive remedies (or an equivalent type of urgent legal relief) in any jurisdiction.
21 By submitting ideas, suggestions, documents, and/or proposals ("Contributions") to Koncord Partners through its suggestion or feedback web pages, you acknowledge and agree that: (a) your Contributions do not contain confidential or proprietary information; (b) Koncord Partners is not under any obligation of confidentiality, express or implied, with respect to the Contributions; (c) Koncord Partners shall be entitled to use or disclose (or choose not to use or disclose) such Contributions for any purpose, in any way, in any media worldwide; (d) Koncord Partners may have something similar to the Contributions already under consideration or in development; (e) your Contributions automatically become the property of Koncord Partners without any obligation of Koncord Partners to you; and (f) you are not entitled to any compensation or reimbursement of any kind from Koncord Partners under any circumstances.
22 Indemnities
22.1 You agree to indemnify and hold Koncord Partners and its subsidiaries, affiliates, officers, employees, agents, co-branders, partners and licensors harmless from any claim or demand, including reasonable legal fees, made by any third party due to or arising out of Content you submit, post, transmit or make available through the Service, your use of the Service, your connection to the Service, your violation of the TOS, or your violation of any rights of another.
23 No resale of service
23.1 You agree not to reproduce, duplicate, copy, sell, trade, or exploit for any commercial purposes, any portion of the Service (including the Koncord Partners I.D. associated with your account), use of the Service, or access to the Service.
24 General practices regarding use and storage
24.1 You acknowledge that Koncord Partners may establish general practices and limits concerning use of the Service, including without limitation the maximum number of days that email messages, message board postings or other uploaded Content will be retained by the Service, the maximum number of email messages that may be sent from or received by an account on the Service, the maximum size of any email message that may be sent from or received by an account on the Service, the maximum disk space that will be allotted on Koncord Partners' servers on your behalf, and the maximum number of times (and the maximum duration for which) you may access the Service in a given period of time. You agree that Koncord Partners has no responsibility or liability for the deletion or failure to store any messages and other communications or other Content maintained or transmitted by the Service. You acknowledge that Koncord Partners reserves the right to log off accounts that are inactive for a certain period of time as determined by Koncord Partners. You further acknowledge that Koncord Partners reserves the right to change these general practices and limits at any time, in its sole discretion, with or without notice.
25 Modifications to Service
25.1 Koncord Partners reserves the right at any time to modify or discontinue, temporarily or permanently, the Service (or any part thereof) with or without notice. You agree that Koncord Partners will not be liable to you or to any third party for any modification, suspension or discontinuance of the Service.
26 Special clauses for services relating to financial matters
26.1 If you intend to create or join any service, receive or request any news, messages, alerts, or other information from the Service concerning companies, stock quotes, investments or securities, please read the above Sections 18 and 19 again. They go doubly for you. In addition, for this type of information particularly, the phrase "Let the investor beware" is apt. The Service is provided for informational purposes only, and no Content included in the Service is intended for trading or investing purposes. Koncord Partners and its licensors are not responsible or liable for the accuracy, usefulness or availability of any information transmitted or made available via the Service, and are not responsible or liable for any trading or investment decisions made based on such information.
27 No third party beneficiaries
27.1 You agree that, except as otherwise expressly provided in this TOS, there shall be no third party beneficiaries to this Agreement.
28 Notices
28.1 Notices to you may be made via either email or regular mail. The Service may also provide notices of changes to the TOS or other matters by displaying notices or links to notices to you on the Service.
28.2 From time to time Koncord Partners will send you notices. Such messages may not be received if you violate this TOS by accessing the Service in an unauthorized manner. Your agreement to this TOS constitutes your agreement that you are deemed to have received any and all notices that would have been delivered had you accessed the Service in an authorized manner.
2010 June 24

Turning Bulk Addresses Into Geodata

Website http://www.gpsvisualizer.com/geocoder/ provides a free service for this. After that, you may wish either use its XML file or use Koncord Applied Excel Functions to parse the text.

VBA .SendMail to Multiple Recipients

If one does not want to use CDO to send email, following is the way to send a single email to multiple recipients. However, it appears there is no way to send cc or bcc through .SendMail in VBA.

.SendMail Array("person1@sample.com", "p2@sample.com"), _
"This is the Subject line"

Or

.SendMail Array("person1@sample.com", "p2@sample.com"), _
Subject:="This is the Subject line"

This is particularly useful with work together with ActiveWorkbook in Ms Excel.

For more information, please see:

Ron de Bruin's http://www.rondebruin.nl/mail/tips1.htm

Get Latitude and Longitude Values from Google Maps

Following link provides an easy way to get latitude and longitude values from Google Maps:

http://www.tech-recipes.com/rx/2403/google_maps_get_latitude_longitude_values/

The contributor is qmchenry. Basically, copy following JavaScript into address bar of the browser, geodata of then center will be shown:

javascript:void(prompt('',gApplication.getMap().getCenter()));

The other ways include enabling LatLng Tooltip in Google Maps:

http://www.tech-recipes.com/rx/5519/the-easy-way-to-find-latitude-and-longitude-values-in-google-maps/

Summation of Hour Numbers in T-SQL

This blog article is nothing but to record a standard script how to calculate the summation of hour numbers in report, for purpose not to think again in future.

Hour number need to be accumulated in minutes before present the final result. Else, it might be not accurate enough.

In inner query:

, SUM(DATEDIFF(MI, Departure, Arrival)) AS Mins

Note: DATEDIFF to work out every leg/trip's minutes. SUM() is to work out summation in this category togethere with GROUP BY.

In presentation outer query:

, SUM(CASE WHEN ... Mins ... END)/60 AS ...

Note: SUM() together with CASE statment is to format the presentation of the report.

In case wanting to keep decimal places, use:

, SUM(CASE WHEN ... Mins ... END)/60.0 AS ...
or
, SUM(CASE WHEN ... Mins ... END)/60.00 AS ...

For more about decimal place, please refer to http://koncordpartners.blogspot.com/2010/09/decimal-place-in-t-sql.html.

HTML Shows Nothing While Nothing Is Shown on Error Console

The most possible reason is either HTML or JavaScript codes are not clean. It often happens when you use Notepad to write codes. Another possibility is your JavaScript file is not accessible.

Labels