Showing posts with label attributes. Show all posts
Showing posts with label attributes. Show all posts

Tuesday, March 27, 2012

Can I get both Attributes and Elements values in same OpenXML query ?

As an input parameter for stored procedure I have the following XML, its values are contained in both attributes and elements. For attributes we have to use flag = 1, and for attributes 2. Is there any flag or technique that we can retrieve both ?

Here is my script:

declare
@.xml xml,
@.handle int

set @.xml =
'
<Sortable>
<Field ord="1" type="asc">LastName</Field>
<Field ord="2" type="desc">CreateDate</Field>
<Field ord="3" type="asc">ProspectNum</Field>
</Sortable>
'

exec sp_xml_preparedocument @.handle output, @.xml


select
ord,
type,
Field
from openxml(@.handle, '/Sortable/Field', 1)
with
(
ord int,
type varchar(4),
Field varchar(20) --'./Field'
)

exec sp_xml_removedocument @.handle

I exepect it to return the foillowing result set:

ord type Field
-- - --
1 asc LastName
2 desc CreateDate
3 asc ProspectNum

Obviously it returns NULL for my 'Field' column.

Thanks

Either of these

select
ord,
type,
Field
from openxml(@.handle, '/Sortable/Field', 1)
with
(
ord int,
type varchar(4),
Field varchar(20) '.'
)


select r.value('@.ord','int') as ord,
r.value('@.type','varchar(4)') as type,
r.value('.','varchar(20)') as Field
from @.xml.nodes('/Sortable/Field') as D(r)

Thursday, February 16, 2012

can a report read parameters from POST as opposed to GET?

My scenarios is that I have to have an ADHOC report page, which will
allow the user to select various attributes, and I have to then create
the SQL clause on the fly, based off these selected attributes. I then
have to have the report in reporting services run off of that generated
SQL clause.
I have two ideas how I can do this, but I am looking for the most
efficient.
My first idea, and the one I assume I will have to go with is this.
When the user clicks the run button, the SQL clause will be built based
on their selections. That SQL clause will then get passed into a
stored proc which will act like a "middle man", this "middle man"
procedure will store the clause into a "holding" table. The Reporting
Services report will then have to run, use a procedure that reads from
this "holding" table and uses the SQL clause, executes it, and if
successful, deletes it from the holding table, ready for the next run
of the page.
The other approach I am thinking of, but am not sure will work is
basically passing the generated SQL query to the report as a POST
variable. I am not sure if this will work or not since I haven't tried
it before.
does anyone know if you can pass in POST variables as opposed to GET
variables when calling a report as a url?answered my own question by searching through the help (which I should
have done in the first place). So far it looks like I can POST the SQL
query that I want....but the help file mentions something about a 2000
char limit, for even POST...anyone have any experience with a similar
situation?