ORDER BY FIELD, Query of Queries
Hi, is ther any substitution for this query in CF Query of
Queries?
SELECT * FROM table1 ORDER BY FIELD(col_1, 'apple', 'orange',
'banana')
Query of Queries do not support FIELD but I need a query
ordered in a specific way and i would rather not add a field to my
table for this simple query
Your syntax is not standard sql. There might be a db that
supports it, but none that I know of.
Depending on what you are trying to accomplish, you can
derive your sort column in your initial query. You might not even
need a Q of Q. Maybe something like this:
select case
when col_1 = 'apple' then 1
when col_1 = 'orange' then 2
when col_1 = 'banana' then 3
end as sort_column
from etc
order by sort_column
Similar Messages
-
Problem using DECODE() function with a Query of Queries
I
posted
on my blog about an issue I was having trying to use the PL/SQL
DECODE() function with a Coldfusion Query of Queries. This function
works fine when you query a database for information. However, when
you query another query, it seems that CF doesn't recognize it. I
got errors stating that it found a left parenthesis where it
expected a FROM key word. Here is a simplified version of what I am
trying to do:
quote:
<!--- Simulated query; similar to what I was calling from
my database --->
<cfscript>
qOriginal = queryNew("Name,Email,CountryCode",
"VarChar,VarChar,VarChar");
newRow = queryAddRow(qOriginal, 5);
querySetCell(qOriginal, "Name", "Joe", 1);
querySetCell(qOriginal, "Email", "[email protected]", 1);
querySetCell(qOriginal, "CountryCode", "AMER", 1);
querySetCell(qOriginal, "Name", "Sally", 2);
querySetCell(qOriginal, "Email", "[email protected]", 2);
querySetCell(qOriginal, "CountryCode", "AMER", 2);
querySetCell(qOriginal, "Name", "Bob", 3);
querySetCell(qOriginal, "Email", "[email protected]", 3);
querySetCell(qOriginal, "CountryCode", "ASIA", 3);
querySetCell(qOriginal, "Name", "Mary", 4);
querySetCell(qOriginal, "Email", "[email protected]", 4);
querySetCell(qOriginal, "CountryCode", "EURO", 4);
querySetCell(qOriginal, "Name", "John", 5);
querySetCell(qOriginal, "Email", "[email protected]", 5);
querySetCell(qOriginal, "CountryCode", "EURO", 5);
</cfscript>
<cfquery name="qCountries" dbtype="query">
SELECT DISTINCT(CountryCode) AS CountryCode,
DECODE(states, "AMER", "North America & Canada",
"EURO", "Europe & Africa", "ASIA", "Japan &
Asia","") CountryName
FROM qOriginal
ORDER BY CountryCode
</cfquery>
<cfdump var="#qCountries#">
<!--- ========== END OF CODE ========== --->
So running this returned the following error:
Query Of Queries syntax error.
Encountered "(. Incorrect Select Statement, Expecting a
'FROM', but encountered '(' instead, A select statement should have
a 'FROM' construct.
Does anybody know why this doesn't work? Is it just not
supported? Please note that I have also tried to use the CASE()
function instead of DECODE() and that resulted in basically the
same error. For now I an looping over my distinct query with a
switch statement and manually loading a new query with the data how
I want it. But it would be a lot cleaner and less code to have the
DECODE() to work. Thx!DECODE() is an Oracle function, not generic SQL. Q-of-Q is a
very limited subset of SQL and lacks many functions and clauses
available in standard SQL, especially what you may be used to using
in your particular RDBMS.
See
Query
of Queries user guide
Phil -
Combining results with a Query of Queries - NOT QUITE THERE!!!
I have included a small sample of my database, specifically the four tables I am trying to work with in the hopes that someone can steer me down the right path. Here are the four tables and the bottom is a visual desciption of what I am trying to achieve;
ORDERS
SALES CALLS
ID
SaleDate
TerritoryManager
UserID
SaleDate
TerritoryManager
ID
UserID
426
01-Oct-09
Mike B
10112
10/1/2009
Mike B
253
10112
427
01-Oct-09
Russ C
10115
10/1/2009
Mike B
254
10112
430
01-Oct-09
Jerry W
10145
10/1/2009
Mike B
255
10112
432
01-Oct-09
Ron H
10118
10/1/2009
Mike B
256
10112
433
01-Oct-09
Ron H
10118
10/1/2009
Ron H
257
10118
10/1/2009
Ron H
258
10118
PRODUCTS ORDERED
10/1/2009
Ron H
260
10118
OrderID
Quantity
NewExisting
UserID
10/1/2009
Russ C
261
10115
426
12
0
10112
10/1/2009
Mike B
267
10112
427
2
0
10115
10/1/2009
Mike B
268
10112
427
3
1
10115
430
1
0
10145
USERS
430
1
0
10145
TerritoryManager
Zone
UserID
432
1
0
10118
Mike B
Central
10112
432
1
0
10118
Russ C
Central
10115
432
1
1
10118
Jerry W
Central
10145
432
1
1
10118
Ron H
Central
10118
433
2
1
10120
Don M
Central
10120
Central Zone
Ttl Calls
Ttl Orders
Ttl Items
Ttl New Items
Mike B
5
1
12
1
Russ C
1
1
5
Jerry W
1
2
Ron H
3
2
6
3
I have tried to achieve this result in many ways to no avail. If I try to combine PRODUCTS ORDERED with ORDERS I get an erroneous count. I finally resigned myself to getting all the info I needed with separate queries and then trying to combine them with a query of queries. This worked fine until the last query of queries which timed out with no results. I am a newbie and would appreciate any constructive help with this. I am including my queries below as well;
<cfquery name="qGetOrders" datasource="manna_premier">
SELECT Count(Orders.ID) AS CountOfID,
Orders.UserID AS Orders_UserID,
Users.UserID AS Users_UserID,
Users.TMName
FROM Users INNER JOIN Orders ON Users.[UserID] = Orders.[UserID]
GROUP BY Orders.UserID, Users.UserID, Users.TMName;
</cfquery>
<cfquery name="qGetSalesCalls" datasource="manna_premier">
SELECT Count(Sales_Calls.ID) AS CountOfID,
Users.UserID AS Users_UserID,
Users.TMName,
Sales_Calls.UserID AS Sales_Calls_UserID
FROM Users INNER JOIN Sales_Calls ON Users.[UserID] = Sales_Calls.[UserID]
GROUP BY Sales_Calls.UserID, Users.UserID, Users.TMName;
</cfquery>
<cfquery name="qGetProducts" datasource="manna_premier">
SELECT Count(ProductOrders.OrderID) AS CountOfOrderID,
Sum(ProductOrders.Quantity) AS SumOfQuantity,
Sum(ProductOrders.NewExisting) AS SumOfNewExisting,
ProductOrders.UserID
FROM Orders INNER JOIN ProductOrders ON Orders.[ID] = ProductOrders.[OrderID]
GROUP BY ProductOrders.UserID;
</cfquery>
<cfquery name="qqCombOrd_Prod" dbtype="query">
SELECT *
FROM qGetOrders, qGetProducts
</cfquery>
<cfquery name="qqCombOrd_ProdtoSales" dbtype="query">
SELECT *
FROM qqCombOrd_Prod, qGetSalesCalls
</cfquery>
PLEASE HELP!!! I'm about to go scouting for bridges to leap from!You might be able to simplify that query by getting rid of the subqueries. Something like this
SELECT TerritoryManager
, count(sc.userid) totalcalls
, sum(po.quantity) total
, sum(newexisting) totalnew
, count(o.userid) totalorders
from users u join salescalls sc on u.userid = sc.userid
join orders o on u.userid = o.userid
join productorders po on u.userid = po.userid
where userzone = 'CENTRAL' -
A strange query of queries bug in CF11?
Hi,
I have this strange query of queries result that could be a bug in CF11. The result is fine in CF10.
Basically, I have 2 queries, qrA and qrB. I do a join of the two in joinQr, after which I do a query of qrA. Since I didn't alter qrA in any way, I would expect newQrA to give me the same result as qrA. However it only gives me one row ("D"). Now, here's the strange thing: If I start off qrA with the letters in ascending order ["A", "B", "C", "D"], then newQrA gives me the right result.
<cfset qrA = queryNew("")>
<cfset queryAddColumn( qrA, "size", "varchar", [ "D", "A", "B", "C" ] )>
<cfset qrB = queryNew("")>
<cfset queryAddColumn( qrB, "size", "varchar", [ "A" ] )>
<cfset queryAddColumn( qrB, "quantity", "integer", [ 0 ] )>
<cfquery name="joinQr" dbtype="query">
select qrA.*, qrB.quantity
from qrA, qrB
where qrA.size = qrB.size
</cfquery>
<cfquery name="newQrA" dbtype="query">
select *
from qrA
</cfquery>
<cfdump var="#qrA#">
<cfdump var="#qrB#">
<cfdump var="#joinQr#">
<cfdump var="#newQrA#">For your interest, by coincidence, my first test was with
<cfset queryAddColumn( qrA, "size", "varchar", [ "A","B","C","D" ] )>
It turns out that the order "A","B","C","D" works, whereas "D","A","B","C" fails. Quite funny, really. -
Query Of Queries : Error When Trying To Fake Left Outer Join
Hi there
I am trying to replicate a left outer join, combining two query of queries using a method I located here
However, I keep getting an error message..
Here is the code I am using....
<cfquery dbtype="query" name="qry">
SELECT *
FROM returnQry, returnQry2
WHERE returnQry.mediumImage = returnQry2.mediumImage
ORDER BY returnQry.name
</cfquery>
<cfquery name="returnQry3" dbtype="#application.mx#">
SELECT *
FROM trackmeanings AS t
</cfquery>
<cfquery dbtype="query" name="endQry">
SELECT name,nameRcd,mediumImage, COUNT(sMessage) AS comments
FROM qry, returnQry3
WHERE qry.name = returnQry3.sNameTrack
UNION
SELECT name,nameRcd,mediumImage, COUNT(sMessage) AS comments
FROM qry, returnQry3
WHERE #qry.name# NOT IN (#QuotedValueList(returnQry3.sNameTrack)#)
GROUP BY name,nameRcd,mediumImage
</cfquery>
When I try to use the query output in a page, i get the error message "Incorrect conditional expression, Expected one of [like|null|between|in|comparison] condition"
Would anyone have any ideas?
Many thanksActually , spoke a little too soon, my query now seems to be outputting duplicates when the value is found on both sides of the union, my group by clause doesnt seem to be eliminating them like it usually does.
My SELECT code now reads
<cfquery dbtype="query" name="endQry">
SELECT name,nameRcd,mediumImage, COUNT(sMessage) AS comments
FROM qry, returnQry3
WHERE qry.name = returnQry3.sNameTrack
GROUP BY name,nameRcd,mediumImage
UNION
SELECT name,nameRcd,mediumImage, 0 AS comments
FROM qry
WHERE qry.name NOT IN (<cfqueryparam
value="#returnQry3.sNameTrack#"
cfsqltype="cf_sql_varchar"
list="yes"
/>)
GROUP BY name,nameRcd,mediumImage
ORDER BY name DESC
</cfquery>
and my ouput...is producing duplicates
<cfoutput query="rc.qryTopTracks" group="name">
#rc.qryTopTracks.name#
</cfoutput>
Would you have any idea of how to eliminate them here? Thanks -
Query of queries date comparison
Cut to the basics, I'm trying to run the following code:
<cfset qData = QueryNew("dataDate,ID")>
<cfset padDate = "#DateFormat(Now(),"dd mmm yy")#
23:59">
<cfset queryAddRow(qData)>
<cfset QuerySetCell(qData,"ID",1)>
<cfset QuerySetCell(qData,"dataDate",padDate)>
<cfset delDate = "#DateFormat(Now(),"dd mmm yy")#
00:00">
<cfquery name="qZero" dbtype="query">
SELECT ID
FROM qData
WHERE dataDate = '#delDate#'
</cfquery>
This works fine in MX7 but I need to put it on a server using
MX6.1. It appears that in 6.1 query of queries considers the
dataDate field to be a date but will not accept a date on the right
hand side of the equals sign in the where clause so comes up with
'Unsupported type comparison'. Is there any way round this?I just ran into this problem actually.
What appears to be happening is QoQ has trouble comparing SQL
date types and DB date types. I had to perform an lsdateformat on
the data to get it to process.
I am also looking into a problem where QoQ is switching my
dates to strings. CF has yet to impress me. For every kind of cool
thing they do there are 25 lame things. -
Selecting Randoms from Query of Queries
I can create a query that selects random records
<cfquery....>
select top 10 * from table order by newid() <!--- SQL
Server --->
</cfquery>
or
<cfquery....>
select top 10 * from table order by rand() limit 10 <!---
MySQL--->
</cfquery>
However, is there a way to cache a query then select random
records from it?
I want to cache the overall query that retrieves all the
records, then
randomly pull
from that cached query.
If I use newid() or rand(), the query bombs on the
parentheses.
Any suggestions?
Tamiwell, it's not really a query of queries... more like a query
of a cached
query :)
"DixieGal" <[email protected]> wrote
in message
news:ffsn1b$***$[email protected]..
|I can create a query that selects random records
| <cfquery....>
| select top 10 * from table order by newid() <!--- SQL
Server --->
| </cfquery>
|
| or
| <cfquery....>
| select top 10 * from table order by rand() limit 10
<!--- MySQL--->
| </cfquery>
|
| However, is there a way to cache a query then select random
records from
it?
| I want to cache the overall query that retrieves all the
records, then
| randomly pull
| from that cached query.
|
| If I use newid() or rand(), the query bombs on the
parentheses.
|
| Any suggestions?
|
| --
|
| Tami
|
| -
I am getting this error when trying to run a query of queries
on a query constructed with QueryNew(): The value "" cannot be
converted to a number
My hosting company recently upgraded to Coldfusion 7 and this
is when the error began. It worked fine before this and I have not
been able to figure out what to do to correct the issue.
I have dumped the query that I am constructing with QueryNew
and beside some values being null the query looks fine. I don't
think having some null fields should pose a problem.
Any ideas?Try inserting the word null instead of an empty
string. -
Is Query of Queries faster than multiple WHERE criteria?
If I need a recordset based on two table column fields (let's say firstName and lastName), is it better to run one query with a WHERE firstName = x AND lastName = y, or is it better to query of queries and find all records with a specified firstName, and then query that query to filter only records with a specified last name? Which is the better/faster method?
<cfquery name="somequery" datasource="someds">
SELECT *
FROM sometable
WHERE firstName = 'John' AND lastName = 'Smith'
</cfquery>
or....
<cfquery name="somequery" datasource="someds">
SELECT *
FROM sometable
WHERE firstName = 'John'
</cfquery>
<cfquery name="somequery2" dbtype="query">
SELECT *
FROM somequery
WHERE lastName = 'Smith'
</cfquery>As a rule of thumb, make the database server do all the work... i.e. locally. If what you are interested is "first name = x and last name = y," then those are the only records that you want to be "sent over the little wire" to you. "The little wire" is always the bottleneck.
-
Query of queries case sensitive
Hi,
I've a question regarding this issue. I am pulling data from an xml file and dump that data into query of queries then output them. The problem is when I try to order the query ASC, the upper will be top and the lower will be on the bottom. Is there a way to sort them before dump data into query? Or any ways of getting around this?
Thanks.Depending on your requirements, you might want to add a new column to the query, rather than calling upper() on your actual data column... it depends on whether you want your data column to be all upper case (like if you are displaying it).
So instead of this:
SELECT col1, upper(col2)
FROM q
ORDER BY col2
Have this:
SELECT col1, col2, upper(col2) AS col2Sort
FROM q
ORDER BY col2Sort
It doesn't always matter, obviously, but it's handy to keep it in mind.
Adam -
SQ01 - Ordering Selection Fields
Hello SAP gurus,
I want to know if its possible to order selection fields in SAP Query transaction SQ01 in SAP ECC 6.0.
Thanks in advance,
Adelmo R SilvaHi,
1. Go to SQ01
2. Enter your Query name.
3. Select "Change".
4. Press F6
5. Select your required Field Groups
6. Press F6
7. Select your required Fields.
8. Press F6 and you will reach screen of selection fields.
9. No.: Sequence on selection screen
Selection text: Text on selection screen
Sngl: Single value entry (no interval/multiple selection) -
Formatted Search to pull Sales Order Remarks field onto Purchase Order
Hi Guys,
I need a formatted search for a Purchase Order remarks field, which will pull the remarks field from the linked Sales Order
(When a PO is done through the logistics tab of the Sales Order)
I have made this query but it is not working:
SELECT distinct T0.[Comments] FROM ORDR T0 , POR1 T1 WHERE T0.[DocNum] = T1.[BaseRef]
It is just pulling the remarks for the first sales order - purchase order link.
Any help will be appreciated.
Thanks
Best Regards
Dario MoutinhoHi Dario Moutinho,
Try:
SELECT distinct T0.Comments FROM ORDR T0
WHERE T0.DocEnthy = $[POR1.BaseEntry\]
Thanks,
Gordon -
Items are not getting displayed in Sales Order Lines 'Ordered Item' field
Hi All,
Ordered Item field in Sales Order lines is not getting values When trying to create a Manual Sales Order.
When clicked on Ordered Item LOV, no values are getting displayed.
Thanks,
Chandra.879035 wrote:
Hi,
I was unable to select any item (nothing is getting displayed in Ordered Item field when the LOV is clicked) in Sales Order Lines.
The Sales Order header information i was able to enter & generate the Order Number.
R12.1.3 is the version i am using.
Thanks,
Chandra.Have you done all the required setup in OM??
Like system parameters...Imp one would be Item Validation Organization
Make sure item is also available in the price list which you are using in order
Mahendra -
How do I change the value of the Order By field in an MP3 file?
good day Guys,
I'm new here in the forum and I have a question that is "breaking" the order of my songs and my head too ...
How do I change the value of the Order By field in an MP3 file?
for example, in the photo below, the song "The Bad Touch" is coming BEFORE the song "A Little Respect", this happens because of the Name field to Order ...
My "problem" is in the photo below, the "tab" Order, iTunes will not let me erase what is written in the "Sort As" ...
I've been "collecting" several songs over SEVERAL years
I'm currently with more than 1,500 songs on HD and several backups on DVDs and external hard drives and I think, download it again, will be a "little" laborious and boring
I DON'T WANT to be filling the tags of songs (name, singer, CD, year, etc.)
I have used the program Mp3tag to remove the music tags
I've tried to download the song again and go through Mp3tag program as if it were a new song
I've changed the music access permissions, folder and even entire hard drive (my Windows has only one user)
I've tried to catch the song again, from a previous backup
I've tried to create a copy of the file at iTunes own
I've tried to create a new music file in a music recording program
NOTHING of what I did above resolved
-> I'm using Windows 7 64-bit Ultimate
-> I'm using iTunes 12.1.1.4 for 64-bit Windows
-> My iPad is the third generation (a little old, I know) with Wi-Fi and 3G, but it has served me VERY WELL
-> The iPad is updated with iOS 8.1.3 and is not unlocked
I'm sorry for the GIANT post, but well, I think I could explain as much as possible and for my English, too bad, by the way, I'm from Brazil and I'm using Google translator
Hugs and await answers,
Paulo Ricardohello turingtest2,
my language is Brazilian Portuguese (there are some little differences between Brazilian Portuguese and the Portuguese of Portugal, but nothing that interferes with the script)
at this time, I'm managing songs manually, I don't know if this will interfere with the execution of a script or command
as I picked up this iPad recently, I still don't understand how to set up the iTunes Music Library and the person who gave me, told me it was easier to put the songs manually
as you said, in my iTunes, 95% of the songs are with ALL the blank fields, including the Name to Sort field, only songs that begin with a/an/the standing with the Name to Sort field filled with name of the song, without the a/the
I do not know what to do...
I want to learn to ride the iTunes Music Library, that my work is less
you know any site that teaches create/manage my iTunes Music Library?
this site/forum may be in English, no problem
thanks for all your help and the help of others who responded to my request -
Purchase Order form in Query only mode for some users
Hi All,
I want to make the Purchase Orders form as query only for a single user. I tried by giving 'Query_only=Yes' in the parameters section. I am getting 'FRM-04151: You cannot query records here' message more than 10 time. I know we get this message and this is applicable to all the users. But this message is comming more than 10 times.
Is there anyway that I can restrict the Query only mode to a single user and please suggest about the message also.
Thanks in Advance,
NareshNaresh,
Since you want to achieve this for one user only, I would suggest you create a new function/menu/responsibility and assign this responsibility to the user.
Note: 400380.1 - How To Create a QUERY-ONLY FORM
https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=400380.1
For the FRM error, please review the following document.
Note: 116074.1 - ACCESS LEVEL - REVIEW ONLY - PO
https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=116074.1
Regards,
Hussein
Maybe you are looking for
-
INSTEAD OF TRIGGER (UPDATE): new.field null or not set
When using an instead of trigger for an update on a view, you can "relate" the updates to the (another) base table(s). to perform the update statement you have the use the ":new.field" notation. Is there a way to determine if the field value is inclu
-
Problems with Spotlight & Programs
I am a senior in high school and right now and our school has a macbook for every student thanks to the Maine Learning Technology Initiative. I'm on April vacation right now and my computer is constantly slow, though I think that has to do with the a
-
How to play audio with an embed code?
I have a code to embed an audio player and I create a muse document to create a html index and them I put it in indesign document with the overlay creator tool (web content). In the desktop preview works fine but in the ipad doesn't. Any idea? thanks
-
USB 3.0 performs at USB 2.0 speeds have installed every driver i can find
Have tried absolutely everything I can think of. When I bought laptop it was on windows 8.... everything worked fine. But windows 8 and me didnt get on very well. so downgraded to windows 7 pro and all is well in the world apart from the usb 3.0 port
-
Airport Time Capsule keeps turning off light
My Airport time capsule 2gig (2013) model keeps turning off like every 30 mins. I need to unplug and plug it over again to turn on the time capsule. I connect my airport time capsule to my macbook pro 15inch retina display using the thunderbolt. I'm