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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-07-21 : 09:44:52
|
| Rick writes "I need to create a query that can be created "on the fly" using MS SQL 2000. What I mean by that is that I need to parameterize the column names. So the user can select which columns they want. The results will be fed into a UDF.**You Don't Need to read below unless you need further infoThe UDF goes row by row and calculates a statiscal value from the two columns. The user defined function looks basically like this:Alter FunctionNameReturnsVarChar(20)ASDeclare Variables Part...IF tableName = 'table'BeginDECLARE field_cursor CURSOR FOR SELECT Col1, Col2 From tableNameENDOPEN field_cursor- I need to paramertize the column names where it says, "SELECT Column1, Column2 from Table" and parameterize the column names." |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-07-21 : 10:39:35
|
| U may need to use dynamic SQL (But the Senior members of this Forum advices to avoid Dynamic SQL as much)There u can pass the table names, where criteria, ... and create the SQL Query and execute it.There is another non recommended way (unfortunately, this is having security threats as well) for ur requirement, to create the Query in the front end and pass to the SQL server.Also, the cursor u r using is also not recommended.For Dynamic SQL refer:http://www.sommarskog.se/dynamic_sql.html.Srinika |
 |
|
|
|
|
|