Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax question for INSERT statement

Status
Not open for further replies.

ddub

MIS
Joined
Jul 9, 2002
Messages
17
Location
US
Hi,

What would the proper syntax be if I wanted to replace 'smith' with the current user name in the following INSERT statement?

INSERT INTO smith.tblTemp
SELECT * FROM tblSource

This statement is part of my stored procedure that allows whoever's executing it to create a table and then insert values into it.
 
Declare @User Varchar(20)
Declare @sql varchar (200)

set @sql = 'INSERT INTO '+@Usewr+'.tblTemp SELECT * FROM tblSource'

exec (@0sql)
AL Almeida
NT/DB Admin
"May all those that come behind us, find us faithfull"
 
Just do an insert using the table name only. If you leave off the owner, the user name will be assumed.

INSERT INTO tblTemp
SELECT * FROM tblSource
Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Thanks for both tips, aalmeida and tlbroadbent. The syntax from aalmeida worked for me. I had tried it the way tlbroadbent had suggested earlier, but it would not work. Maybe this was because I gave the users only the db_ddladmin role and not db_datawriter also.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top