May 23, 2012, 09:52:30 AM
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News
: Mobile users - Our forum is Tapatalk enabled.
http://www.tapatalk.com/
Home
Help
Search
Login
Register
DotDragnet
>
The Tech Side
>
Tech stuff
>
Another SQL question
Pages: [
1
]
Go Down
« previous
next »
Print
Author
Topic: Another SQL question (Read 1159 times)
Charisma Bypass
Hero Member
Posts: 556
Another SQL question
«
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 = 20
09
-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
Re: Another SQL question
«
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
Lighting
Jeep Stone
Hero Member
Posts: 908
Re: Another SQL question
«
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
Jeepstone
JasonD
Global Moderator
Hero Member
Posts: 547
Re: Another SQL question
«
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
Re: Another SQL question
«
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
« previous
next »
Jump to:
Please select a destination:
-----------------------------
General Category
-----------------------------
=> General Discussion
=> Jee's Forum of Appalling Jokes
-----------------------------
The Creative Side
-----------------------------
=> Arty stuff
=> Photography
=> On the web
-----------------------------
The Tech Side
-----------------------------
=> Tech stuff
=> Hardware & Software
-----------------------------
The Business Side
-----------------------------
=> Anything business related
-----------------------------
The Practical Side
-----------------------------
=> Practical Advice
DotDragnet
>
The Tech Side
>
Tech stuff
>
Another SQL question
Loading...