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
 move record
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

eirikr_1
Starting Member

26 Posts

Posted - 02/10/2013 :  01:38:26  Show Profile  Reply with Quote
Master table
ComputerName. AuditId. AuditDate.
A. 111. 1/1/13
A. 222. 2/1/13
A. 000. 2/1/13

B. 111. 1/1/13

C. 000. 1/1/13
C. 111. 2/1/13
AuditId equals to zero telling no vulnerability found on that day scan.
I need to write a query to move computer A to different table because there is no vulnerable auditId found after the 2/1/13. Computer C won't be moved because there is another vulnerability in the next day. Please help. Thank you

James K
Flowing Fount of Yak Knowledge

3559 Posts

Posted - 02/10/2013 :  06:27:41  Show Profile  Reply with Quote
Do you want to move all records for A (the 3 records in this example), or just the one's where there were no vulnerability scans? Also, do you want to move the 1/1/13 record for C?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 02/11/2013 :  00:52:31  Show Profile  Reply with Quote

INSERT INTO TableB (ComputerName, othercolumns...)
SELECT ComputerName,othercolumns...
FROM
(
SELECT MAX(CASE WHEN AuditId='000.' THEN AuditDate END) OVER (PARTITION BY ComputerName) AS ZeroDate,
MAX(AuditDate) OVER (PARTITION BY ComputerName) AS MaxDate,
*
FROM Table
)t
WHERE MaxDate = ZeroDate


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

Go to Top of Page

eirikr_1
Starting Member

26 Posts

Posted - 02/11/2013 :  00:56:56  Show Profile  Reply with Quote
Hello James
Since there is no vulnerability found after 2/1/13. I want to move all As to a historical table.
With computer C, Although I found no Vulnerability on 1/1/13, however the scan shows another
Vulnerability found on 2/1/13. So I don’t move the computer C record.
Thank you for help
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 02/11/2013 :  01:00:26  Show Profile  Reply with Quote
quote:
Originally posted by eirikr_1

Hello James
Since there is no vulnerability found after 2/1/13. I want to move all As to a historical table.
With computer C, Although I found no Vulnerability on 1/1/13, however the scan shows another
Vulnerability found on 2/1/13. So I don’t move the computer C record.
Thank you for help



You missed the point
he was asking whether you need to move all records related to Computer A or just the record with no vulnerability (ie latest alone)

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

Go to Top of Page

eirikr_1
Starting Member

26 Posts

Posted - 02/11/2013 :  01:17:05  Show Profile  Reply with Quote
All three records related to A will be moved.
Assuming on 2/2/13 scan show another vulnerability found with auditId 1234, then all 4 records related to A wont be moved. It means this computer need to be patched. Thank you with respecful
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 02/11/2013 :  01:25:02  Show Profile  Reply with Quote
quote:
Originally posted by eirikr_1

All three records related to A will be moved.
Assuming on 2/2/13 scan show another vulnerability found with auditId 1234, then all 4 records related to A wont be moved. It means this computer need to be patched. Thank you with respecful



ok...then use my suggestion posted earlier

------------------------------------------------------------------------------------------------------
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.06 seconds. Powered By: Snitz Forums 2000