Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 22nd, 2004, 09:02 PM
haffej haffej is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 87 haffej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
transferring datetime data between databases

i'm trying to transfer existing tables to a new database. the tables i'm transferring from/to don't have the same structure/field names (trying to improve what i already have), so what i'm doing is opening a connection to both databases, getting a recordset from one, creating a sql string to execute, and executing that on the new database for each record. my problem is with the datetime field. in both tables it's labelled as "DBTimeStamp" (i created it as datetime), but when i try to copy it into the new database, i get the error "The name 'Fri' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted." of course, when i put single quotes like it's a string, i get the "date cannot be converted from string" error... how can this be done? what do i need to do to the existing datetime to make it suitable for inserting into the new database??

Reply With Quote
  #2  
Old January 23rd, 2004, 12:04 AM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 6
Are you trying to copy a string (date) into a datetime field? If so, make sure that the string value you are trying to copy over is acceptable in a datetime field. Also, SQL Server has an easy to use export feature. Right click on the database, select Export Data and continue with the wizard. This way, you don't have to do all of this programmatically. Hope this helps.

Reply With Quote
  #3  
Old January 23rd, 2004, 08:48 AM
haffej haffej is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 87 haffej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
is there any way to NOT retrieve the date as a string? i tried both of these:

user_regDate = RS("user_regDate").value;

user_regDate = RS("user_regDate");

and for both, the insert complains that it's a string...

might it be a better idea to transfer directly from one recordset to another, rather than assembling an insert string? ie:

RS1 is the recordset retrieved from the old db
RS2 is an empty recordset from the new db

RS2.Open(/*connect to users table*/);
RS2.AddNew();
RS2("user_regDate") = RS1("user_regDate");
RS2.Update();

would that work?? (i'd try it right now but i have to get going to work!)

thanks, any help is appreciated.

Reply With Quote
  #4  
Old January 23rd, 2004, 10:15 AM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 6
Well, I suggest that u try SQL Server's export features so that you don't have to go through the trouble of doing this programmatically. Second, Send me a sample date string that you are trying to insert into the second recordset. (such as '10/10/2003 10:00:00AM")

Thanks

Reply With Quote
  #5  
Old January 23rd, 2004, 10:30 AM
haffej haffej is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 87 haffej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
here is the type of string i get when i try to run the code:

Fri Mar 21 23:15:38 PST 2003

(... and actually, that's supposed to be eastern time... i added 3 hours so that it would be stored as eastern time but i obviously overlooked that it still labels it as PST. a side question would be how can i fix that? my db is hosted in california, i'm in new york...)

how do i use the export function? in changing to new tables, i want some new field names and some additional fields, am i able to control that sort of thing in using the export function? or does it simply duplicate an entire table?

thanks

Reply With Quote
  #6  
Old January 23rd, 2004, 11:03 AM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 6
The problem is that a datetime field will not accept that value. It accepts values like '10/10/2004 3:04 pm'. If you really want to store that string as a datetime field, you are going to have to parse it into a valid datetime value.

Reply With Quote
  #7  
Old January 23rd, 2004, 05:02 PM
haffej haffej is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 87 haffej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
sweet, i got it. i had to take the string, split it, change the month to a number, add a leading zero to the day if necessary, and assemble the string as YYYYMMDD HH:MM:SS

thanks for your help!

i'm going to look into the export/import thing more, too.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > transferring datetime data between databases


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT