I have a table that contains a number of columns containing either a varchar
value, or null. There are multiple rows per grouping. I would like to colapse
the multiple rows into a single row, either by appending the strings to each
other, or simply selecting the first (or last) one.
If it was a number field I could do a SUM, MAX or MIN. SUM doesn't work, for
obvious reasons. I thought MAX would work, but MAX returns only one value for
all of the columns (as opposed to one per column) and the rest are left as
null.
Any suggestions?
Here's an example...
The table contains this data, all items are varchar
32611317
3261Non-Client
32612
3261mmarkowitz
I'd like to turn this into...
3261 1317 Non-client 2 mmarkowitz
|||This looks like a PIVOT. Can you flatten this table out on the client? If
not, see http://www.aspfaq.com/2462
http://www.aspfaq.com/
(Reverse address to reply.)
"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:7838E3D4-CD8D-46EB-A75F-D069B30EE9AB@.microsoft.com...
> I have a table that contains a number of columns containing either a
varchar
> value, or null. There are multiple rows per grouping. I would like to
colapse
> the multiple rows into a single row, either by appending the strings to
each
> other, or simply selecting the first (or last) one.
> If it was a number field I could do a SUM, MAX or MIN. SUM doesn't work,
for
> obvious reasons. I thought MAX would work, but MAX returns only one value
for
> all of the columns (as opposed to one per column) and the rest are left as
> null.
> Any suggestions?
|||"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:DD2FA7A5-A0F2-4BFF-85E9-42533F4E423C@.microsoft.com...
> Here's an example...
> The table contains this data, all items are varchar
>
> 3261 1317
> 3261 Non-Client
> 3261 2
> 3261 mmarkowitz
> I'd like to turn this into...
> 3261 1317 Non-client 2 mmarkowitz
I'm not sure if this will help, but you may want to take a look at the
GROUP BY WITH ROLLUP and WITH CUBE commands. It may work for what you are
after.
SELECT Col1, Max(Col2)
FROM tablename
GROUP BY Col1
WITH ROLLUP
HTH
Rick Sawtell
MCT, MCSD, MCDBA
|||SELECT col1, MAX(col2), MAX(col3), MAX(col4), ...
FROM YourTable
GROUP BY col1
David Portas
SQL Server MVP
|||I don't think this will work, he wants to flatten one ofthe two columns in
his table out into multiple columns...
http://www.aspfaq.com/
(Reverse address to reply.)
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1103306604.369012.58920@.z14g2000cwz.googlegro ups.com...
> SELECT col1, MAX(col2), MAX(col3), MAX(col4), ...
> FROM YourTable
> GROUP BY col1
> --
> David Portas
> SQL Server MVP
> --
>
|||OK. Looks to me like 5 columns but I guess that's just presentational ;-)
Tough to pivot without an explicit attribute for the column.
David Portas
SQL Server MVP
|||"Aaron [SQL Server MVP]" wrote:
> This looks like a PIVOT.
Actually it is the RESULT of a pivot, which is why it is spread out
vertically like that.
But I did figure out a "trick". After reading the page you sent, I combined
their technique of ISNULL (instead of CASE) with MIN, and presto.
Thanks!
(anyone interested in the code?)
Showing posts with label grouping. Show all posts
Showing posts with label grouping. Show all posts
Friday, March 16, 2012
"SUM" of a varchar column?
I have a table that contains a number of columns containing either a varchar
value, or null. There are multiple rows per grouping. I would like to colapse
the multiple rows into a single row, either by appending the strings to each
other, or simply selecting the first (or last) one.
If it was a number field I could do a SUM, MAX or MIN. SUM doesn't work, for
obvious reasons. I thought MAX would work, but MAX returns only one value for
all of the columns (as opposed to one per column) and the rest are left as
null.
Any suggestions?Here's an example...
The table contains this data, all items are varchar
3261 1317
3261 Non-Client
3261 2
3261 mmarkowitz
I'd like to turn this into...
3261 1317 Non-client 2 mmarkowitz|||This looks like a PIVOT. Can you flatten this table out on the client? If
not, see http://www.aspfaq.com/2462
--
http://www.aspfaq.com/
(Reverse address to reply.)
"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:7838E3D4-CD8D-46EB-A75F-D069B30EE9AB@.microsoft.com...
> I have a table that contains a number of columns containing either a
varchar
> value, or null. There are multiple rows per grouping. I would like to
colapse
> the multiple rows into a single row, either by appending the strings to
each
> other, or simply selecting the first (or last) one.
> If it was a number field I could do a SUM, MAX or MIN. SUM doesn't work,
for
> obvious reasons. I thought MAX would work, but MAX returns only one value
for
> all of the columns (as opposed to one per column) and the rest are left as
> null.
> Any suggestions?|||"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:DD2FA7A5-A0F2-4BFF-85E9-42533F4E423C@.microsoft.com...
> Here's an example...
> The table contains this data, all items are varchar
>
> 3261 1317
> 3261 Non-Client
> 3261 2
> 3261 mmarkowitz
> I'd like to turn this into...
> 3261 1317 Non-client 2 mmarkowitz
I'm not sure if this will help, but you may want to take a look at the
GROUP BY WITH ROLLUP and WITH CUBE commands. It may work for what you are
after.
SELECT Col1, Max(Col2)
FROM tablename
GROUP BY Col1
WITH ROLLUP
HTH
Rick Sawtell
MCT, MCSD, MCDBA|||SELECT col1, MAX(col2), MAX(col3), MAX(col4), ...
FROM YourTable
GROUP BY col1
--
David Portas
SQL Server MVP
--|||I don't think this will work, he wants to flatten one ofthe two columns in
his table out into multiple columns...
--
http://www.aspfaq.com/
(Reverse address to reply.)
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1103306604.369012.58920@.z14g2000cwz.googlegroups.com...
> SELECT col1, MAX(col2), MAX(col3), MAX(col4), ...
> FROM YourTable
> GROUP BY col1
> --
> David Portas
> SQL Server MVP
> --
>|||OK. Looks to me like 5 columns but I guess that's just presentational ;-)
Tough to pivot without an explicit attribute for the column.
--
David Portas
SQL Server MVP
--|||"Aaron [SQL Server MVP]" wrote:
> This looks like a PIVOT.
Actually it is the RESULT of a pivot, which is why it is spread out
vertically like that.
But I did figure out a "trick". After reading the page you sent, I combined
their technique of ISNULL (instead of CASE) with MIN, and presto.
Thanks!
(anyone interested in the code?)
value, or null. There are multiple rows per grouping. I would like to colapse
the multiple rows into a single row, either by appending the strings to each
other, or simply selecting the first (or last) one.
If it was a number field I could do a SUM, MAX or MIN. SUM doesn't work, for
obvious reasons. I thought MAX would work, but MAX returns only one value for
all of the columns (as opposed to one per column) and the rest are left as
null.
Any suggestions?Here's an example...
The table contains this data, all items are varchar
3261 1317
3261 Non-Client
3261 2
3261 mmarkowitz
I'd like to turn this into...
3261 1317 Non-client 2 mmarkowitz|||This looks like a PIVOT. Can you flatten this table out on the client? If
not, see http://www.aspfaq.com/2462
--
http://www.aspfaq.com/
(Reverse address to reply.)
"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:7838E3D4-CD8D-46EB-A75F-D069B30EE9AB@.microsoft.com...
> I have a table that contains a number of columns containing either a
varchar
> value, or null. There are multiple rows per grouping. I would like to
colapse
> the multiple rows into a single row, either by appending the strings to
each
> other, or simply selecting the first (or last) one.
> If it was a number field I could do a SUM, MAX or MIN. SUM doesn't work,
for
> obvious reasons. I thought MAX would work, but MAX returns only one value
for
> all of the columns (as opposed to one per column) and the rest are left as
> null.
> Any suggestions?|||"Maury Markowitz" <MauryMarkowitz@.discussions.microsoft.com> wrote in
message news:DD2FA7A5-A0F2-4BFF-85E9-42533F4E423C@.microsoft.com...
> Here's an example...
> The table contains this data, all items are varchar
>
> 3261 1317
> 3261 Non-Client
> 3261 2
> 3261 mmarkowitz
> I'd like to turn this into...
> 3261 1317 Non-client 2 mmarkowitz
I'm not sure if this will help, but you may want to take a look at the
GROUP BY WITH ROLLUP and WITH CUBE commands. It may work for what you are
after.
SELECT Col1, Max(Col2)
FROM tablename
GROUP BY Col1
WITH ROLLUP
HTH
Rick Sawtell
MCT, MCSD, MCDBA|||SELECT col1, MAX(col2), MAX(col3), MAX(col4), ...
FROM YourTable
GROUP BY col1
--
David Portas
SQL Server MVP
--|||I don't think this will work, he wants to flatten one ofthe two columns in
his table out into multiple columns...
--
http://www.aspfaq.com/
(Reverse address to reply.)
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1103306604.369012.58920@.z14g2000cwz.googlegroups.com...
> SELECT col1, MAX(col2), MAX(col3), MAX(col4), ...
> FROM YourTable
> GROUP BY col1
> --
> David Portas
> SQL Server MVP
> --
>|||OK. Looks to me like 5 columns but I guess that's just presentational ;-)
Tough to pivot without an explicit attribute for the column.
--
David Portas
SQL Server MVP
--|||"Aaron [SQL Server MVP]" wrote:
> This looks like a PIVOT.
Actually it is the RESULT of a pivot, which is why it is spread out
vertically like that.
But I did figure out a "trick". After reading the page you sent, I combined
their technique of ISNULL (instead of CASE) with MIN, and presto.
Thanks!
(anyone interested in the code?)
Saturday, February 25, 2012
"Next Page" is extremely slow - like it's requerying
I have a report with a single dataset, 3-levels of table grouping, and
returns 5 pages. When I preview the report in VStudio, it returns the 5
pages and I can navigate the pages real quickly. The problem is, when I run
it online via the RS front-end and click "Next Page," it takes a good 30
seconds to load the subsequent page or pages. The query itself runs in about
45 seconds, but why is the paging not near instantaneous?
Thanks,
jI hope you must have asked some questions yourself like
1. Is this report is slow or all the reports are slow?
2. Is your dev environment and production is different then how fast is your
production machine, is the machine slow (database server)?
3. Is Cache enabled/disabled ?
4. Are you doing the dev and online chking on the same machine ?
Probabily you can go to configuration from RS manager screen and check for
the cache options.
Amarnath
"Jordan" wrote:
> I have a report with a single dataset, 3-levels of table grouping, and
> returns 5 pages. When I preview the report in VStudio, it returns the 5
> pages and I can navigate the pages real quickly. The problem is, when I run
> it online via the RS front-end and click "Next Page," it takes a good 30
> seconds to load the subsequent page or pages. The query itself runs in about
> 45 seconds, but why is the paging not near instantaneous?
> Thanks,
> j
>
>|||Absolutely.
1. This report is slow. All the other reports paginate just fine, even those
that use the same datasources.
2. It's a production machine.
3. It's not caching a temporary copy, but neither is any of the other
reports. I set the caching (every 10 minutes) and it's 99% faster, but I
still don't understand. The report shouldn't refresh itself on every page,
only every time it is run.
4. Yes. Would this really matter?
Thanks,
j
"Amarnath" <Amarnath@.discussions.microsoft.com> wrote in message
news:DC42BC35-CD2A-42EB-BADA-E7FA77FCCA5F@.microsoft.com...
>I hope you must have asked some questions yourself like
> 1. Is this report is slow or all the reports are slow?
> 2. Is your dev environment and production is different then how fast is
> your
> production machine, is the machine slow (database server)?
> 3. Is Cache enabled/disabled ?
> 4. Are you doing the dev and online chking on the same machine ?
> Probabily you can go to configuration from RS manager screen and check for
> the cache options.
> Amarnath
> "Jordan" wrote:
>> I have a report with a single dataset, 3-levels of table grouping, and
>> returns 5 pages. When I preview the report in VStudio, it returns the 5
>> pages and I can navigate the pages real quickly. The problem is, when I
>> run
>> it online via the RS front-end and click "Next Page," it takes a good 30
>> seconds to load the subsequent page or pages. The query itself runs in
>> about
>> 45 seconds, but why is the paging not near instantaneous?
>> Thanks,
>> j
>>|||Absolutely.
1. This report is slow. All the other reports paginate just fine, even those
that use the same datasources.
2. It's a production machine.
3. It's not caching a temporary copy, but neither is any of the other
reports. I set the caching (every 10 minutes) and it's 99% faster, but I
still don't understand. The report shouldn't refresh itself on every page,
only every time it is run.
4. Yes. Would this really matter?
Thanks,
j
returns 5 pages. When I preview the report in VStudio, it returns the 5
pages and I can navigate the pages real quickly. The problem is, when I run
it online via the RS front-end and click "Next Page," it takes a good 30
seconds to load the subsequent page or pages. The query itself runs in about
45 seconds, but why is the paging not near instantaneous?
Thanks,
jI hope you must have asked some questions yourself like
1. Is this report is slow or all the reports are slow?
2. Is your dev environment and production is different then how fast is your
production machine, is the machine slow (database server)?
3. Is Cache enabled/disabled ?
4. Are you doing the dev and online chking on the same machine ?
Probabily you can go to configuration from RS manager screen and check for
the cache options.
Amarnath
"Jordan" wrote:
> I have a report with a single dataset, 3-levels of table grouping, and
> returns 5 pages. When I preview the report in VStudio, it returns the 5
> pages and I can navigate the pages real quickly. The problem is, when I run
> it online via the RS front-end and click "Next Page," it takes a good 30
> seconds to load the subsequent page or pages. The query itself runs in about
> 45 seconds, but why is the paging not near instantaneous?
> Thanks,
> j
>
>|||Absolutely.
1. This report is slow. All the other reports paginate just fine, even those
that use the same datasources.
2. It's a production machine.
3. It's not caching a temporary copy, but neither is any of the other
reports. I set the caching (every 10 minutes) and it's 99% faster, but I
still don't understand. The report shouldn't refresh itself on every page,
only every time it is run.
4. Yes. Would this really matter?
Thanks,
j
"Amarnath" <Amarnath@.discussions.microsoft.com> wrote in message
news:DC42BC35-CD2A-42EB-BADA-E7FA77FCCA5F@.microsoft.com...
>I hope you must have asked some questions yourself like
> 1. Is this report is slow or all the reports are slow?
> 2. Is your dev environment and production is different then how fast is
> your
> production machine, is the machine slow (database server)?
> 3. Is Cache enabled/disabled ?
> 4. Are you doing the dev and online chking on the same machine ?
> Probabily you can go to configuration from RS manager screen and check for
> the cache options.
> Amarnath
> "Jordan" wrote:
>> I have a report with a single dataset, 3-levels of table grouping, and
>> returns 5 pages. When I preview the report in VStudio, it returns the 5
>> pages and I can navigate the pages real quickly. The problem is, when I
>> run
>> it online via the RS front-end and click "Next Page," it takes a good 30
>> seconds to load the subsequent page or pages. The query itself runs in
>> about
>> 45 seconds, but why is the paging not near instantaneous?
>> Thanks,
>> j
>>|||Absolutely.
1. This report is slow. All the other reports paginate just fine, even those
that use the same datasources.
2. It's a production machine.
3. It's not caching a temporary copy, but neither is any of the other
reports. I set the caching (every 10 minutes) and it's 99% faster, but I
still don't understand. The report shouldn't refresh itself on every page,
only every time it is run.
4. Yes. Would this really matter?
Thanks,
j
Sunday, February 19, 2012
"Hide Duplicates" within Details Grouping
I'm having problems using the "Hide Duplicates" function within the Details
Grouping of a table in a report (using RS SP2, SQL Server 2000, Visual Studio
2003).
The details grouping has two rows, set out as follows:
| CallFlow Name |
| | Outcome Type | Grammar Type | Meaning | Totals
There are about 10 different "CallFlows", each of which is displayed as
above. There are several possible "Outcome Types"(Success, Fail, Hangup etc),
and I want to prevent duplicates within the scope of the Callflow as shown
below:
| CallFlow Name 1 |
| | Success ...
| | Success ...
| | Success ...
The problem is, when setting "Hide Duplicates" for "Outcome Type", it hides
*ALL* of the duplicated information even in the next Callflow. Is there a
conditional expression or formatting that can be applied to this field so
that duplicates are only hidden for that particular table?
ThanksAll the fields should be in one row of the report layout table.
| CallFlow Name | Outcome Type | Grammar Type | Meaning | Totals
In the table's properties, add a group for the CallFlow field.
In the CallFlow cell's properties, click on the Hide Duplicates dropdown
and select the new group created.
GeoSynch
"Laura-Anne" <Laura-Anne@.discussions.microsoft.com> wrote in message
news:B64F7CCE-F9EB-46C1-9C95-87012913AD82@.microsoft.com...
> I'm having problems using the "Hide Duplicates" function within the Details
> Grouping of a table in a report (using RS SP2, SQL Server 2000, Visual Studio
> 2003).
> The details grouping has two rows, set out as follows:
> | CallFlow Name |
> | | Outcome Type | Grammar Type | Meaning | Totals
> There are about 10 different "CallFlows", each of which is displayed as
> above. There are several possible "Outcome Types"(Success, Fail, Hangup etc),
> and I want to prevent duplicates within the scope of the Callflow as shown
> below:
> | CallFlow Name 1 |
> | | Success ...
> | | Success ...
> | | Success ...
> The problem is, when setting "Hide Duplicates" for "Outcome Type", it hides
> *ALL* of the duplicated information even in the next Callflow. Is there a
> conditional expression or formatting that can be applied to this field so
> that duplicates are only hidden for that particular table?
> Thanks
>|||That worked perfectly - thank you very much!
"GeoSynch" wrote:
> All the fields should be in one row of the report layout table.
> | CallFlow Name | Outcome Type | Grammar Type | Meaning | Totals
> In the table's properties, add a group for the CallFlow field.
> In the CallFlow cell's properties, click on the Hide Duplicates dropdown
> and select the new group created.
>
> GeoSynch
>
> "Laura-Anne" <Laura-Anne@.discussions.microsoft.com> wrote in message
> news:B64F7CCE-F9EB-46C1-9C95-87012913AD82@.microsoft.com...
> > I'm having problems using the "Hide Duplicates" function within the Details
> > Grouping of a table in a report (using RS SP2, SQL Server 2000, Visual Studio
> > 2003).
> >
> > The details grouping has two rows, set out as follows:
> >
> > | CallFlow Name |
> > | | Outcome Type | Grammar Type | Meaning | Totals
> >
> > There are about 10 different "CallFlows", each of which is displayed as
> > above. There are several possible "Outcome Types"(Success, Fail, Hangup etc),
> > and I want to prevent duplicates within the scope of the Callflow as shown
> > below:
> >
> > | CallFlow Name 1 |
> > | | Success ...
> > | | Success ...
> > | | Success ...
> >
> > The problem is, when setting "Hide Duplicates" for "Outcome Type", it hides
> > *ALL* of the duplicated information even in the next Callflow. Is there a
> > conditional expression or formatting that can be applied to this field so
> > that duplicates are only hidden for that particular table?
> >
> > Thanks
> >
>
>
Grouping of a table in a report (using RS SP2, SQL Server 2000, Visual Studio
2003).
The details grouping has two rows, set out as follows:
| CallFlow Name |
| | Outcome Type | Grammar Type | Meaning | Totals
There are about 10 different "CallFlows", each of which is displayed as
above. There are several possible "Outcome Types"(Success, Fail, Hangup etc),
and I want to prevent duplicates within the scope of the Callflow as shown
below:
| CallFlow Name 1 |
| | Success ...
| | Success ...
| | Success ...
The problem is, when setting "Hide Duplicates" for "Outcome Type", it hides
*ALL* of the duplicated information even in the next Callflow. Is there a
conditional expression or formatting that can be applied to this field so
that duplicates are only hidden for that particular table?
ThanksAll the fields should be in one row of the report layout table.
| CallFlow Name | Outcome Type | Grammar Type | Meaning | Totals
In the table's properties, add a group for the CallFlow field.
In the CallFlow cell's properties, click on the Hide Duplicates dropdown
and select the new group created.
GeoSynch
"Laura-Anne" <Laura-Anne@.discussions.microsoft.com> wrote in message
news:B64F7CCE-F9EB-46C1-9C95-87012913AD82@.microsoft.com...
> I'm having problems using the "Hide Duplicates" function within the Details
> Grouping of a table in a report (using RS SP2, SQL Server 2000, Visual Studio
> 2003).
> The details grouping has two rows, set out as follows:
> | CallFlow Name |
> | | Outcome Type | Grammar Type | Meaning | Totals
> There are about 10 different "CallFlows", each of which is displayed as
> above. There are several possible "Outcome Types"(Success, Fail, Hangup etc),
> and I want to prevent duplicates within the scope of the Callflow as shown
> below:
> | CallFlow Name 1 |
> | | Success ...
> | | Success ...
> | | Success ...
> The problem is, when setting "Hide Duplicates" for "Outcome Type", it hides
> *ALL* of the duplicated information even in the next Callflow. Is there a
> conditional expression or formatting that can be applied to this field so
> that duplicates are only hidden for that particular table?
> Thanks
>|||That worked perfectly - thank you very much!
"GeoSynch" wrote:
> All the fields should be in one row of the report layout table.
> | CallFlow Name | Outcome Type | Grammar Type | Meaning | Totals
> In the table's properties, add a group for the CallFlow field.
> In the CallFlow cell's properties, click on the Hide Duplicates dropdown
> and select the new group created.
>
> GeoSynch
>
> "Laura-Anne" <Laura-Anne@.discussions.microsoft.com> wrote in message
> news:B64F7CCE-F9EB-46C1-9C95-87012913AD82@.microsoft.com...
> > I'm having problems using the "Hide Duplicates" function within the Details
> > Grouping of a table in a report (using RS SP2, SQL Server 2000, Visual Studio
> > 2003).
> >
> > The details grouping has two rows, set out as follows:
> >
> > | CallFlow Name |
> > | | Outcome Type | Grammar Type | Meaning | Totals
> >
> > There are about 10 different "CallFlows", each of which is displayed as
> > above. There are several possible "Outcome Types"(Success, Fail, Hangup etc),
> > and I want to prevent duplicates within the scope of the Callflow as shown
> > below:
> >
> > | CallFlow Name 1 |
> > | | Success ...
> > | | Success ...
> > | | Success ...
> >
> > The problem is, when setting "Hide Duplicates" for "Outcome Type", it hides
> > *ALL* of the duplicated information even in the next Callflow. Is there a
> > conditional expression or formatting that can be applied to this field so
> > that duplicates are only hidden for that particular table?
> >
> > Thanks
> >
>
>
Subscribe to:
Posts (Atom)
