SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Concat function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Seventhnight
Flowing Fount of Yak Knowledge

USA
2878 Posts

Posted - 06/21/2004 :  11:27:36  Show Profile  Visit Seventhnight's Homepage  Reply with Quote
Alright, I recently read this blog entry:
http://weblogs.sqlteam.com/jeffs/archive/2004/06/03/1491.aspx

This entry linked to an article that enabled you to use xp's in an UDF to build concatenated values.

I was following along with a post this morning:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=36439

And I decided to experiment. I got surprisingly far (I thought) as I managed to use xp's to return a concatenated @variable from a dynamic sql query without using a table of any sort. Please take a look at my sql to this point and help me through this.

Even though I only used objects found in the 'Extended Stored Procedures' section, i still recieved:
Server: Msg 557, Level 16, State 2, Procedure ConcatStr, Line 15
Only functions and extended stored procedures can be executed from within a function.

Here is my code:
quote:

CREATE FUNCTION dbo.ConcatStr
(
@qryStr nvarchar(1000),
@colName nvarchar(100),
@params nvarchar(1000)
)
Returns nvarchar(2000) as
BEGIN
Set @QryStr = Replace(@QryStr,@colName,'@rtnVal = isnull(@rtnVal + '','', '''') + ' + @colName)
Select @QryStr = 'Declare @rtnVal nvarchar(1000);' + @QryStr + ';Select @rtnValue = @rtnVal'

Declare @p1 int

Set @params = isnull(@params + ', ', '') + '@rtnValue nvarchar(4000) output'
exec master..sp_prepare @p1 output, @params, @QryStr, 1

Declare @rtnValue nvarchar(4000)
exec master..sp_execute @p1, '1', @rtnValue output

Return @RtnValue
END


Go
Declare @qryStr nvarchar(1000),
@colName nvarchar(100),
@params nvarchar(1000)

Set @qryStr = 'Select Prefix From myDb.dbo.myClientList Where Active = @Active'
Set @colName = 'Prefix'
Set @params = '@active nvarchar(1)'

Select myDb.dbo.ConcatStr(@qryStr,@colName,@params)



Maybe there is no solution, but I thought I'd ask!?!




Corey

Seventhnight
Flowing Fount of Yak Knowledge

USA
2878 Posts

Posted - 06/21/2004 :  15:35:29  Show Profile  Visit Seventhnight's Homepage  Reply with Quote
After talking to Brett...
EXEC master..sp_help sp_Prepare gives type:Extended Stored Procedure


Corey
Go to Top of Page

jsmith8858
Dr. Cross Join

USA
7423 Posts

Posted - 06/22/2004 :  16:43:18  Show Profile  Visit jsmith8858's Homepage  Reply with Quote
you cannot execute the extended stored procedures that allow you to use dynamic SQL from within a UDF unfortunately .... believe me, I've tried !!

- Jeff

Edited by - jsmith8858 on 06/22/2004 16:44:24
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000