Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 split a table
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

eirikr_1
Starting Member

27 Posts

Posted - 02/07/2013 :  12:20:57  Show Profile  Reply with Quote
I need some help with a query to split a table
master table
Id ComputerName Ip Vuln ScanDate
1 computerA 1.1.1 iav1 1/1/13
2 computerA 1.1.1 iav2 1/1/13
3 computerB 2.2.2 iav3 2/1/13

into to
computerInfo table
Id ComputerName Ip
1 computerA 1.1.1
2 computerB 2.2.2

vulnerabilities table
Id ComputerId Vuln ScanDate
1 1 iav1 1/1/13
2 1 iav2 1/1/13
3 2 iav3 2/1/13

thank you

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 02/07/2013 :  16:43:03  Show Profile  Reply with Quote
-- first table
SELECT DISTINCT IDENTITY(INT,1,1) as ID, ComputerName INTO ComputerInfoTable FROM MasterTable;

-- second table
SELECT 
	a.Id,b.Id AS ComputerId,a.Vuln,a.ScanDate
INTO VulnerabilitiesTable
FROM 
	MasterTable a
	INNER JOIN ComputerInfoTable b ON a.ComputerName = b.computername;
Go to Top of Page

eirikr_1
Starting Member

27 Posts

Posted - 02/10/2013 :  01:21:34  Show Profile  Reply with Quote
Thank you James
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 02/10/2013 :  06:40:01  Show Profile  Reply with Quote
You are very welcome - glad to help.
Go to Top of Page
  Previous Topic Topic Next 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.03 seconds. Powered By: Snitz Forums 2000