RE: Using a column variable in an Insert Stored procedure

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Pam Davey (PamDavey_at_discussions.microsoft.com)
Date: 08/31/04


Date: Mon, 30 Aug 2004 21:13:05 -0700

Thank you for the suggestion. I'll definitely try it.

FYI though, dbo.CustomTable does exist. I should have included that this is
actually the content of the @Table variable (sysname) that the sp sends to
the user defined function. The function is actually retrieving the column
names from that table(CustomTable). I'll be happy to try your suggestion but
I'm at a loss as to why SQL Server is returning this error.

Thanks again.

"Clint Colefax" wrote:

> Does CustomTable exist?
>
> Generally this error message is telling you that the specified object does
> not exist.
>
> Even so, I don't think what you are trying to do will work anyway. You may
> need to look into creating an add hoc sql statement using the sp_executesql
> procedure. With this you can build a script in a nvarchar variable, then pass
> this to the procedure to execute.
>
> "Pam Davey" wrote:
>
> > I'm not sure if this is the correct place for this msg..
> >
> > I'm a bit new to SQL server and here's what I have:
> >
> > I've created a stored procedure in SQL Server 2000 which has a parameter
> > @Table sysname.
> > The sp calls a scalar user defined function and passes it the @Table
> > variable. The function returns a variable (@Columns varchar(8000)) which
> > lists the column names in @Table in this format (col1, col2, ...)
> > Back in the sp I use the @Columns variable in an insert statement this way:
> >
> > INSERT INTO MyDB.dbo.CustomTable
> > (@Columns)
> > VALUES
> > (@Value1, @Value2...)
> >
> > The syntax checks in the sp and it works nicely up to the Insert statement
> > at which point SQL Server returns the error: Invalid object name
> > MyDB.dbo.Custom
> >
> > What am I overlooking?
> >
> > Thank you for any help.



Relevant Pages

  • Re: Connecting to a sql server database
    ... You are trying to use integrated security in your app (as is shown in the ... line numbered code where the connection string is shown). ... sql server, hence integrated security fails. ... > causing the error message and what the correction for this. ...
    (microsoft.public.dotnet.general)
  • Re: Invalid OLEVERB structure error 80040000 on DTS job
    ... >> Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP) ... >- I copied this DTS package from a 32 bit Windows Server 2003 system. ... >I would only get that error message in the Job History logs though. ...
    (microsoft.public.sqlserver.dts)
  • Re: Classic ASP connectionstring to SQL Server 2005
    ... So this connection string is in the VB6 dll? ... What is the error message? ... Provider cannot be found. ... can you ping the sql server? ...
    (microsoft.public.inetserver.asp.db)
  • Re: ANNOUNCEMENT: New SQL Server security tool - SQL Server 2000 Scan Tool
    ... > This posting is provided "AS IS" with no warranties, and confers no rights. ... >> computers running Windows 2000 or higher and can identify instances ... >> please state the version of SQL Server being used and the error ... >> error message text received, ...
    (microsoft.public.windowsxp.security_admin)
  • Re: ANNOUNCEMENT: New SQL Server security tool - SQL Server 2000 Scan Tool
    ... > This posting is provided "AS IS" with no warranties, and confers no rights. ... >> computers running Windows 2000 or higher and can identify instances ... >> please state the version of SQL Server being used and the error ... >> error message text received, ...
    (microsoft.public.win2000.security)