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 SP problem

Author  Topic 

bjornh
Yak Posting Veteran

87 Posts

Posted - 2002-08-09 : 16:38:07
hi,

I've created this table:

CREATE TABLE [dbo].[herkomst] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[website] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
[url] [varchar] (300) COLLATE Latin1_General_CI_AS NULL
) ON [PRIMARY]
GO


And this SP:

create procedure dbo.test
@TableName VarChar(100),
@website varchar(100),
@url varchar(100)
AS

Declare @SQL VarChar(1000)

SELECT @SQL = 'insert into ' + @tableName + ' (website, url) values ("' + @website + '", "' + @url + '")'
SELECT @SQL = @SQL + @TableName

Exec ( @SQL)

GO

And I created this query to execute it:

exec test 'herkomst', 'http://www.googel.nl/', 'http://www.google.nl/sksdk'
go


but I get this error:

Server: Msg 128, Level 15, State 1, Line 1
The name 'http://www.googel.nl/' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

Can somebody please tell me what I did wrong up here?

thanks
Bjorn

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-08-09 : 16:44:15
You used double quotes (") to delimit a string in SQL Server, which uses single quotes (') to delmit string values:

create procedure dbo.test
@TableName VarChar(100),
@website varchar(100),
@url varchar(100)
AS

Declare @SQL VarChar(1000)

SELECT @SQL = 'insert into ' + @tableName + ' (website, url) values (''' + @website + ''', ''' + @url + ''')'

Exec ( @SQL)


Go to Top of Page

bjornh
Yak Posting Veteran

87 Posts

Posted - 2002-08-09 : 16:53:50
ha oke, it works, thanks.

Go to Top of Page
   

- Advertisement -