Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
hkben
Starting Member
4 Posts |
Posted - 2007-08-20 : 02:15:49
|
I have extracted the data from Point of Sales. it has two columns one for date and one for time in the database.I need to combine both column into single column with the format "mm/dd/yyyy hh:mm:ss" before i import the data into the SQL server for my BI project.Example: Data extract from Point of SalesFDATE FTIME20060114 06361620060115 07074320060116 071020How can i combine those two when i import into SQL server like below:FDATE01/14/2006 06:36:1601/15/2006 07:07:4301/16/2006 07:10:20million thanks. |
|
hkben
Starting Member
4 Posts |
Posted - 2007-08-20 : 04:15:22
|
By using the below function, i got what i wanted.But....this is what i am doing now....1.Export the data from POS 2.Import into SQL server (Create Table, Insert Into ..etc..)INSERT INTO payment values ('20070701', '064640');INSERT INTO payment values ('20070701', '065700');3.Update & combine Date and Time together. (update about 50,000+ records all the time, when i import new data.)How can i modifty the exported data before import into the payment table. So that SQL server knows is datetime format??CREATE FUNCTION fnCombineDateTime (@Date char(8), @Time char(6))RETURNS datetimeASBEGINDECLARE @DateTime datetimeSELECT @DateTime=CONVERT(datetime, @Date + ' ' + STUFF(STUFF(@Time, 3, 0, ':'), 6, 0, ':')) RETURN @DateTimeEND"Update Payment Table Column FDate+FTime with function fnCombineDateTime"update payment Set FDate = (select dbo.fnCombineDateTime(FDate, FTime)) |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-08-20 : 04:20:05
|
You can do it without calling a function alsoupdate payment Set FDatetime =CONVERT(datetime, FDate + ' ' + STUFF(STUFF(FTime, 3, 0, ':'), 6, 0, ':')) MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|