Showing posts with label parent. Show all posts
Showing posts with label parent. Show all posts

Friday, March 30, 2012

How to create Schema with FOR XML EXPLICIT option?

Hi,
i have this query:
SELECT 1 as Tag, NULL as Parent,
nomecampo as [label!1!for],
etichetta as [label!1!],
null as [input!2!id],
null as [input!2!type],
null as [input!2!name],
null as [input!2!value]
FROM t_campiaree
UNION ALL
select 2 as tag,
0 as parent,
null as [label!2!for],
null as [label!2!],
id as [input!2!id],
tipointerfaccia as [input!2!type],
nomecampo as [input!2!name],
'' [input!2!value]
from t_campiaree
FOR XML EXPLICIT
and the results is this:
<label for=3D"nome">Nome</label>
<label for=3D"cognome">Cognome</label>
<label for=3D"eta">Et=E0</label>
<input id=3D"1" type=3D"input" name=3D"nome" value=3D"" />
<input id=3D"2" type=3D"input" name=3D"cognome" value=3D"" />
<input id=3D"3" type=3D"input" name=3D"eta" value=3D"" />
now, how i can create schema for this xml file?
the XMLSCHEMA option don't work with EXPLICIT mode right?Hello maurox,

> the XMLSCHEMA option don't work with EXPLICIT mode right?
Nope, not yet anyway. If you can save the query results to a file and if
you have the .NET SDK installed, you can use XSD.EXE to infer a schema.
Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/|||thank kent.

>Nope, not yet anyway. If you can save the query results to a file and if
>you have the .NET SDK installed, you can use XSD.EXE to infer a schema.
it is the only solution?
i try with xsd.exe but i don't know how set the type of each
attribute..(i.e. attribute 'id' is integer but in the schema generated
is string)...sql

How to create Schema with FOR XML EXPLICIT option?

Hi,
i have this query:
SELECT 1 as Tag, NULL as Parent,
nomecampo as [label!1!for],
etichetta as [label!1!],
null as [input!2!id],
null as [input!2!type],
null as [input!2!name],
null as [input!2!value]
FROM t_campiaree
UNION ALL
select 2 as tag,
0 as parent,
null as [label!2!for],
null as [label!2!],
id as [input!2!id],
tipointerfaccia as [input!2!type],
nomecampo as [input!2!name],
'' [input!2!value]
from t_campiaree
FOR XML EXPLICIT
and the results is this:
<label for=3D"nome">Nome</label>
<label for=3D"cognome">Cognome</label>
<label for=3D"eta">Et=E0</label>
<input id=3D"1" type=3D"input" name=3D"nome" value=3D"" />
<input id=3D"2" type=3D"input" name=3D"cognome" value=3D"" />
<input id=3D"3" type=3D"input" name=3D"eta" value=3D"" />
now, how i can create schema for this xml file?
the XMLSCHEMA option don't work with EXPLICIT mode right?
Hello maurox,

> the XMLSCHEMA option don't work with EXPLICIT mode right?
Nope, not yet anyway. If you can save the query results to a file and if
you have the .NET SDK installed, you can use XSD.EXE to infer a schema.
Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/
|||thank kent.

>Nope, not yet anyway. If you can save the query results to a file and if
>you have the .NET SDK installed, you can use XSD.EXE to infer a schema.
it is the only solution?
i try with xsd.exe but i don't know how set the type of each
attribute..(i.e. attribute 'id' is integer but in the schema generated
is string)...

Friday, February 24, 2012

How to count

Hello all!
What is a neat way to count the number of children for every parent in
code
below?

CREATE TABLE parent
(
row_id INTEGER
NOT NULL
IDENTITY(1,1)
PRIMARY KEY,

parent_name VARCHAR(100)
)
GO

CREATE TABLE children
(
parent_row_id INTEGER,
child_name VARCHAR(100)
)

INSERT INTO parent (parent_name) VALUES ('King')
INSERT INTO parent (parent_name) VALUES ('Farmer')
INSERT INTO children (child_name, parent_row_id) VALUES ('Prince', 1)Select parent_name, SubQuery.Sum_of_children from parent
INNER JOIN
(
Select parent_row_id,COUNT(*) from children group by
parent_row_id
) SubQuery
ON SubQuery.parent_row_id = parent.row_id

HTH, Jens Suessmeyer.|||SELECT parent_name,
(SELECT COUNT(parent_row_id)
FROM children
WHERE parent_row_id = row_id) AS number_of_children
FROM parent

Good luck,
Tony Sebion

"jonsjostedt@.hotmail.com" <jonsjostedt@.hotmail.com> wrote in message
news:1126624285.607326.195420@.g44g2000cwa.googlegr oups.com:

> Hello all!
> What is a neat way to count the number of children for every parent in
> code
> below?
> CREATE TABLE parent
> (
> row_id INTEGER
> NOT NULL
> IDENTITY(1,1)
> PRIMARY KEY,
> parent_name VARCHAR(100)
> )
> GO
> CREATE TABLE children
> (
> parent_row_id INTEGER,
> child_name VARCHAR(100)
> )
> INSERT INTO parent (parent_name) VALUES ('King')
> INSERT INTO parent (parent_name) VALUES ('Farmer')
> INSERT INTO children (child_name, parent_row_id) VALUES ('Prince', 1)