Robert Davis (5/24/2006)
Try adding a USE statement to the dynamic SQL.<DT><FONT color=#1111ff>set</FONT><FONT size=2><FONT color=#1111ff> @sql</FONT> </FONT><FONT color=#808080 size=2>=</FONT><FONT size=2> N</FONT><FONT color=#ff0000 size=2>' USE [OtherDatabase] <DT>create function dbo.fn_tot_alldbs(@yourparameter int) <DT>returns int <DT>as <DT>--auto generated function code <DT>begin <DT>declare @intCount int <DT>select @intcount = 0 <DT>'</FONT></DT>
I think you'll find that'll return an error about how CREATE must be the first thing in the batch.
--Jeff Moden
Change is inevitable... Change for the better is not.