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 - 2001-01-23 : 09:47:41
|
Tom writes "I made a UDF called GetElection that takes 4 parameters. One of those parameters I would like to make dynamic in a sql query.
With out dynamic- notice the 7126 [second parameter/where condition]): *// works with explicit parameters //* select num,lname,fname,ssn, (SELECT optionid FROM UDF_GETELECTION(2001,7126,1,'')) as medoc from employee ee where num = 7126
*// I get an error if I try this way //* select top 10 ee.num,lname,fname,ssn, (SELECT optionid FROM UDF_GETELECTION(2001,ee.num,1,'')) as medoc from employee ee ///////////////////////////////////////////// Server: Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near 'ee'. ///////////////////////////////////////////////
*// A nested select would do also (this is some what similar to the udf but the udf may be recursive and does a lot more) BUT THE NESTED SELECT IS DYNAMIC IT WILL RETURN TOP TEN WITH NO ERROR//*
select top 10 num,lname,fname,ssn, (SELECT optionid FROM election where planyear =2001 and num = ee.num and planid =1 and electstatus = 'C') as medoc from employee ee
Am I doing something wrong? Or can UDF's not be used dynamically? I have read the help and posted this online but have not received any response. I have worked in FoxPro and this is easily done there." |
|
|
|
|
|
|
|