all groups > sql server new users > june 2007 >
You're in the

sql server new users

group:

GROUP BY problem


Re: GROUP BY problem Tom Moreau
6/22/2007 12:00:00 AM
sql server new users:
Consider:

SQL 2000
1) re-casting the string as an xml doc AND
2) using OPENXML to render the contents as a table, filtering as appropriate

SQL2005
1) using a CLR proc to convert the string to a table and joining as
appropriate OR
2) feeding the data as an xml parameter and using the .nodes method to
render as a table

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau


[quoted text, click to view]
Hi,

I have a query where I group results using three conditions: date, exam and
solicitant. Solicitants are selected in WHERE condition using '... where
solicitant in (string variable) and...'.

My problem is that I have, in string variable, a sequence like
'70214,70214,58256,58256,0,0,0,0', where each number relates to a specific
solicitant and '0' to exams where solicitant is not registered.

When I print query result it is fine as long as I have only numbers > 0.
Since '0' represents solicitants not registered on the system, I should not
group them (I don't know if they are the same person or not, so I can't
group them).

Is there a way to group only by the 'numbers' greater than '0' or I'll have
to make two separate queries?


Thanks for any help,


Luiz Horacio
GROUP BY problem Luiz Horacio
6/22/2007 2:22:23 AM
Hi,

I have a query where I group results using three conditions: date, exam =
and solicitant. Solicitants are selected in WHERE condition using '... =
where solicitant in (string variable) and...'.

My problem is that I have, in string variable, a sequence like =
'70214,70214,58256,58256,0,0,0,0', where each number relates to a =
specific solicitant and '0' to exams where solicitant is not registered.

When I print query result it is fine as long as I have only numbers > 0. =
Since '0' represents solicitants not registered on the system, I should =
not group them (I don't know if they are the same person or not, so I =
can't group them).

Is there a way to group only by the 'numbers' greater than '0' or I'll =
have to make two separate queries?


Thanks for any help,


Re: GROUP BY problem Luiz Horacio
6/23/2007 12:25:24 AM
Hi Tom,

Thanks for your help, but this is faaarrr beyond my current knowledge.

Thanks anyway,

Luiz Horacio

"Tom Moreau" <tom@dont.spam.me.cips.ca> escreveu na mensagem
news:uExpPcMtHHA.3640@TK2MSFTNGP05.phx.gbl...
[quoted text, click to view]

Re: GROUP BY problem Hugo Kornelis
6/23/2007 1:00:12 AM
[quoted text, click to view]

(snip)
[quoted text, click to view]

Hi Luiz,

Probably. Using a CASE expression in the GROUP BY is often the answer to
complex grouping issues.

But I fail to understand the exact requirements you describe. If you
need more help, then please include CREATE TABLE statements (including
all constraints, properties, and indexes), INSERT statements (for a few
well-chosen rows of sample data), and expected output with your next
post.

--
Hugo Kornelis, SQL Server MVP
Re: GROUP BY problem Luiz Horacio
6/23/2007 1:19:32 AM
Hi Hugo,

Thanks. I'll take a look on CASE expression.

Thanks,

Luiz Horacio

"Hugo Kornelis" <hugo@perFact.REMOVETHIS.info.INVALID> escreveu na mensagem
news:nvko7390g9vq9ljped26q1ro0hv3h1c9cq@4ax.com...
[quoted text, click to view]

Re: GROUP BY problem Tom Moreau
6/23/2007 5:57:47 AM
Attached is code from an article I wrote in 2002, which can be used to feed
the comma-delimited string to a stored proc, which then invokes a function.

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau


[quoted text, click to view]
Hi Tom,

Thanks for your help, but this is faaarrr beyond my current knowledge.

Thanks anyway,

Luiz Horacio

"Tom Moreau" <tom@dont.spam.me.cips.ca> escreveu na mensagem
news:uExpPcMtHHA.3640@TK2MSFTNGP05.phx.gbl...
[quoted text, click to view]
AddThis Social Bookmark Button