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.
Author |
Topic |
faijurrahuman
Starting Member
15 Posts |
Posted - 2012-03-01 : 02:37:08
|
Hi;I want dynamically search condition.This is my table(This is generated dynamically ) this is not a physical table.id Tablename columnname Value1 Company Company_name Microsoft2 Address Pcity CA3 Phone Pnumber 100-4582I want search the Value in the particular table , In this tables are already in the database(Company,Address,Phone). dynamically pass the tablename and columnname and search the Value.ExSelect c.Company_name from Company cjoin Address a on a.companyid=c.companyidjoin phone p on p.companyid=c.companyidwhere 1=1and c.company_name like '%Microsoft%'and a.Pcity Like '%CA%'and p.Pnumber like '%100-4582%'I want dynamically buld the query and search the condition in the Value column.How can I do this ..Thanks.Share Knowledge team |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-03-01 : 05:01:02
|
this is not a good idea. IF you think about what you are really asking then you are saying "I want to do what a general purpose SELECT statement does in a sp".One of the advantages of a sp is that it stores the execution plan for its use. It's tuned for its job by the engine.There's nothing *stopping* you from writing a dynamic sql solution that would do what you want but its the wrong idea.Either -- write a sp for each job you want. Or use vanilla SQL for the different calls.Don't try and invent some sort of meta sp that takes a table name. It just leads to an insecure, inefficient, wrong designCharlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
faijurrahuman
Starting Member
15 Posts |
Posted - 2012-03-01 : 05:12:09
|
ok.. But here we need that type of solution. ..help to solve the problem....Share Knowledge team |
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-03-01 : 05:27:47
|
no you don't - you need to rethink your approach. I'm not going to waste my time helping you do something dangerous and stupid.If you persist in your plan at least please read this and guard against sql injection:http://www.sommarskog.se/dynamic_sql.htmlCharlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
|
|