Monday, March 12, 2012
Requesting help with complicated aggregation of a table
ossible of 1-9, * (invalid) and " " (space). The way I am trying to do this in MySQL is like this:
SELECT con_id, count(q2*) (q3*) (q4*)
FROM db_data where con_id in (select con_id FROM congregs where syn_id = "1A")
GROUP BY q2, q3, q4, con_id
The following SQL Statement works with the following output but have not yet been able to get the above statement working
SELECT q3, count(*)
FROM db_data
WHERE con_id=1234567
GROUP BY q3
-- Output --
q3 count(*)
7
*1
14
238
33
I have 415 columns in the db_data table and am wondering if there is any way to write a query that does the above to the entire table (or a selection of rows "from row # to row #). To further compound the problem (and greater sweeten a solution) the poss
ible outputs change depending upon the question. So in q3, in addition to the * and blank possibilities, there can be 1, 2 or 3; in q133 there is a possible 1-7 plus the * and blank.
I can not get the above query to work in SQL Server, only MySQL.
Any help would be welcomed
Thank you
mchemnitz,
Do you mean the following?
SELECT con_id, count(q2), count(q3), count (q4)
FROM db_data where con_id in (select con_id FROM congregs where syn_id =
"1A")
GROUP BY con_id
ORDER BY con_id, q2, q3, q4
The above is COUNT(ALL col), but you might prefer COUNT (DISTINCT col).
Russell Fields
"mchemnitz" <mchemnitz@.discussions.microsoft.com> wrote in message
news:17E24782-1BC0-40C3-BCE3-EB2ED78F57D0@.microsoft.com...
> I am moving our Databases from My SQL to SQL Server 2000 and am now
starting to use views to access data. Very nice feature and worth the
upgrade. I need to rewrite a report that we currently have as an Excel file
that aggregates tinyint data that has possible of 1-9, * (invalid) and " "
(space). The way I am trying to do this in MySQL is like this:
> SELECT con_id, count(q2*) (q3*) (q4*)
> FROM db_data where con_id in (select con_id FROM congregs where syn_id =
"1A")
> GROUP BY q2, q3, q4, con_id
> The following SQL Statement works with the following output but have not
yet been able to get the above statement working
> SELECT q3, count(*)
> FROM db_data
> WHERE con_id=1234567
> GROUP BY q3
> -- Output --
> q3 count(*)
> 7
> * 1
> 1 4
> 2 38
> 3 3
> I have 415 columns in the db_data table and am wondering if there is any
way to write a query that does the above to the entire table (or a selection
of rows "from row # to row #). To further compound the problem (and greater
sweeten a solution) the possible outputs change depending upon the question.
So in q3, in addition to the * and blank possibilities, there can be 1, 2 or
3; in q133 there is a possible 1-7 plus the * and blank.
> I can not get the above query to work in SQL Server, only MySQL.
> Any help would be welcomed
> Thank you
Requesting help with complicated aggregation of a table
to use views to access data. Very nice feature and worth the upgrade. I n
eed to rewrite a report that we currently have as an Excel file that aggrega
tes tinyint data that has p
ossible of 1-9, * (invalid) and " " (space). The way I am trying to do this
in mysql is like this:
SELECT con_id, count(q2*) (q3*) (q4*)
FROM db_data where con_id in (select con_id FROM congregs where syn_id = "1A
")
GROUP BY q2, q3, q4, con_id
The following SQL Statement works with the following output but have not yet
been able to get the above statement working
SELECT q3, count(*)
FROM db_data
WHERE con_id=1234567
GROUP BY q3
-- Output --
q3 count(*)
7
* 1
1 4
2 38
3 3
I have 415 columns in the db_data table and am wondering if there is any way
to write a query that does the above to the entire table (or a selection of
rows "from row # to row #). To further compound the problem (and greater s
weeten a solution) the poss
ible outputs change depending upon the question. So in q3, in addition to t
he * and blank possibilities, there can be 1, 2 or 3; in q133 there is a pos
sible 1-7 plus the * and blank.
I can not get the above query to work in SQL Server, only MySQL.
Any help would be welcomed
Thank youmchemnitz,
Do you mean the following?
SELECT con_id, count(q2), count(q3), count (q4)
FROM db_data where con_id in (select con_id FROM congregs where syn_id =
"1A")
GROUP BY con_id
ORDER BY con_id, q2, q3, q4
The above is COUNT(ALL col), but you might prefer COUNT (DISTINCT col).
Russell Fields
"mchemnitz" <mchemnitz@.discussions.microsoft.com> wrote in message
news:17E24782-1BC0-40C3-BCE3-EB2ED78F57D0@.microsoft.com...
> I am moving our Databases from My SQL to SQL Server 2000 and am now
starting to use views to access data. Very nice feature and worth the
upgrade. I need to rewrite a report that we currently have as an Excel file
that aggregates tinyint data that has possible of 1-9, * (invalid) and " "
(space). The way I am trying to do this in mysql is like this:
> SELECT con_id, count(q2*) (q3*) (q4*)
> FROM db_data where con_id in (select con_id FROM congregs where syn_id =
"1A")
> GROUP BY q2, q3, q4, con_id
> The following SQL Statement works with the following output but have not
yet been able to get the above statement working
> SELECT q3, count(*)
> FROM db_data
> WHERE con_id=1234567
> GROUP BY q3
> -- Output --
> q3 count(*)
> 7
> * 1
> 1 4
> 2 38
> 3 3
> I have 415 columns in the db_data table and am wondering if there is any
way to write a query that does the above to the entire table (or a selection
of rows "from row # to row #). To further compound the problem (and greater
sweeten a solution) the possible outputs change depending upon the question.
So in q3, in addition to the * and blank possibilities, there can be 1, 2 or
3; in q133 there is a possible 1-7 plus the * and blank.
> I can not get the above query to work in SQL Server, only MySQL.
> Any help would be welcomed
> Thank you
Request for info - detecting DB changes and batching for e-mail
I have a .NET app recently ported from 1.1 to 2.0 with a pending feature request. I'd first like to state that I'm not asking anyone for the programmatic answer, unless of course, you'd like to provide it. I'm simply asking the best way to accomplish this task with the tools I have available to me (VS 2005, SQL 2000 and 2005). I do not consider myself a professional .NET or T-SQL programmer but I do have a good understanding of the technologies so that I can find what I need to know once I know I'm going about something the right way.
The application I wrote, from scratch, manages News, Featured Connections, and FAQs for a web site. It was designed in a multi-layer approach where there are:
items -> assigned to categories -> assigned to users
So if user Fred is granted rights to category A, when he authenticates to the app he can Add/Change/Delete any item in category A. Simple enough. But also what Fred can do is see all the other items other users have created and *schedule* any relevant item related to his web page to appear within his own items even tho he has no rights to change that item in the admin interface.
The feature request is a notification service, so that Fred gets an e-mail when someone has added a new item or edited an existing one. I don't want Fred to get an e-mail *every* time an item is created or edited, that would be big bother and would generate lots of e-mails. What I'd like to do is send Fred an e-mail sometime in the middle of the night that informs him of the items added or changed since his last login, so that at his choosing he can go into the admin interface and schedule one or more of those items for his page.
Should I just write a new console app that does this, compile it and schedule the .EXE to run at midnight? Or is there a better way to leverage the new features in SQL 2005 (extended strored procs, triggers) and .NET to do this a better way? Currently, the DB is in SQL 2000 but I have no problems moving it to SQL 2005 if that helps me in some way. Thanks in advance for your comments.
...Bill
Table UserLastNotify
ID (useridtype - int/uid/whatever)
LastChangeSeen int
Create trigger on your categories table, recording a changeid, time,categoryid that changed to an auditCategories table.
Create a stored procedure (or cursor) that checks the last changeid in the auditCategories table to their entry in the UserLastNotify table, and then filter based on whatever criteria you want them to be notified about. Then generate the email, and update the UserLastNotify table with the current max of auditCategories (alternatively you can also use the max of the auditCategories id that you generated an email for them - since any higher you either haven't seen, or don't care about).
Create an sql job that runs at midnight every night that calls your stored procedure.
Wednesday, March 7, 2012
Reposting: Expand All / Collapse All feature
report designed with RS ? I find it annoying to click every + sign to open
all nodes. Maybe, there is an easier way that I do not know.
2. When the same drill-down report is partially expanded and I export the
report as-it-is to Excel, the exported file has only the partial
data.....only the data that was expanded. The other data is never exported.
What can I do to resolve this ?
Please respond.Yes, you can do this.
Step 1) Create a textbox outside of your table/matrix. Give it a name, e.g.
Toggler. Step 2) Highlight the row you want to hide/show. Set its Visibility
Hidden property to False, and use the textbox you created at Step 1 as the
ToggleItem property.
Charles Kangai, MCT, MCDBA
"DC" wrote:
> 1. Is there a way to Expand All nodes or Collapse All Nodes in a drill-down
> report designed with RS ? I find it annoying to click every + sign to open
> all nodes. Maybe, there is an easier way that I do not know.
> 2. When the same drill-down report is partially expanded and I export the
> report as-it-is to Excel, the exported file has only the partial
> data.....only the data that was expanded. The other data is never exported.
> What can I do to resolve this ?
> Please respond.
>
>|||Also, if you put the visibility settings at Group line level (i.e.
highlight the whole group by clicking on the left hand tab) rather cell
level, when you export to Excel you'll get full outlining/grouping for
ALL data regardless of how the report is currently 'expanded'. (This
only works with SP1).
Regards
Chris
Charles Kangai wrote:
> Yes, you can do this.
> Step 1) Create a textbox outside of your table/matrix. Give it a
> name, e.g. Toggler. Step 2) Highlight the row you want to hide/show.
> Set its Visibility Hidden property to False, and use the textbox you
> created at Step 1 as the ToggleItem property.
> Charles Kangai, MCT, MCDBA
> "DC" wrote:
> > 1. Is there a way to Expand All nodes or Collapse All Nodes in a
> > drill-down report designed with RS ? I find it annoying to click
> > every + sign to open all nodes. Maybe, there is an easier way that
> > I do not know.
> >
> > 2. When the same drill-down report is partially expanded and I
> > export the report as-it-is to Excel, the exported file has only the
> > partial data.....only the data that was expanded. The other data
> > is never exported. What can I do to resolve this ?
> >
> > Please respond.
> >
> >
> >
> >|||Here is an expand all that I am using:
Create Report parameter: "ExpandAll"
Available Values:
Label: Yes Value: True
Label: No Value: False
Default Value: No
Group1: =Fields!Status.Value
Initial Appearance Expression: =IIF( Parameters!ExpandAll.Value = true,
true, false)
Group2 =Fields!Name.Value
Initial Appearance Expression: =IIF( Parameters!ExpandAll.Value = true,
true, false)
Visibility:
Hidden expression: =IIF( Parameters!ExpandAll.Value = true, False, True)
ToggleItem: Status
Detail records:
Visibility:
Hidden expression: =IIF( Parameters!ExpandAll.Value = true, false, true)
ToggleItem: Name
Good luck,
Chuck Kee
"Chris McGuigan" wrote:
> Also, if you put the visibility settings at Group line level (i.e.
> highlight the whole group by clicking on the left hand tab) rather cell
> level, when you export to Excel you'll get full outlining/grouping for
> ALL data regardless of how the report is currently 'expanded'. (This
> only works with SP1).
> Regards
> Chris
> Charles Kangai wrote:
> > Yes, you can do this.
> > Step 1) Create a textbox outside of your table/matrix. Give it a
> > name, e.g. Toggler. Step 2) Highlight the row you want to hide/show.
> > Set its Visibility Hidden property to False, and use the textbox you
> > created at Step 1 as the ToggleItem property.
> >
> > Charles Kangai, MCT, MCDBA
> >
> > "DC" wrote:
> >
> > > 1. Is there a way to Expand All nodes or Collapse All Nodes in a
> > > drill-down report designed with RS ? I find it annoying to click
> > > every + sign to open all nodes. Maybe, there is an easier way that
> > > I do not know.
> > >
> > > 2. When the same drill-down report is partially expanded and I
> > > export the report as-it-is to Excel, the exported file has only the
> > > partial data.....only the data that was expanded. The other data
> > > is never exported. What can I do to resolve this ?
> > >
> > > Please respond.
> > >
> > >
> > >
> > >
>