Solved

transferring old records to new table, but calculating (incrementing) lead ordinals per lead id

Posted on 2012-03-27
2
307 Views
Last Modified: 2012-03-27
hi.
i am not sure if this can be done through a single mysql query, but it was attempted as follows:
// update test transactions table
$sql10 = "INSERT INTO 
			dwtphovu_8347379386_test.8_transactions 
			(
				bigint_TransactionID,
				text_TransactionEvent,
				bigint_SupplierID,
				bigint_LeadID,
				bigint_TransactionAmount,
				bigint_TransactionBalance,
				timestamp_TransactionEvent,
				smallint_LeadOrdinal
			) 
		SELECT 
			PTR.bigint_TransactionID,
			PTR.text_TransactionEvent,
			PTR.bigint_SupplierID,
			PTR.bigint_LeadID,
			PTR.bigint_TransactionAmount,
			PTR.bigint_TransactionBalance,
			PTR.timestamp_TransactionEvent, 
			#insert integers counting from 0 here, per lead id.
		FROM 
			dwtphovu_8347379386_prod.8_transactions PTR;";
$result10 = mysql_query_errors($sql10, $conn , __FILE__ , __LINE__ , true );

Open in new window

if this can be done only via php/mysql combined - how would this be achieved?
0
Comment
Question by:intellisource
  • 2
2 Comments
 

Accepted Solution

by:
intellisource earned 0 total points
ID: 37772343
i'm wondering now, wether it would help to select a count with the insert of each record from the old table - for example:
// update test transactions table
$sql10 = "INSERT INTO 
			dwtphovu_8347379386_test.8_transactions 
			(
				bigint_TransactionID,
				text_TransactionEvent,
				bigint_SupplierID,
				bigint_LeadID,
				bigint_TransactionAmount,
				bigint_TransactionBalance,
				timestamp_TransactionEvent,
				smallint_LeadOrdinal
			) 
		SELECT 
			PTR.bigint_TransactionID,
			PTR.text_TransactionEvent,
			PTR.bigint_SupplierID,
			PTR.bigint_LeadID,
			PTR.bigint_TransactionAmount,
			PTR.bigint_TransactionBalance,
			PTR.timestamp_TransactionEvent, 
			(
				SELECT 
					COUNT(TT.smallint_LeadOrdinal) AS smallint_LeadOrdinal
				FROM 
					dwtphovu_8347379386_test.8_transactions TT 
				WHERE 
					TT.bigint_LeadID = PTR.bigint_LeadID
			)
		FROM 
			dwtphovu_8347379386_prod.8_transactions PTR;";
$result10 = mysql_query_errors($sql10, $conn , __FILE__ , __LINE__ , true );

Open in new window

0
 

Author Closing Comment

by:intellisource
ID: 37772939
and it seems to work beautifully ;)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now