ColdFusion 8 query issues - coldfusion

I am using ColdFusion 8 and have query I built using SELECT Count(dog) as stuff. This works fine on one page but when I use it, changing the parameters of course, it boggs my server down. All I need is to count the items in the db tables, return how many dogs, cats, sheep, etc. and show the count and the name. Did it with the SELECT Count the first time but can't seem to get it to work this time. Is there a way I can do the same thing by not using the Count()? And forgot to mention I am using an old Sybase db...

can't you do the following...
<cfquery name="getpetstuff" datasource="mydatabase" timeout="30">
Select dogs, count(*) as mycount
from allpets
group by dogs
</cfquery>

Adding indexes to tables will solve many performance problems in MS-SQL which has it's roots in Sybase.
Try adding an index that just contains the dogs in the allpets table.

Related

Get slicer to affect other tab in Power Bi

I have a report like this:
It's got three tabs, based on three separate SQL queries (and Power bi queries) of our database.
One tab is based on all the subjects we have in our program
One tab is a query of a database with all the staff associated with all the
subjects in our database
The third tab (that I am working on now) is from a query of all the subjects in our database that need reconsent. The way I envision all three tabs working is that you start in the first tab, filter to the subjects you care about, and then those slicers/filters affect the next two tabs.
My problem is:
I dont know how to get the slicers/filters in the first tab to affect the others. I was able to get the second tab linked by just merging those two queries (there's pretty much 100% overlap) and just using "one" dataset for both.
I've tried "manage relationships" and created a relationship between the first query subject mrn and the third query subject mrn... but even though there's a 'relationship' between the two... thats not enough for slicers on the first tab to affect anything on the third tab. How do I do that?
I asked this on the power bi forum as well and was given some followup questions that I'll add info from here:
The sync slicers setting is on:
And if I go look at the table on the third tab, it says a bunch of slicers are currently affecting it:
(I changed the slicer values between taking these screenshots, dates look different in each)
Also here is a photo of the relationship between queries in the model:
So to repeat/rephrase:
Let's say I use slicers on the first tab to filter to 10 people coming in the next week (which are in one query). Lets say 1 of those people exists in the third query as someone who needs reconsent. How do I get only that one guy to show up on the third tab with his info from that query?

Power Query Preview Top and Order By

Is there a way to keep Power Query from using ORDER BY when getting preview data?
I am trying to work with a table in SQL Server that contains 373 million records. The Power Query Editor wants to produce a preview. The M code for the "Navigate" step looks like...
Source{[Schema="dbo",Item="TableName"]}[Data]
...and it produces SQL that looks like...
select top 4096 [$Ordered].[ThisID]
, [$Ordered].[ThatID]
, [$Ordered].
<bunch
of other
columns>
from [dbo].[TableName] as [$Ordered]
order by [$Ordered].[ThisID]
, [$Ordered].[ThatID]
ThisID and ThatID are ints. These two columns make up the primary key, so the combination of them is indexed. But indexed or not, this query wants to order 373 million records by 2 variables before returning a handful of rows that may as well be random given the context. This query could take a very long time (hours?) to run, so it times out and I have nothing to work with (not even column names). What I need would take less than 1 second. (Basically, remove the ORDER BY clause.)
How can I change the number of rows returned? I think I need 100 - 400, not 4096.
How can I tell the Power Query Editor to not care about which records are in the preview (no ORDER BY)?
These feel like they should be settings (not M code) but I am not seeing anything in the options to control this behavior.
I have a bunch of other tables in my model. Will this one table need to be done using pass-thru SQL? Will that still work in Direct Query mode?
Can this problem be solved by changing the M code in the Advanced Editor?

Select Columns from multiple tables - Django

I am trying to select all the columns from one table and only a single column from the second table using the Django ORM.The two tables are related by a foreign key but the column in the second table which i want, is not related, so using select_related doesn't work.
I used
FirstTable.objects.filter().values("All first table columns separated by a comma","second tablename__column name")
and this worked fine. Since, the columns are very large in number, i do not want to list all of them in "values". So, i am looking for an easy way to do this.
Thanks for your help
EDIT:
Thanks for the help! I was able to get it working by using annotate like the following.
FirstTable.objects.filter().annotate(variable_name=F("SecondtableFieldName"))
You Can use the extra method in this.
FirstTable.objects.filter().extra("write down here what every yo want")

Apex 5.1: Create a Select List with Database Column Values

I have a column in my database (CAMPAIGN_NAME) and I want my users to be able to select any of the current campaigns in the system so they can see some charts by Campaign. Since we add campaigns all the time, I cannot use a list of Static Values, I need to be able to retrieve the current values from the CAMPAIGN_NAME column for the user to select one or several. I tried using a Select List with a List Of Values from an SQL Query (SELECT CAMPAIGN_NAME FROM LEAD_MATRIX) but it doesn't do the trick. Do you happen to know how to workaround on this? Any help will be much appreciated!
Good database design would assume that there is also a unique id for each name.
With that said try the following for your dynamic lov:
SELECT CAMPAIGN_NAME as display_val
,CAMPAIGN_ID as read_val
FROM LEAD_MATRIX
Order by CAMPAIGN_NAME
If you don't have a unique id for each name I'd encourage you to get one.
You'll need to ensure that your reports are leveraging this Id as well.
Of course it is possible to make LOV using such query as below:
SELECT CAMPAIGN_NAME AS D ,CAMPAIGN_NAME AS R FROM LEAD_MATRIX
But it's not good practice. I recommend you to create primary key and store that key value in target tables (for example for report purposes).
Then your query should be like:
SELECT CAMPAIGN_NAME AS D ,CAMPAIGN_ID AS R FROM LEAD_MATRIX

Power Query - Select Columns from table instead of removing afterwards

The default behaviour when importing data from a database table (such as SQL Server) is to bring in all columns and then select which columns you would like to remove.
Is there a way to do the reverse? ie Select which columns you want from a table? Preferably without using a Native SQL solution.
M:
let
db = Sql.Databases("sqlserver.database.url"){[Name="DatabaseName"]}[Data],
Sales_vDimCustomer = db{[Schema="Sales",Item="vDimCustomer"]}[Data],
remove_columns = Table.RemoveColumns(Sales_vDimCustomer,{"Key", "Code","Column1","Column2","Column3","Column4","Column5","Column6","Column7","Column8","Column9","Column10"})
in
remove_columns
The snippet above shows the connection and subsequent removal.
Compared to the native SQL way way:
= Sql.Database("sqlserver.database.url", "DatabaseName", [Query="
SELECT Name,
Representative,
Status,
DateLastModified,
UserLastModified,
ExtractionDate
FROM Sales.vDimCustomer
"])
I can't see much documentation on the }[Data], value in the step so was hoping maybe that I could hijack that field to specify which fields from that data.
Any ideas would be great! :)
My first concern is that when this gets compiled down to SQL, it gets sent as two queries (as watched in ExpressProfiler).
The first query removes the selected columns and the second selects all columns.
My second concern is that if a column is added to or removed from the database then it could crash my report (additional columns in Excel Tables jump your structured table language formulas to the wrong column). This is not a problem using Native SQL as it just won't select the new column and would actually crash if the column was removed which is something I would want to know about.
Ouch that was actually easy after I had another think and a look at the docs.
let
db = Sql.Databases("sqlserver.database.url"){[Name="DatabaseName"]}[Data],
Sales_vDimCustomer = Table.SelectColumns(
(db{[Schema="Sales",Item="vDimCustomer"]}[Data],
{
"Name",
"Representative",
"Status",
"DateLastModified",
"UserLastModified",
"ExtractionDate"
}
)
in
Sales_vDimCustomer
This also loaded much faster than the other way and only generated one SQL requested instead of two.