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 2005 Forums
 Transact-SQL (2005)
 SQL Query

Author  Topic 

mahimam_2004
Starting Member

40 Posts

Posted - 2008-07-06 : 12:41:54
Hi,

I have a table tblbusiness like this:

ID | Business Name |

1 | xxx LLC

2 | ff LLP



Like the above table, I have multiple tables to store Manufacturer(id, name) , Distributor(id, name), LicenseNo( id, Number), Person (id, name)..



Now from the website user has to perform the search for the above fields. To do this, in the web site, I amputting

dropdown list1 : (operator) value

Name:

business name LIKE ff

Manufacturer name NOT

Person name ... Not Like



Now th stored procedure got the parameters: columnname: frist dropdownlist value, which is the table's column. second parameter is for operator which is used in Where clause. and third parameter is value. Based upon teh selection of first drop down list value, i have to get the table name before performing the query(Ex: if columnname value is businessname, table is tblbusiness).

Do the search like this:

if(columnname like 'businessname')

tbl = 'tblBusienss'

else if(columnname like 'personname')

tbl = 'tblPerson'



Select * from tbl where 'columnname' 'pOperator' 'pvalue' ;

How to perform the above query?

Thanks in advance

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-06 : 21:08:18
you will need Dynamic SQL. Take a look at this http://www.sommarskog.se/dynamic_sql.html


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -