Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 insert stored procedure without autonumber with variables to table and fields

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2000-10-29 : 08:22:43
nuno writes "I've search your site (let me congratulate you for it)and i don ´t seem to find what i really need. I think that i am just not getting the right code.

I am new to sql so hope you can help me

I need something like this

in a stored procedure:
( with no automatic id )

create ...
(
@table CHAR
@id INT
@date smalldatetime
@name CHAR or NVarCHAR.......
...
)
AS

INSERT INTO @table (id,date,name) VALUES (@id,@date,@name)

----------------------------------------------------------

I know(think) i can do this
DECLARE @string varchar(250)

SELECT @string = "INSERT INTO " + @table + "(id) VALUES(@id)"
in this case i get an error of having to declare the variable

if i to this

DECLARE @string varchar(250)
DECLARE @id2 INT
SELECT @id2 = @id

SELECT @string = "INSERT INTO " + @table + "(id) VALUES(" & @id2 & ")"

i get this error

[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the nvarchar value 'INSERT INTO arte_cinema (id) VALUES ( ' to a column of data type int.

when i run the syntax check is says it's ok.
I've tried other sintaxes around the variable and it never gets to work.


Sorry for being so extense.
i thank you in advance for your time.

Nuno"
   

- Advertisement -