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

Invalid column name

Status
Not open for further replies.

INFORMAT

Programmer
Joined
Jan 3, 2001
Messages
121
Location
BE
Hi

I've created a query in the query analyzer and it worked fine. Then i used that query to make a stored procedure. when I call this stored procedure in the query analyzer I get the following message :
"invalid column name : XXX"
the xxx is the name of a string parameter.
The stored procedure gets 4 parameters and one of those is the name of another database.
In the stored procedure, I create a new table for inserting the data.
to insert the data in the table, a use simular code:

execute('
INSERT INTO(xx,yy,zz,...)
SELECT '
+databasepointer+'.dbo.bla.xx,
'
+databasepointer+'.dbo.bla.yy,...
from '
+databasepointer+'.dbo.bla
inner join lala
on '
+databasepointer+'.dbo.bla.lll = lala.lll
where lala.kk = "'
+astringpointer+'" ')

the error is generated on "'+atringpointer+'"

could someone help me with this problem?

björn
 
Sounds like it might be to do with QUOTED_IDENTIFIERs.

Books online gives some examples, try using the
SET QUOTED_IDENTIFIER OFF statement in your stored procedure


Also if you change your execute to a print & then call the stored procedure what to you get? You can then try to excecute the statement that is returned.

Apologies if you've already tried this :)

 
Use 4 single quotes in a row e.g.

create procedure foobar(@p char(40)) as
begin
execute (
'select * from foo where fname =' + '''' +@p+ '''')
end

You may also want to take a look at sp_executesql
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top