Inserting query results into table

Hello! I'm drawing a big blank here! I've got a SELECT query whose results I need to be put into a table. The table already exists in the Database, but any records in it need to be deleted and then the results of the SELECT query should be inserted.

Here's the SELECT statement I'm using.

select student_ssn, last_name, first_name, value_09, value_15 from Pfaids2005.dbo.user_string as u

join pfaids2005.dbo.stu_award_year s on u.stu_award_year_token=s.stu_award_year_token
join PFaids2005.dbo.student st on u.student_token=st.student_token

where(((value_09='MPN' or value_09='PIF') and (value_15='P' or value_15='Y')))
and u.award_year_token='2014'

order by last_name, first_name

Here's what the query looks like:

I'd like those query results to be inserted into a table called "CustomData".

Any quidance is appreciated!

You can truncate the table first or use the DELETE command if there are foreign keys. Then use INSERT/SELECT to insert the data.

INSERT ...
YourQueryGoesHere

Tara,

I tried that first. Which usually works, but I'm getting a "Msg 213, Level 16, State 1, Line 3
Column name or number of supplied values does not match table definition." error.

Ok.. so I figured it out after I actually read the error message. LOL

1 Like