Wednesday, March 7, 2012

Parameters as table?

Is it possible to use parameters as table? @.table maybe?You mean is it possible to use @.Table as parameter? I dont think so. Not in 2000 and not even in 2005.|||Well could i use the text in a dropdownlist as the table name something like "SELECT * from '+ dropdownlist1.text +'" ??|||You can but there are some caveats with dynamic SQL. Check outThe Curse and Blessings of Dynamic SQL before you make a decision.|||

he's my situation, i have 4 tables which contain customers. i was thinking with two dropdownlist. dropdownlist1 has the name for the 4 tables and dropdownlist2 has the customers names. so i want to somehow depening on dropdownlist1 and dropdownlist2 to get info with a SELECT query. any suggestions?

Thank you.

|||Are the 4 tables related? post some sample data in the tables along with the table structure, and the result you are expecting so we can better understand what you are trying to do.|||

The tables are not related. I will try to break down the situation.

4 Tables contain SALES ORDERS

The 4 tables are North, South, East and West

Dropdownlist1 which has the values of North, South, East and West.

Dropdownlist2 gets the customers names from each region. i.e North will only show North customer and South will only show south customers and so on.

So I want a select query that will give me the results depending on what was selected from the two dropdownlist. i.e I select North in dropdownlist1and select John Doug in dropdownlist2. The query would be "SELECT * FROM north WHERE txtcustomername='John Doug"" Maybe the way i'm trying to accomplish this isn't the best.

Thank you.

|||

Looks like you have a bad design of tables. given the situation, your only choice seems to be a dynamic SQL. Read up the article link I posted.

You would prbly end up with something like this..

EXEC('SELECT * FROM ' + @.table + 'WHERE ' + @.condition )

|||More like this:

EXEC

('SELECT * FROM '+ @.table+'WHERE customername='''+ @.name+'''')|||is EXEC a sql command? will it work in vb.net?|||Its a SQL Command. I would rather create a stored proc with the parameters and call the proc from your application.|||i don't have access to create store proc's

No comments:

Post a Comment