Re: SQL Variable USE.
From: Ricardo (rgutery_at_mentorits.com)
Date: 05/21/04
- Next message: Ricardo: "Re: Another Scripting ?"
- Previous message: songie D: "Re: Function VS StoredProcedure"
- In reply to: songie D: "Re: SQL Variable USE."
- Next in thread: Gregory A. Larsen: "Re: SQL Variable USE."
- Messages sorted by: [ date ] [ thread ]
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
> >
> >
> >
>
>
- Next message: Ricardo: "Re: Another Scripting ?"
- Previous message: songie D: "Re: Function VS StoredProcedure"
- In reply to: songie D: "Re: SQL Variable USE."
- Next in thread: Gregory A. Larsen: "Re: SQL Variable USE."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|