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 |
dehseth
Starting Member
18 Posts |
Posted - 2006-12-23 : 03:37:07
|
Hi ppl, i need to create a function which uses exec method which i couldn't.code:create function f () RETURNS int ASBEGINEXEC('if (1) return ')RETURN 1ENDgives me this error: "Invalid use of side-effecting or time-dependent operator in 'EXECUTE STRING' within a function."is there any way to use EXEC in a function? my actual problem is to create a function or smt else which works like IIF function like:variable = IIF (condition, true_part, false_part) works as exactly asvariable = condition ? true_part : false_partI cannot use ?: syntax in t-sql so what could i do to accomplish that?as an example:executingint x = IIF(5 > 4, 3 , 6)sets x as 3executing int x = IIF(5 <= 4, 3 , 6)sets x as 6condition part may have AND OR + * - / operators like we use in IF sentence. thank you everyone. |
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2006-12-23 : 04:04:51
|
>>is there any way to use EXEC in a function? exec Your_Stored_procedure @variables_go_here |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-12-23 : 08:09:52
|
IIF is suppored in Access and you have to use CASE WHEN in sql serverint x = IIF(5 > 4, 3 , 6)sets x as 3Can be written as Declare @x intSelect @x= CASE WHEN 5 > 4 THEN 3 ELSE 6 ENDPrint @xAlso, you cant use EXEC in a FunctionMadhivananFailing to plan is Planning to fail |
 |
|
dehseth
Starting Member
18 Posts |
Posted - 2006-12-25 : 07:00:46
|
thank you for ur reply man... i solved my problem calling a SP inside of my Function. seems like working.  quote: Originally posted by madhivanan IIF is suppored in Access and you have to use CASE WHEN in sql serverint x = IIF(5 > 4, 3 , 6)sets x as 3Can be written as Declare @x intSelect @x= CASE WHEN 5 > 4 THEN 3 ELSE 6 ENDPrint @xAlso, you cant use EXEC in a FunctionMadhivananFailing to plan is Planning to fail
|
 |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-12-25 : 07:28:42
|
quote: i solved my problem calling a SP inside of my Function. seems like working.
This is somthing new, how did you called SP in the UDF?? can you post the code which satisfied your purpose? Chiraghttp://chirikworld.blogspot.com/ |
 |
|
dehseth
Starting Member
18 Posts |
Posted - 2006-12-26 : 05:40:45
|
sorry it didn't work. i also tried a c# dll as function and use exec in this function. also ddin't work. seems like there's noway to use exec | execute command in function related functions | stored procs..quote: Originally posted by chiragkhabaria
quote: i solved my problem calling a SP inside of my Function. seems like working.
This is somthing new, how did you called SP in the UDF?? can you post the code which satisfied your purpose? Chiraghttp://chirikworld.blogspot.com/
|
 |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-12-26 : 05:55:57
|
post the code which you have tried...???Chiraghttp://chirikworld.blogspot.com/ |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-12-26 : 09:10:22
|
You cant use Dynamic SQL in FunctionPost the full code you usedIf you cant avoid Dynamic SQL, you should use stored procedure in place of FunctionhMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|