October 28, 2008 at 5:54 pm
How do I query this field?
Is this possible?
Thank you for your help!
I removed the < for display purpose:
Parameters
Parameter
Name>StartDate/Name>
Type>DateTime/Type>
Nullable>False/Nullable>
AllowBlank>True/AllowBlank>
MultiValue>False/MultiValue>
UsedInQuery>True/UsedInQuery>
State>MissingValidValue/State>
Prompt>Start Date/Prompt>
PromptUser>True/PromptUser>
DynamicDefaultValue>True/DynamicDefaultValue>
/Parameter>
Parameter>
Name>EndDate/Name>
Type>DateTime/Type>
Nullable>False/Nullable>
AllowBlank>True/AllowBlank>
MultiValue>False/MultiValue>
UsedInQuery>True/UsedInQuery>
State>MissingValidValue/State>
Prompt>End Date/Prompt>
PromptUser>True/PromptUser>
Dependencies>
Dependency>StartDate/Dependency>
/Dependencies>
DynamicDefaultValue>True/DynamicDefaultValue>
/Parameter>
Parameter>
Name>Store/Name>
Type>String/Type>
Nullable>False/Nullable>
AllowBlank>False/AllowBlank>
MultiValue>False/MultiValue>
UsedInQuery>True/UsedInQuery>
State>MissingValidValue/State>
Prompt>Plant/Prompt>
PromptUser>True/PromptUser>
DynamicValidValues>True/DynamicValidValues>
DynamicDefaultValue>True/DynamicDefaultValue>
/Parameter>
Parameter>
Name>Customer/Name>
Type>String/Type>
Nullable>False/Nullable>
AllowBlank>False/AllowBlank>
MultiValue>True/MultiValue>
UsedInQuery>True/UsedInQuery>
State>MissingValidValue/State>
Prompt>Source/Prompt>
PromptUser>True/PromptUser>
Dependencies>
Dependency>Store/Dependency>
/Dependencies>
DynamicValidValues>True/DynamicValidValues>
/Parameter>
Parameter>
Name>Colors/Name>
Type>String/Type>
Nullable>True/Nullable>
AllowBlank>False/AllowBlank>
MultiValue>False/MultiValue>
UsedInQuery>True/UsedInQuery>
State>MissingValidValue/State>
Prompt>Colors:/Prompt>
PromptUser>False/PromptUser>
DefaultValues>
Value>Red/Value>
/DefaultValues>Values>
Value>Red/Value>
/Values>
/Parameter>
Parameter>
Name>MyType/Name>
Type>String/Type>
Nullable>False/Nullable>
AllowBlank>False/AllowBlank>
MultiValue>True/MultiValue>
UsedInQuery>True/UsedInQuery>
State>MissingValidValue/State>
Prompt>MyType/Prompt>
PromptUser>True/PromptUser>
Dependencies>
Dependency>Colors/Dependency>
Dependency>Customer/Dependency>
Dependency>Store/Dependency>
/Dependencies>
DynamicValidValues>True/DynamicValidValues>
/Parameter>
Parameter>
Name>CityName/Name>
Type>String/Type>
Nullable>True/Nullable>
AllowBlank>True/AllowBlank>
MultiValue>False/MultiValue>
UsedInQuery>False/UsedInQuery>
State>MissingValidValue/State>
Prompt />
PromptUser>True/PromptUser>
DynamicValidValues>True/DynamicValidValues>
DynamicDefaultValue>True/DynamicDefaultValue>
/Parameter>
/Parameters>"
Final Results will be something like this:
ParameterNameDefaultValues Dependencies
StartDate
EndDate
Store
Customer
Colors Red
MyTypeColors
Customer
Store
CityName
October 28, 2008 at 7:10 pm
Are you using this in an application?
If so, I would bring back the whole XML and use XPath Query to return the desired results.
October 29, 2008 at 5:36 am
I am creating a report in reporting services.
October 29, 2008 at 7:19 am
Can you attach your XML as a txt document so we can play with it?
October 29, 2008 at 7:37 am
Ggraber,
Here is the file of one value and one field.
Thank you!
October 29, 2008 at 7:49 am
declare @x xml
set @x='..your xml here..'
select r.value('Prompt[1]','varchar(10)') as ParameterName,
rv.value('.','varchar(10)') as DefaultValues,
rd.value('.','varchar(10)') as Dependencies
from @x.nodes('/Parameters/Parameter') as x(r)
outer apply r.nodes('DefaultValues/Value') as xv(rv)
outer apply r.nodes('Dependencies/Dependency') as xd(rd)
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537October 29, 2008 at 7:58 am
Mark,
So, I cannot select from a field of a table?
I need to select from a file?
I have this table from reporting services and I need to pull data from field Parameter ([Parameter] [ntext] NULL)
CREATE TABLE [dbo].[Catalog](
[ItemID] [uniqueidentifier] NOT NULL,
[Path] [nvarchar](425) NOT NULL,
[Name] [nvarchar](425) NOT NULL,
[ParentID] [uniqueidentifier] NULL,
[Type] [int] NOT NULL,
[Content] [image] NULL,
[Intermediate] [uniqueidentifier] NULL,
[SnapshotDataID] [uniqueidentifier] NULL,
[LinkSourceID] [uniqueidentifier] NULL,
[Property] [ntext] NULL,
[Description] [nvarchar](512) NULL,
[Hidden] [bit] NULL,
[CreatedByID] [uniqueidentifier] NOT NULL,
[CreationDate] [datetime] NOT NULL,
[ModifiedByID] [uniqueidentifier] NOT NULL,
[ModifiedDate] [datetime] NOT NULL,
[MimeType] [nvarchar](260) NULL,
[SnapshotLimit] [int] NULL,
[Parameter] [ntext] NULL,
[PolicyID] [uniqueidentifier] NOT NULL,
[PolicyRoot] [bit] NOT NULL,
[ExecutionFlag] [int] NOT NULL,
[ExecutionTime] [datetime] NULL)
October 29, 2008 at 8:04 am
with cte as (
select cast(Parameter as xml) as Parameter
from [dbo].[Catalog])
select r.value('Prompt[1]','varchar(10)') as ParameterName,
rv.value('.','varchar(10)') as DefaultValues,
rd.value('.','varchar(10)') as Dependencies
from cte
cross apply Parameter.nodes('/Parameters/Parameter') as x(r)
outer apply r.nodes('DefaultValues/Value') as xv(rv)
outer apply r.nodes('Dependencies/Dependency') as xd(rd)
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537October 29, 2008 at 8:11 am
JohnDBA (10/29/2008)
Ggraber,Here is the file of one value and one field.
Thank you!
Looks like Mark beat me to it. 🙂
If multiple dependencies or default values existed did you want one row for each of them?
Or did you want only one row for each Parameter and CSV for the values?
October 29, 2008 at 8:43 am
And by the way: this would of course work much faster and much better (many more options) if the Parameter column's data type were XML.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
October 29, 2008 at 8:46 am
Ggraber,
One row for each of them will be better because there may be several dependencies.
Thank you so much!
October 29, 2008 at 8:56 am
You can get one row per parameter using this
with cte as (
select cast(Parameter as xml) as Parameter
from [dbo].[Catalog])
select r.value('Prompt[1]','varchar(10)') as ParameterName,
(select rv.value('.','varchar(10)') as "data()"
from r.nodes('DefaultValues/Value') as xv(rv) for xml path('')) as DefaultValues,
(select rd.value('.','varchar(10)') as "data()"
from r.nodes('Dependencies/Dependency') as xd(rd) for xml path('')) as Dependencies
from cte
cross apply Parameter.nodes('/Parameters/Parameter') as x(r)
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537October 30, 2008 at 6:44 pm
Thank you very much, this worked very nice! 🙂
I do appreciate your help!
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply