Re: SQL Variable USE.

From: Ricardo (rgutery_at_mentorits.com)
Date: 05/21/04


Date: Fri, 21 May 2004 17:17:28 -0600

Okay, I tried the suggestion from songie using this code:

(CREATE PROCEDURE [dbo].[NewTable] @tblName NVARCHAR(20)
AS
 CREATE TABLE [dbo].[@TBLNAME]
(
  [EmpID] [int] IDENTITY (1, 1) NOT NULL ,
  [EmpName] [nvarchar] (15) NOT NULL ,
  [EmpAddr] [ntext] NULL ,
  [EmpPicture] [image] NULL
 ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
)

I then exec the proc like so: exec NewTable 'A_Do_Do'.

No errors, but I get a table called TBLNAME (not what the what is stored in
the variable - I printed the varibale and it contains 'A_Do_Do').

do I need to tell SQL to use the 'CONTENTS' of the param or something???

btw: If I exec the query agian, I get this error indicating the code is
working fine;
Server: Msg 2714, Level 16, State 6, Procedure NewTable, Line 4
There is already an object named '@TBLNAME' in the database.

TX to all...

"songie D" <songie@d.com> wrote in message
news:eGAFtc4PEHA.2716@tk2msftngp13.phx.gbl...
> Don't pass the filename. Just pass the name of the table,
> like 'testtable'. SQL server will decide where to put it on
> disk for itself. And don't put the collation in, let it inherit
> it from the database level settings. That way it'll match
> with all the other tables.
>
> "Ricardo" <rgutery@mentorits.com> wrote in message
> news:uVWb9P4PEHA.3524@TK2MSFTNGP10.phx.gbl...
> > I have begun to play with SQL 2K and have a quick question.
> >
> > I would like to create a procedure named NewTable. In that proc, I would
> > like to PASS into the proc the name of a table that I would like to
create
> > like so:
> >
> > exec NewTable 'c:\test\testtable.mdf'
> >
> > How far off am I on something like the following/ Actually my question
> > should be, can I use the variable called TBLNAME in the create table
> > statement the way I have it below? If I'm on drugs, let me know.
> >
> > CREATE PROCEDURE [OWNER].NewTable] @tblName NVARCHAR(20)
> > AS
> >
> > CREATE TABLE [dbo].[@TBLNAME] (
> > [EmpID] [int] IDENTITY (1, 1) NOT NULL ,
> > [EmpName] [nvarchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
,
> > [EmpAddr] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> > [EmpPicture] [image] NULL
> > ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
> > GO
> >
> >
> >
>
>



Relevant Pages

  • Re: SqlDataAdapter1.SelectCommand.CommandType= CommandType.StoredProcedure
    ... >> kann man beim EXEC PROC keine Parameter beifügen. ... > da das TDS Protokoll das intern unterscheiden kann. ... > nach der Ausführung ungültig werden. ...
    (microsoft.public.de.german.entwickler.dotnet.datenbank)
  • typo error...
    ... First Proc should be p1 and not p3 ... > exec p1 ... >> Over night we take a copy of various live SQL databases onto another SQL ... >> I connect to the live databases using linked servers. ...
    (microsoft.public.sqlserver.programming)
  • Re: Strangeness in PROC-land
    ... //STEP1 EXEC PGM=IEFBR14 ... It complains about the second PEND because you can not nest PROCs inside ... instream data inside a PROC. ... But the JCL error is on the second PEND ...
    (bit.listserv.ibm-main)
  • Re: sp_revokedbaccess
    ... the source for this system proc in the procsyst.sql file in your SQL Server ... installation folder (e;g. C:\Program Files\Microsoft SQL ... EXEC sp_MS_MarkSystemObject N'sp_revokedbaccess' ...
    (microsoft.public.sqlserver.security)
  • Changing the step name in a procedure by using a parameter
    ... Naming each step for PROC A is easy, but all the steps generated by PROC B will have the same name. ... We haven't found a way to reference the condition code of a step within a procedure within a procedure. ... //X&MSR.A EXEC ... ... For IBM-MAIN subscribe / signoff / archive access instructions, ...
    (bit.listserv.ibm-main)