SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Splitting a table into two tables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ebi007
Starting Member

15 Posts

Posted - 07/16/2012 :  03:42:14  Show Profile  Reply with Quote
i have a table with only the date column as primary key, i would like to
split that table into two tables with distinct records.

ex: table A
name birthdate
erica 2012-07-1987 12:24:45
ocean 2012-05-1990 07:20:00

table A1
name birthdate
erica 2012-07-1987 12:24:45
ocean 2012-05-1990 07:20:00


table A2
josé 2012-11-1982 12:00:35
jessica 2012-07-1987 05:11:45

thanks



---------------------------
there is no limits only God can stop me.

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 07/16/2012 :  04:01:56  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
How do you want to do the split (and why)?
You can start off with two views with queries to simulate the two tables.
Then maybe decide if you need to go any further.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

ebi007
Starting Member

15 Posts

Posted - 07/16/2012 :  04:14:54  Show Profile  Reply with Quote
the two tables will only be temp tables , will drop them afterwards.
in fact i want to get the other half part of the table A
i mean i need the 2 last records in another table.

---------------------------
there is no limits only God can stop me.
Go to Top of Page

lionofdezert
Aged Yak Warrior

Pakistan
864 Posts

Posted - 07/16/2012 :  04:33:43  Show Profile  Visit lionofdezert's Homepage  Send lionofdezert a Yahoo! Message  Reply with Quote
Use SELECT * INTO statement with your requried filter in WHERE clause. Then with same filter remove from first one.

SELECT * INTO NewTable FROM Old Table WHERE conditionhere

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

ebi007
Starting Member

15 Posts

Posted - 07/16/2012 :  06:13:24  Show Profile  Reply with Quote
[quote]Originally posted by lionofdezert

Use SELECT * INTO statement with your requried filter in WHERE clause. Then with same filter remove from first one.

SELECT * INTO NewTable FROM Old Table WHERE conditionhere

--------------------------
Can you use my previous example to write the query please ?

---------------------------
there is no limits only God can stop me.
Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 07/16/2012 :  06:40:00  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
select *
into TableA1
from TableA
where birthdate in ('2012-07-1987T12:24:45', '2012-05-1990T07:20:00')

select *
into TableA2
from TableA
where birthdate not in ('2012-07-1987T12:24:45', '2012-05-1990T07:20:00')

Back to my original question.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

ebi007
Starting Member

15 Posts

Posted - 07/16/2012 :  08:39:33  Show Profile  Reply with Quote
quote:
Originally posted by nigelrivett

select *
into TableA1
from TableA
where birthdate in ('2012-07-1987T12:24:45', '2012-05-1990T07:20:00')

select *
into TableA2
from TableA
where birthdate not in ('2012-07-1987T12:24:45', '2012-05-1990T07:20:00')

Back to my original question.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.



birthdate is in smalldatetime format not varchar.

---------------------------
there is no limits only God can stop me.
Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 07/16/2012 :  09:14:41  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
Shouldn't matter.
The problem is with your data
2012-07-1987 12:24:45
You don't have valid dates.

If you correct the values it should be ok.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47093 Posts

Posted - 07/16/2012 :  09:53:27  Show Profile  Reply with Quote
quote:
Originally posted by ebi007

quote:
Originally posted by nigelrivett

select *
into TableA1
from TableA
where birthdate in ('2012-07-1987T12:24:45', '2012-05-1990T07:20:00')

select *
into TableA2
from TableA
where birthdate not in ('2012-07-1987T12:24:45', '2012-05-1990T07:20:00')

Back to my original question.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.


why are date values like this? why is day portion four digits?
birthdate is in smalldatetime format not varchar.

---------------------------
there is no limits only God can stop me.



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000