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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help On Stored Procedure 2

Status
Not open for further replies.

JeffSabat

Programmer
Sep 15, 2003
32
0
0
PH
Why is this not possible?

CREATE PROCEDURE [uspInsertNotes]
@OwnerID varchar(50),
@Subject varchar(50),
@Notes ntext(16),
@DateCreated varchar(50),
@CreatedBy varchar(50),
@tableName as nvarchar(256)
AS
INSERT INTO @tableName
(OwnerId,Subject,Notes, DateCreated, CreatedBy)
VALUES
(@OwnerID, @Subject, @Notes, @DateCreated, @CreatedBy)

Is there a solution to this problem or it is really neccessary to name the table in this code...

Also, is it possible i will pass an array of data to a parameter like for example, multiple subject, multiple notes?
Pls help....
tnxs a lot..
 
For thge array pass a csv string and parse it in the SP or pass a temp table.

As for the table name variable look at dynamic sql

declare @sql varchar(8000)

select @sql = 'insert ' + @tblname + '(col1, col2) ''myval1'',''myval2'''
exec (@sql)

look at sp_executesql for using parameters on a dynamic sql statement.

======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
You can use dynamic SQL to enter the table name and execute the insert. I believe that this FAQ (faq183-761) explains how this is done.

--Rob
 
thank you very much for the help..
i'm just so happy..
again, thank you...
jeffrey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top