troubleshooting Question

Insert partial results into table.

Avatar of BobRosas
BobRosas asked on
Microsoft SQL Server 2008Microsoft SQL Server 2005
3 Comments1 Solution231 ViewsLast Modified:
The attached code below works but now I'd like to insert EmployeeID and RandomDateTime into a new table.  I want Dept, Firstname and Lastname to show when it's run but I don't need to save that to the new table.

I tried the following but I get the error...
    There is already an object named 'SOGItblRandom' in the database.
I want to be able to append the new results to the same table each time it's run.  How do I do that?
 
   ...
,CURRENT_TIMESTAMP As RandomDateTime
      INSERT INTO [TCP].[dbo].SOGItblRandom
FROM [TCP].[dbo].[EmployeeList]
   ...

SELECT TOP (SELECT cast(round(25 * COUNT(EmployeeID) * 1.0/ 100, 0) as integer)
	    FROM [TCP].[dbo].[EmployeeList]
	    WHERE Department = ('SR7012') AND [Suspend] <> 1
	   ) 
       [EmployeeId]
      ,[Department] 
      ,[FirstName]
      ,[LastName]
      ,CURRENT_TIMESTAMP As RandomDateTime
FROM [TCP].[dbo].[EmployeeList]
WHERE Department  = ('SR7012') AND [Suspend] <> 1
ORDER BY NEWID()
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros