DotDragnet
May 23, 2012, 09:52:30 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Mobile users - Our forum is Tapatalk enabled. http://www.tapatalk.com/
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Another SQL question  (Read 1159 times)
Charisma Bypass
Hero Member
*****
Posts: 556



View Profile Awards
« on: May 14, 2009, 10:50:37 AM »

Right then ...

Customers table. 
Row is customers_number

Customers Info table
Pertinent rows are; customers_id and customers_info_date_account_created

What I have to do is:

get part of the customers_info_date_account_created and all of the customers_id and mix them up, then insert the result in the customers_number

Thus:

customers_id = 1441
customers_info_date_account_created = 2009-04-21 12:22:01

I need to get the parts in bold and insert them like this;

091441 into the customers_number (customers_info)

Any help would be very much appreciated.  Thank You in advance.
Logged
MattC
Hero Member
*****
Posts: 825



mattc_stfc
View Profile WWW Awards
« Reply #1 on: May 14, 2009, 12:07:21 PM »

I don't know the full solution but this might help

http://doc.ddart.net/mssql/sql70/da-db_8.htm
Logged

Jeep Stone
Hero Member
*****
Posts: 908



View Profile WWW Awards
« Reply #2 on: May 14, 2009, 01:22:30 PM »

You need to CONCATenate the customer_id with the YEAR() of customers_info_date_account_created, so something like this pseudo code:

INSERT INTO customersinfo (customers_numner) VALUES (SELECT CONCAT(YEAR(customers_info_date_account_created), customers_id))

Logged

JasonD
Global Moderator
Hero Member
*****
Posts: 547



View Profile Awards
« Reply #3 on: May 14, 2009, 02:24:11 PM »

You need DATE_FORMAT if you want a two digit year, and you probably want some zero padding to the customers_id, so

INSERT INTO customersinfo (customers_numner) VALUES (SELECT CONCAT(DATE_FORMAT(customers_info_date_account_created, '%y'), LPAD(customers_id, 4, '0')))

Replace 4 with however many digits the id can go up to.
Logged
Charisma Bypass
Hero Member
*****
Posts: 556



View Profile Awards
« Reply #4 on: May 14, 2009, 05:39:07 PM »

Thank you guys, you set me on the right track.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!