May 8, 2008 at 3:36 pm
The following code (based off of your query) works for me. Note that I build the XML string by hand, but your XML string should look similiar.
[Code]
declare @C XML
set @C = ' '
select m.item.value('CUSTOMER_NUMBER[1]','integer') [Customer_Number]
from @C.nodes('/C/CUSTOMER') as m(item)
[/Code]
The result set I get back is:
Customer_Number
--------------
1
2
There must be a problem with the XML string that you are passing to the @C parameter.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
May 8, 2008 at 3:38 pm
lklein (5/8/2008)
This is so frustrating... yikes - I get an error running that just in design view right?
Yes, the RaisError raises an error. In Preview mode, you'll see the xml line that you're passing to the procedure.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
May 8, 2008 at 3:42 pm
This is the function in the code section - which is different from the beginning article.
Function ReturnXML(ByVal MultiValueList As Object, ByVal Root As String, ByVal Node As String, ByVal Element As String) As String
'**************************************************************************
' Returns an XML string by using the specified values.
' Parameters:
' MultiValueList - a multi value list from SSRS
' Root, Node, Element - String to use in building the XML string
'**************************************************************************
Dim ReturnString = ""
Dim sParamItem As Object
ReturnString = " "
For Each sParamItem In MultiValueList
ReturnString &= " "
Next
ReturnString &= " "
Return (ReturnString)
End Function
May 8, 2008 at 4:43 pm
lklein (5/8/2008)
This is the function in the code section - which is different from the beginning article.
If you're not using the function in the beginning article, I don't know what you're doing. And the post you sent is removing all of the xml tags, so all I see is a string of spaces.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
May 9, 2008 at 1:16 am
May 9, 2008 at 6:00 am
Adriaan Davel (5/9/2008)
Hi Wayne,Nice one, have you looked at the performance of using the XML joins in your stored procedure?
In my "casual" testing, XML datasets up to about 1000 "records" performed pretty fast. Beyond 1000 it started slowing down; when it got to 5000 it was crawling, and I stopped one query with > 20,000 elements after about an hour. Most of the XML datasets I use are in dealing with SSRS, where the users want to be able to select > 1 option. Most of these selections are kept down to 15000. but, they've been told...
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
May 9, 2008 at 8:13 am
Wayne,
I've put the original code back in the code property and have the same results - nothing returns. However, now that it's back to your code - is there anything on the sql server that needs to be set to allow XML?
Function ReturnXML(ByVal MultiValueList As Object, ByVal Root As String, ByVal Node As String, ByVal Element As String) As String
Dim ReturnString = ""
Dim sParamItem As Object
ReturnString = " "
For Each sParamItem In MultiValueList
ReturnString &= " "
Next
ReturnString &= " "
Return (ReturnString)
End Function
May 12, 2008 at 6:53 am
Hello again...
As you can see, posting XML strings is stripping everything out.
I've recoded this to build the string in a more complex method. Hopefully, it will post okay.
This code, when I run it, returns 2 records. What do you get?
declare @start char(1), @end char(1), @Root char(1), @Node char(8), @Element char(15)
select @Start = char(60), @end = char(62), @Root = 'C', @Node = 'CUSTOMER', @Element = 'CUSTOMER_NUMBER'
declare @C XML
set @C = @Start + @Root + @End +
@Start + @Node + @End + @Start + @Element + @End + '1' + @Start + '/' + @Element + @End + @Start + '/' + @Node + @End +
@Start + @Node + @End + @Start + @Element + @End + '2' + @Start + '/' + @Element + @End + @Start + '/' + @Node + @End +
@Start + '/' + @Root + @End
select m.item.value('CUSTOMER_NUMBER[1]','integer') [Customer_Number]
from @C.nodes('/C/CUSTOMER') as m(item)
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
May 12, 2008 at 7:31 am
Yes - I get 1,2
May 27, 2011 at 8:17 am
WayneS (5/12/2008)
Hello again...As you can see, posting XML strings is stripping everything out.
I've recoded this to build the string in a more complex method. Hopefully, it will post okay.
This code, when I run it, returns 2 records. What do you get?
declare @start char(1), @end char(1), @Root char(1), @Node char(8), @Element char(15)
select @Start = char(60), @end = char(62), @Root = 'C', @Node = 'CUSTOMER', @Element = 'CUSTOMER_NUMBER'
declare @C XML
set @C = @Start + @Root + @End +
@Start + @Node + @End + @Start + @Element + @End + '1' + @Start + '/' + @Element + @End + @Start + '/' + @Node + @End +
@Start + @Node + @End + @Start + @Element + @End + '2' + @Start + '/' + @Element + @End + @Start + '/' + @Node + @End +
@Start + '/' + @Root + @End
select m.item.value('CUSTOMER_NUMBER[1]','integer') [Customer_Number]
from @C.nodes('/C/CUSTOMER') as m(item)
I get 1 & 2 too.
But I haven't managed to pass the multi value paramater as an XML to my sproc.
Did anyone got it to work?
This is my thread:
http://www.sqlservercentral.com/Forums/Topic1115348-150-1.aspx#bm1115415
Thanks.
October 4, 2012 at 9:11 pm
Hi,
very useful code..
can u please let me know how to call this custom code function from SSRS ?
October 5, 2012 at 7:13 am
You can either use it in the Code tab of the report properties, or you can build it into a library and link the dll into the report from the References tab of the report properties.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Viewing 12 posts - 31 through 41 (of 41 total)
You must be logged in to reply to this topic. Login to reply