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
 Development Tools
 ASP.NET
 Select table from form variable

Author  Topic 

olud
Starting Member

6 Posts

Posted - 2003-08-04 : 08:18:40
Hi all
I am quite new at this sql lark so pls help!!!
I am not even sure if the question belongs here!
I have a database with several table that will hold different information collected from forms filled by users over the web.

The type of user will determine the table their information goes to. The type of user is determined by their log in. I use cookies to store their details. Is it possible to write a statement to select a table or insert into a table based on the value of their cookie/session variable...

In other words... if the value of cookie/session variable = ww2, then insert into /select table 1 etc

Thanks in advance

olud

samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2003-08-04 : 08:44:57
You can read the cookie/session variable value and build a query string with that value and pass it to the sql server using a DB Connection.
If you are using stored procedure, make your procedure to accept table name as a parameter and use dynamic sql to build & execute the query string.
Hope this helps.

Sekar
~~~~
Success is not a destination that you ever reach. Success is the quality of your journey.
Go to Top of Page

skillile
Posting Yak Master

208 Posts

Posted - 2003-08-04 : 22:20:29
Maybe something like this

CREATE PROC ps_insert_table
(
@table int =0,
@something varchar(50) = 'na'
)
AS

SET NOCOUNT ON


--DO TABLE 1
IF @table = 1 BEGIN

INSERT INTO dbo.table1(x) VALUES(@something)

RETURN @@ERROR
END



--DO TABLE 2
IF @table = 2 BEGIN

INSERT INTO dbo.table2(x) VALUES(@something)

RETURN @@ERROR
END

slow down to move faster...
Go to Top of Page
   

- Advertisement -