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
 Transact-SQL (2000)
 new to T-SQL and have some questions

Author  Topic 

havey
Starting Member

16 Posts

Posted - 2005-08-25 : 12:44:29
Hi,

I hope i'm in the right forum....
I have an ASP application that will need to send a value to a stored procedure (sql 2000). The db server is on another ipAddress. I'm trying to create a table and comlumn heading in the db called "testing", the ASP value that is being passed when the stored proced is called is VALU

This is my ill syntax procedure - now please keep in mind that i really don't know what i'm doing cause this is my first attempt at a store procedure (i don't usually work directly on the server but rather create dynamic sql statments in the ASP page)

CREATE PROCCEDURE sp_table
@VALU nvarchar(30)
CREATE TABLE @VALU
(
Column_1 varchar(200),
Column_2 varchar(200),
Column_3 varchar(200),
Column_4 varchar(200),
Column_5 varchar(200),
Column_6 varchar(200)
)

// What i'm tring to do (i'm lost) is pass a value (VALU) to the Procedure. I'm hoping the procedure can create a table name of the value of VALU, and create columns 1 thru 6 in that table.

Can someone look over my Store Procedure and let me know the issues, thanks

sdiwi
Starting Member

27 Posts

Posted - 2005-08-25 : 12:50:32
hi.

you cannot use variables in that way.
what you are trying is to execute a query from inside a sp.
you can use the system stored procedure sp_executesql to solve your problem...

your code would then somehow look like this:

CREATE PROCCEDURE sp_table
@VALU nvarchar(30)
AS
DECLARE @query NVARCHAR(500);

SET @query = N'CREATE TABLE @VALU
(
Column_1 varchar(200),
Column_2 varchar(200),
Column_3 varchar(200),
Column_4 varchar(200),
Column_5 varchar(200),
Column_6 varchar(200)
)';

EXEC sp_executesql @query;

-----------------------------


however it is possible to use variables in that way

CREATE PROCEDURE test
@myid INT
AS
SELECT * FROM mytable WHERE id = @myid;



hope it somehow helped you.
gotta go home now;)
this is my last deed @work for today

cya,
peace,
sdiwi.
Go to Top of Page
   

- Advertisement -