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 |
|
sanjnep
Posting Yak Master
191 Posts |
Posted - 2007-04-10 : 15:11:13
|
| Is it possible to write dynamic sql on scalar function and assign the value to return value? I like some thing like below but it is not working...Thanks______________________________________________________________________set @sql = 'select @CallLegKey= min(calllegkey) as CallLegKey from rt_'+@platform+'_CallLegswhere datediff(day,convert(datetime, CallEndTime) ,'''+cast(@today as varchar(20))+''') = '+cast(@cutoff as varchar(5))exec @sqlreturn @CallLegKey |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-10 : 15:14:21
|
| http://www.sommarskog.se/dynamic_sql.htmlPeter LarssonHelsingborg, Sweden |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-04-10 : 18:53:19
|
quote: Dynamic sql inside function and return value
No. Not allowed. Use stored procedure to do it KH |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-04-11 : 08:52:45
|
quote: Originally posted by sanjnep Is it possible to write dynamic sql on scalar function and assign the value to return value? I like some thing like below but it is not working...Thanks______________________________________________________________________set @sql = 'select @CallLegKey= min(calllegkey) as CallLegKey from rt_'+@platform+'_CallLegswhere datediff(day,convert(datetime, CallEndTime) ,'''+cast(@today as varchar(20))+''') = '+cast(@cutoff as varchar(5))exec @sqlreturn @CallLegKey
Make sure you have read Sommarskog's article fullyMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|