Solved

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

Posted on 2012-03-27
2
306 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
Comment Utility
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
Comment Utility
and it seems to work beautifully ;)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Creating and Managing Databases with phpMyAdmin in cPanel.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 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

7 Experts available now in Live!

Get 1:1 Help Now