Results 1 to 5 of 5

Thread: Merging tables

  1. #1
    Join Date
    Apr 2004
    Posts
    21

    Merging tables

    Always please MS SQL only

    And thanks in advance for you wonderful people: We need to import a database, merging tables. The snag is that one of the databases has a column of dates in datetime format. The other database has a column of dates entered as nvarchar in the format of 20040319 to represent 3-19-2004.

    Is there a way to convert those nvarchar numbers to a format acceptable to Sequel's datetime column?

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    Yes.

    example:

    create table mydate(date nvarchar(10))

    create table yourdate(date datetime)
    insert into mydate select '20040329'
    insert into mydate select '20030329'
    insert into mydate select '20020227'
    insert into mydate select '20041224'
    insert into mydate select '20041201'

    insert into yourdate select convert(datetime,date,112) from mydate

    select * from yourdate

  3. #3
    Join Date
    Apr 2004
    Posts
    21

    Merging info

    Hi -- in your reply, can't get it to work. don't understand. I want to convert a column, not create a table. I cannot alter it and get it to work.

    Any help?

  4. #4
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    select convert(datetime,date,112) from mydate

    here date is the column name. I simulated your nVarchar COlumn table and a datetime column table in that example.

    You have to use "convert" function to change the format to datetime (SQL Server acceptable format)

  5. #5
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    or you can use SUBSTRING Function to add "-" in between the date values.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •