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
 Other Development Tools
 URL QueryString in SQL FROM clause?

Author  Topic 

brandt719
Starting Member

2 Posts

Posted - 2007-02-02 : 13:01:15
Is it possible to pull a URL QueryString into the FROM clause of a SQL statement? I have an ASP page that has a drop-down list of names of people in a particular group. Now, I would like for the drop-down list to pull a NEW group of folks from another table IF a particular URL Querysting is present. For example: www.mysite.com/default.asp?GroupID="ZTA". Is this possible? I use url querystrings in WHERE clauses, but I get a syntax error when I try to use it in a FROM clause. I appreciate any advice you could give me. Thanks

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-02-02 : 14:49:47
It is possible, you'd need to use dynamic SQL, basically construct the query by concatenating the name of the table into the SQL query.

However, it's not the best way to do it. Are those tables really all completely different, or are they very similar, just holding different groups of people/things/whatever? If they are similar, then create one table that holds them all, and add a type column that holds the value to determine the right group and then select the group in the WHERE clause as you've been doing. Unless the things in the different tables really represent different kinds of entities, this should be a much better design.
Go to Top of Page
   

- Advertisement -