Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««12345»»

Using XML to pass Multi-Select parameters from SSRS to SQL Server Expand / Collapse
Author
Message
Posted Thursday, May 8, 2008 3:36 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 8:11 PM
Points: 6,604, Visits: 8,910
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.

declare @C XML
set @C = ' '

select m.item.value('CUSTOMER_NUMBER[1]','integer') [Customer_Number]
from @C.nodes('/C/CUSTOMER') as m(item)

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
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings
Post #497477
Posted Thursday, May 8, 2008 3:38 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 8:11 PM
Points: 6,604, Visits: 8,910
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
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings
Post #497479
Posted Thursday, May 8, 2008 3:42 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, May 22, 2014 3:06 PM
Points: 64, Visits: 263
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

Post #497486
Posted Thursday, May 8, 2008 4:43 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 8:11 PM
Points: 6,604, Visits: 8,910
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
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings
Post #497504
Posted Friday, May 9, 2008 1:16 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, May 21, 2012 8:34 AM
Points: 15, Visits: 13

Hi Wayne,

Nice one, have you looked at the performance of using the XML joins in your stored procedure?

I did quite a bit of performance testing with the "other" methods [url=http://www.sqlservercentral.com/articles/Development/3138/][/url] and the results were quite interesting, would love to see how XML performs with this.

Post #497624
Posted Friday, May 9, 2008 6:00 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 8:11 PM
Points: 6,604, Visits: 8,910
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
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings
Post #497773
Posted Friday, May 9, 2008 8:13 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, May 22, 2014 3:06 PM
Points: 64, Visits: 263
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
Post #497919
Posted Monday, May 12, 2008 6:53 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 8:11 PM
Points: 6,604, Visits: 8,910
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
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings
Post #498727
Posted Monday, May 12, 2008 7:31 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, May 22, 2014 3:06 PM
Points: 64, Visits: 263
Yes - I get 1,2
Post #498763
Posted Friday, May 27, 2011 8:17 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, February 22, 2012 6:08 AM
Points: 11, Visits: 63
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.
Post #1116277
« Prev Topic | Next Topic »

Add to briefcase «««12345»»

Permissions Expand / Collapse