SQL SELECT with GROUP BY: Retrieve records for a list of customers
I need to write a SQL statement to retrieve a list of customers, which are in two tables of different natures, say T1 and T2.
The customer is a FK in both tables. Both tables have a column which is the date of an order.
INPUT:
* list of customers, say '12345, 34567, 45678'
OUTPUT
* REF CURSOR to a recordset containing: {custID, startDate, endDate}
Algorithm
* For each customer, find the date of first order (from T1 and T2)
* For that date, t0, startDate=t0-10 days; endDate := t0+15 days;
I have a feeling some GROUP BY is involved to do the trick.
Can it be done without any looping? I am just not experienced enough to solve this in an optimal way.
Any help, please?
Thank you.
Hi,
I'm not sure what your data is, or shat you want for output.
If your tables can have many rows for the same customer_id, but your output should have only one row per customer_id, then it sounds like you do need to "GROUP BY custiomer_id".
If the data is coming from two different tables, first do a UNION of those two tables in a sub-query (like union_data below), and then do a GROUP BY on the results of the sub-query.
It will probably be more efficient if you GROUP BY in the sub-query, too.
I believe you need something like this:
WITH union_data AS
SELECT customer_id
, MIN (order_date) AS start_dt
FROM t1
WHERE customer_id IN (12345, 34567, 45678)
GROUP BY customer_id
UNION ALL
SELECT customer_id -- column names may be different from t1
, MIN (order_date) AS start_dt
FROM t2
WHERE customer_id IN (12345, 34567, 45678)
GROUP BY customer_id
SELECT customer_id
, MIN (start_date) AS start_date
, MIN (start_date) - 10 AS t0
, MIN (start_date) + 5 AS end_date
FROM union_data
GROUP BY customer_id;If you need help, post a little sample data (CREATE TABLE and INSERT statements for both tables, relevant columns only), and the results you want to get from that data.
Similar Messages
-
How to create a matchcode for the list of Customers "Group key" KNA1-KONZS
Hi All,
with reference to the creation of "Group key" KNA1-KONZS for Customers,
I'd like to know if is possible to create a matchcode for the list of Customers "Group key" created.
Thanks
GandalfHi
MAINTAIN THE GROUP KEY IN GENERAL DATA ---CONTROL DATA SCREEN
If the customer or the vendor belongs to a group, you can enter a group
key here. The group key is freely assignable.
If you create a matchcode using this group key, group evaluations are
possible.
KNA1-KONZS
Cya
udayakumar -
Tcode for the List of customers
Hi All
can any body tell me the tcode for the list of customers in the systemgo to change mode of customer master and enter f4 in the customer number column and enter u will get all the list of customers in the system
rewards if it is helpful to u -
Need help for SQL SELECT query to fetch XML records from Oracle tables having CLOB field
Hello,
I have a scenario wherein i need to fetch records from several oracle tables having CLOB fields(which is holding XML) and then merge them logically to form a hierarchy XML. All these tables are related with PK-FK relationship. This XML hierarchy is having 'OP' as top-most root node and ‘DE’ as it’s bottom-most node with One-To-Many relationship. Hence, Each OP can have multiple GM, Each GM can have multiple DM and so on.
Table structures are mentioned below:
OP:
Name Null Type
OP_NBR NOT NULL NUMBER(4) (Primary Key)
OP_DESC VARCHAR2(50)
OP_PAYLOD_XML CLOB
GM:
Name Null Type
GM_NBR NOT NULL NUMBER(4) (Primary Key)
GM_DESC VARCHAR2(40)
OP_NBR NOT NULL NUMBER(4) (Foreign Key)
GM_PAYLOD_XML CLOB
DM:
Name Null Type
DM_NBR NOT NULL NUMBER(4) (Primary Key)
DM_DESC VARCHAR2(40)
GM_NBR NOT NULL NUMBER(4) (Foreign Key)
DM_PAYLOD_XML CLOB
DE:
Name Null Type
DE_NBR NOT NULL NUMBER(4) (Primary Key)
DE_DESC NOT NULL VARCHAR2(40)
DM_NBR NOT NULL NUMBER(4) (Foreign Key)
DE_PAYLOD_XML CLOB
+++++++++++++++++++++++++++++++++++++++++++++++++++++
SELECT
j.op_nbr||'||'||j.op_desc||'||'||j.op_paylod_xml AS op_paylod_xml,
i.gm_nbr||'||'||i.gm_desc||'||'||i.gm_paylod_xml AS gm_paylod_xml,
h.dm_nbr||'||'||h.dm_desc||'||'||h.dm_paylod_xml AS dm_paylod_xml,
g.de_nbr||'||'||g.de_desc||'||'||g.de_paylod_xml AS de_paylod_xml,
FROM
DE g, DM h, GM i, OP j
WHERE
h.dm_nbr = g.dm_nbr(+) and
i.gm_nbr = h.gm_nbr(+) and
j.op_nbr = i.op_nbr(+)
+++++++++++++++++++++++++++++++++++++++++++++++++++++
I am using above SQL select statement for fetching the XML records and this gives me all related xmls for each entity in a single record(OP, GM, DM. DE). Output of this SQL query is as below:
Current O/P:
<resultSet>
<Record1>
<OP_PAYLOD_XML1>
<GM_PAYLOD_XML1>
<DM_PAYLOD_XML1>
<DE_PAYLOD_XML1>
</Record1>
<Record2>
<OP_PAYLOD_XML2>
<GM_PAYLOD_XML2>
<DM_PAYLOD_XML2>
<DE_PAYLOD_XML2>
</Record2>
<RecordN>
<OP_PAYLOD_XMLN>
<GM_PAYLOD_XMLN>
<DM_PAYLOD_XMLN>
<DE_PAYLOD_XMLN>
</RecordN>
</resultSet>
Now i want to change my SQL query so that i get following output structure:
<resultSet>
<Record>
<OP_PAYLOD_XML1>
<GM_PAYLOD_XML1>
<GM_PAYLOD_XML2> .......
<GM_PAYLOD_XMLN>
<DM_PAYLOD_XML1>
<DM_PAYLOD_XML2> .......
<DM_PAYLOD_XMLN>
<DE_PAYLOD_XML1>
<DE_PAYLOD_XML2> .......
<DE_PAYLOD_XMLN>
</Record>
<Record>
<OP_PAYLOD_XML2>
<GM_PAYLOD_XML1'>
<GM_PAYLOD_XML2'> .......
<GM_PAYLOD_XMLN'>
<DM_PAYLOD_XML1'>
<DM_PAYLOD_XML2'> .......
<DM_PAYLOD_XMLN'>
<DE_PAYLOD_XML1'>
<DE_PAYLOD_XML2'> .......
<DE_PAYLOD_XMLN'>
</Record>
<resultSet>
Appreciate your help in this regard!Hi,
A few questions :
How's your first query supposed to give you an XML output like you show ?
Is there something you're not telling us?
What's the content of, for example, <OP_PAYLOD_XML1> ?
I don't think it's a good idea to embed the node level in the tag name, it would make much sense to expose that as an attribute.
What's the db version BTW? -
Sql select with concate of columns SP2-0734: unknown command beginning
I am running a ksh script that does some dumpster diving and pull records out.
It is basically reading a file does a select and at the end, you will see $i.
AND ORD_ORDER.ADV_ORDER_TEXT_FIELD_568='$';
I can run the script manually. (without the while loop)
But, when I run it thru the script I get a whack of errors.
SP2-0734: unknown command beginning "FROM ADVXR..." - rest of line ignored.
SP2-0734: unknown command beginning "ADVXRT_HDB..." - rest of line ignored.
SP2-0734: unknown command beginning "ADVXRT_HDB..." - rest of line ignored.
SP2-0734: unknown command beginning "ADVXRT_HDB..." - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
What I need it to do is pull the selected records out and place in a file.
Script
cat $TICKETS_MISMATCH |while read i
do
$SQLPLUS -silent "advxrt_hdb/$LOGONID@hdb" <<EOF >$TICKETS_MISMATCH_FULL
set feedback off
set verify off
set echo off
set heading off
set pagesize 7010
SELECT ORD_ORDER.ADV_ORDER_TEXT_FIELD_568
|| ','
|| ORD_ORDER.ORDER_NUM
|| ','
|| ORD_ORDER.ADV_ORDER_SUMMARY_FIELD_012
|| ','
|| LAB_USER.NAME
|| ','
|| LAB_USER.LOGON_ID
|| ','
|| LAB_USER.ADV_EXTENDED_USER_FIELD_001
|| ','
|| TO_CHAR(MOBILECOMP1_SR.ADV_COMPLETION_TIME_FIELD_001, 'HH24:MI:SS')
|| ','
|| TO_CHAR(MOBILECOMP1_SR.ADV_COMPLETION_DATE_FIELD_001, 'DD-MON-YYYY')
|| ','
|| MOBILECOMP1_SR.ADV_COMPLETION_NOTES_FIELD_001
|| ','
|| MOBILECOMP1_SR.ADV_COMPLETION_TEXT_FIELD_003
|| ','
|| MOBILECOMP1_SR.ADV_COMPLETION_TEXT_FIELD_013
|| ','
|| MOBILECOMP1_SR.ADV_COMPLETION_TEXT_FIELD_014
|| ','
|| MOBILECOMP1_SR.ADV_COMPLETION_TEXT_FIELD_023
|| ','
|| ORD_JOB_CODE.NAME
|| ','
|| ROUND(ASN_ASSIGNMENT.TOTAL_TIME_EN_ROUTE / 60,0)
|| ','
|| ROUND(ASN_ASSIGNMENT.TOTAL_TIME_ON_SITE / 60,0)
FROM ADVXRT_HDB.LAB_USER,
ADVXRT_HDB.SR_REPORT,
ADVXRT_HDB.ASN_ASSIGNMENT,
ADVXRT_HDB.ORD_ORDER,
ADVXRT_HDB.MOBILECOMP1_SR,
ADVXRT_HDB.ORD_JOB_CODE
WHERE (ASN_ASSIGNMENT.ASSIGNMENT_ID = SR_REPORT.ASSIGNMENT)
AND (ASN_ASSIGNMENT.FOR_ORDER = ORD_ORDER.ORDER_ID)
AND (MOBILECOMP1_SR.MOBILE_COMP1_ID = SR_REPORT.RECORD_NUMBER)
AND (ORD_ORDER.JOB_CODE = ORD_JOB_CODE.JOB_CODE_ID)
AND (SR_REPORT.USER_ID = LAB_USER.USER_ID(+))
AND ORD_ORDER.COMPLETED BETWEEN ((TO_DATE('${date_entered} 00:00:00','YYYY-MM-DD HH24:MI:SS')) - ((SELECT DECODE
(UTC_OFFSET, NULL, 0, UTC_OFFSET) FROM TZ_UTC_TO_LOCAL TZ WHERE (TO_DATE
('${date_entered} 00:00:00','YYYY-MM-DD HH24:MI:SS') BETWEEN TZ.STARTS_UTC AND
TZ.ENDS_UTC)AND TZ.TIME_AUTHORITY = 1000264000000000000000000013))/(24*60*60))
AND
((TO_DATE('${date_entered} 11:59:59','YYYY-MM-DD HH24:MI:SS')) - ((SELECT DECODE
(UTC_OFFSET, NULL, 0, UTC_OFFSET) FROM TZ_UTC_TO_LOCAL TZ WHERE (TO_DATE
('${date_entered} 11:59:59','YYYY-MM-DD HH24:MI:SS') BETWEEN TZ.STARTS_UTC AND
TZ.ENDS_UTC)AND TZ.TIME_AUTHORITY = 1000264000000000000000000013))/(24*60*60))
AND ORD_ORDER.ADV_ORDER_TEXT_FIELD_568='${i}';
exit;
EOF
doneSQL> DEFINE sqlplusrelease
DEFINE SQLPLUSRELEASE = "1002000200" (CHAR)
cat $TICKETS_MISMATCH |while read i
do
$SQLPLUS -silent "advxrt_hdb/$LOGONID@hdb" <<EOF >>$TICKETS_MISMATCH_FULL
set feedback off
set verify off
set echo off
set heading off
set pagesize 7010
SET SQLBLANKLINES ON
SELECT ORD_ORDER.ADV_ORDER_TEXT_FIELD_568
|| ','
|| ORD_ORDER.ORDER_NUM
|| ','
|| ORD_ORDER.ADV_ORDER_SUMMARY_FIELD_012
|| ','
|| LAB_USER.NAME
|| ','
|| LAB_USER.LOGON_ID
|| ','
|| LAB_USER.ADV_EXTENDED_USER_FIELD_001
|| ','
|| TO_CHAR(MOBILECOMP1_SR.ADV_COMPLETION_TIME_FIELD_001, 'HH24:MI:SS')
|| ','
|| TO_CHAR(MOBILECOMP1_SR.ADV_COMPLETION_DATE_FIELD_001, 'DD-MON-YYYY')
|| ','
|| MOBILECOMP1_SR.ADV_COMPLETION_NOTES_FIELD_001
|| ','
|| MOBILECOMP1_SR.ADV_COMPLETION_TEXT_FIELD_003
|| ','
|| MOBILECOMP1_SR.ADV_COMPLETION_TEXT_FIELD_013
|| ','
|| MOBILECOMP1_SR.ADV_COMPLETION_TEXT_FIELD_014
|| ','
|| MOBILECOMP1_SR.ADV_COMPLETION_TEXT_FIELD_023
|| ','
|| ORD_JOB_CODE.NAME
|| ','
|| ROUND(ASN_ASSIGNMENT.TOTAL_TIME_EN_ROUTE / 60,0)
|| ','
|| ROUND(ASN_ASSIGNMENT.TOTAL_TIME_ON_SITE / 60,0)
FROM ADVXRT_HDB.LAB_USER,
ADVXRT_HDB.SR_REPORT,
ADVXRT_HDB.ASN_ASSIGNMENT,
ADVXRT_HDB.ORD_ORDER,
ADVXRT_HDB.MOBILECOMP1_SR,
ADVXRT_HDB.ORD_JOB_CODE
WHERE (ASN_ASSIGNMENT.ASSIGNMENT_ID = SR_REPORT.ASSIGNMENT)
AND (ASN_ASSIGNMENT.FOR_ORDER = ORD_ORDER.ORDER_ID)
AND (MOBILECOMP1_SR.MOBILE_COMP1_ID = SR_REPORT.RECORD_NUMBER)
AND (ORD_ORDER.JOB_CODE = ORD_JOB_CODE.JOB_CODE_ID)
AND (SR_REPORT.USER_ID = LAB_USER.USER_ID(+))
AND ORD_ORDER.COMPLETED BETWEEN ((TO_DATE('${date_entered} 00:00:00','YYYY-MM-DD HH24:MI:SS')) - ((SELECT DECODE
(UTC_OFFSET, NULL, 0, UTC_OFFSET) FROM TZ_UTC_TO_LOCAL TZ WHERE (TO_DATE
('${date_entered} 00:00:00','YYYY-MM-DD HH24:MI:SS') BETWEEN TZ.STARTS_UTC AND
TZ.ENDS_UTC)AND TZ.TIME_AUTHORITY = 1000264000000000000000000013))/(24*60*60))
AND
((TO_DATE('${date_entered} 11:59:59','YYYY-MM-DD HH24:MI:SS')) - ((SELECT DECODE
(UTC_OFFSET, NULL, 0, UTC_OFFSET) FROM TZ_UTC_TO_LOCAL TZ WHERE (TO_DATE
('${date_entered} 11:59:59','YYYY-MM-DD HH24:MI:SS') BETWEEN TZ.STARTS_UTC AND
TZ.ENDS_UTC)AND TZ.TIME_AUTHORITY = 1000264000000000000000000013))/(24*60*60))
AND ORD_ORDER.ADV_ORDER_TEXT_FIELD_568='${i}';
exit
EOF
done -
How to use SQL loader with DBF fixed format record
Hi everybody!
My situation is that: I want to use SQL loader with Foxpro DBF format, it similar to case 2 study (Fixed format record) but DBF file has header, how can I tell SQL loader skip header.
Thank you in advanceAnother option is to apply SQL operators to fields
LOAD DATA
INFILE *
APPEND
INTO TABLE emp
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' (
empno,
ename,
job,
mgr,
hiredate DATE(20) "DD-Month-YYYY",
sal,
comm,
deptno CHAR TERMINATED BY ':',
projno,
loadseq "my_seq.nextval")This is a modified control file of Case Study 3 which originally demonstrated the use of the Sequence parameter -
T.Code for viewing list of customers of particular account group - Reg
Hi,
Can anyone suggest me T.code to view list of customer of particular account group?
IS there any other method to view the list of customers in a particular account group?
Please, it is an urgent requirement.
Rewards sure
Regards,
SP.Balaji
Message was edited by:
balaji soundarapandianHi Sai Srinivas,
Already solved it and thanx for your help
Regards,
S.P.Balaji -
Discoverer Custom SQL Report with Group By,Having
Hi all,
I'm working with Discoverer 4.1.41.05 and retrieve data from Oracle HRMS.
I want to create a report based on a custom SQL Folder in Discoverer Administration to solve the following scenario:
SELECT EMPLOYEE_NUMBER FROM PER_ALL_PEOPLE_F
MINUS
SELECT EMPLOYEE_NUMBER FROM PER_ALL_PEOPLE_F,PER_EVENTS, PER_BOOKINGS
GROUP BY EMPLOYEE_NUMBER
HAVING SUM(PER_EVENTS.ATTRIBUTE1) >= 10)
The problem is when I run the sql from SQL*Plus is working fine producing the correct result.
When I create the Custom Folder and create a Discoverer report based on it I retrieve all employees since the second select statement retrieve no rows!
Does anyone has any idea how I can solve this problem or if there is another way to create this scenario?
Any feedback is much appreciated.
Thanking you in advance.
ElenaHi Elena,
I think you are missing some joins, you could try something like:
SELECT EMPLOYEE_NUMBER FROM PER_ALL_PEOPLE_F p
WHERE NOT EXISTS
(SELECT NULL
FROM PER_EVENTS e, PER_BOOKINGS b
WHERE b.person_id = p.person_id
AND e.event_id = b.event_id
GROUP BY b.person_id
HAVING SUM(e.ATTRIBUTE1) >= 10)
Rod West -
SQL Selecting the first and last entries for each day
Hello SQL experts,
I hope you can help with this.. I have a table (could have 1M or more rows in it) see structure below. I am looking to get the first and last date/times for each employee for each day. I also need the location GUID for the first read.
EmployeeGUID (uniqueidentifier datatype)
LocationGUID (uniqueidentifier datatype)
DateTime (DateTime datatype)
12345678-0000-0000-0000-000000000000
11111111-0000-0000-0000-000000000000
04/12/2014 07:00:01
12345678-0000-0000-0000-000000000000
22222222-0000-0000-0000-000000000000
04/12/2014 10:40:05
12345678-0000-0000-0000-000000000000
22222222-0000-0000-0000-000000000000
04/12/2014 17:04:02
44422222-0000-0000-0000-000000000000
22222222-0000-0000-0000-000000000000
04/14/2014 08:00:00
44422222-0000-0000-0000-000000000000
22222222-0000-0000-0000-000000000000
04/14/2014 14:00:03
44422222-0000-0000-0000-000000000000
33333333-0000-0000-0000-000000000000
04/15/2014 07:49:00
44422222-0000-0000-0000-000000000000
11111111-0000-0000-0000-000000000000
04/15/2014 09:00:01
This would be the ideal output (I can do without the TotalTimeInHours):
EmployeeGUID (uniqueidentifier datatype)
LocationGUID (uniqueidentifier datatype)
FirstRead (DateTime datatype)
LastRead (DateTime datatype)
TotalTimeInHours
12345678-0000-0000-0000-000000000000
11111111-0000-0000-0000-000000000000
04/12/2014 07:00:01
04/12/2014 17:04:02
Total in hours between the first and last read.
44422222-0000-0000-0000-000000000000
22222222-0000-0000-0000-000000000000
04/14/2014 08:00:00
04/14/2014 14:00:03
44422222-0000-0000-0000-000000000000
33333333-0000-0000-0000-000000000000
04/15/2014 07:49:00
04/15/2014 09:00:01
I would post what I have tried so far but I have been trying many different types of queries over the last few days. In short I need the employees first and last reads for each date. They could have many entries per date or just 1. I am certain that this
is a trivial thing for a SQL expert but not trivial for me :).
Thank you in advance!Thank you!
This is almost what I need. The LocationGUID has to be included in the output. When I include it, I have to put it in the Group By clause. When I do that the reads are based on the LocationGUID (see below).
** I added a few more data entries and included the LocationGUID in the output.
***** SQL ***********
CREATE TABLE test( EmployeeGUID uniqueidentifier, LocationGUID uniqueidentifier, DateTimeCol DateTime )Insert into test values
('12345678-0000-0000-0000-000000000000','11111111-0000-0000-0000-000000000000','04/12/2014 07:00:01')
,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/12/2014 10:40:05')
,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/12/2014 17:04:02')
,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/12/2014 19:00:00')
,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/14/2014 08:00:00')
,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/14/2014 14:04:03')
,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/15/2014 07:49:00')
,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/15/2014 09:00:01')
,('12345678-0000-0000-0000-000000000000','11111111-0000-0000-0000-000000000000','04/13/2014 10:40:05')
,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/13/2014 17:04:02')
,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/13/2014 19:00:00')
;with mycte as (
SELECT *, row_number() OVER(partition by EmployeeGUID, Cast(DateTimeCol as date) Order by DateTimeCol) rnASC,
row_number() OVER (partition by EmployeeGUID, Cast(DateTimeCol as date) Order by DateTimeCol DESC) rnDESC
FROM test)
Select EmployeeGUID ,Cast(DateTimeCol as date) dt,LocationGUID,
Max(Case when rnASC=1 Then DateTimeCol End) minDateTimeCol
,Max(Case when rnDESC=1 Then DateTimeCol End ) maxDateTimeCol
,Datediff(minute, Max(Case when rnASC=1 Then DateTimeCol End) ,Max(Case when rnDESC=1 Then DateTimeCol End ) )/60.0 TotalTimeInHours
from mycte
Group by EmployeeGUID, LocationGUID,Cast(DateTimeCol as date)
Order by dt,EmployeeGUID
drop TABLE test
**** OUTPUT **********
EmployeeGUID
dt
LocationGUID
minDateTimeCol
maxDateTimeCol
TotalTimeInHours
12345678-0000-0000-0000-000000000000
2014-04-12
11111111-0000-0000-0000-000000000000
2014-04-12 07:00:01.000
NULL
NULL
12345678-0000-0000-0000-000000000000
2014-04-12
22222222-0000-0000-0000-000000000000
NULL
2014-04-12 19:00:00.000
NULL
12345678-0000-0000-0000-000000000000
2014-04-13
11111111-0000-0000-0000-000000000000
2014-04-13 10:40:05.000
NULL
NULL
12345678-0000-0000-0000-000000000000
2014-04-13
22222222-0000-0000-0000-000000000000
NULL
2014-04-13 19:00:00.000
NULL
44422222-0000-0000-0000-000000000000
2014-04-14
22222222-0000-0000-0000-000000000000
2014-04-14 08:00:00.000
2014-04-14 14:04:03.000
6.066666 -
SQL Select with comma separated column value
Hi All
ASP VBScript
I have a DB column named allowed_contracts that stores a
comma separated
list of of values e.g. 3, 5, 19, 44, 52
I need to select records based on a variable called
varContractList that
contains another comma separated list i.e. 5, 44, 52
I only want to select records where the allowed_contracts
column contains
each of the varContractList,
For example only return records that have 5 or 44 or 52 in
thier
allowed_contracts column.
My brain is now in a persistant vegetive state trying to work
this out so
any ideas would be much appreciated.
Regards
BrenHi Jules
Cheers for this.
I was trying to be a bit cute (lazy even) by storing the
project ID's as a
comma delimted string but as we see it doesn't always pay to
be lazy. Serves
me right for destroying brain cells by drinking the Welshpool
beer the other
week whilst visiting mates down that neck of the woods. :-))
Time for another table me thinks.
Rgds
Bren
"Julian Roberts" <[email protected]> wrote in message
news:e7i13f$mup$[email protected]..
> Fatal flaw here Bren. In a relational database, one
shouldn't really store
> foreign keys as a comma delimted string. One should have
a 3 table
> structure. eg
>
> Products:
> ProductID
> Product
>
> Categories:
> CategoryID
> Category
>
> ProductCategories:
> ProductID
> CategoryID
>
> So, from the table ProductCategories, a product can
belong to many
> categories. When doing a front end search to find
products in multiple
> categories, products can be shown thus:
>
> select * from Products where ProductID in (select
ProductID from
> ProductCategories where CategoryID in (5,44))
>
> --
> Jules
>
http://www.charon.co.uk/charoncart
> Charon Cart 3
> Shopping Cart Extension for Dreamweaver MX/MX 2004
>
>
>
>
> -
Having downloaded Yosemite it installed fine on my iMac but on my Macbook Pro installation has frozen at the Disc Selection stage (where you want it to install) with the message 'This disc is used for Time Machine Backups'.
I cant find a way past this to complete the installation.
Any ideas anyone ?
Many thanks.Time machine needs its own partition to operate. So you are not going install a OSx Lion on that volume.
If there is enough room you may be able to partition the drive on the fly with DiskUtility
Are you saying you clean installed Lion and you are trying to move your user Data over with TM via the migration Assistant? Please explain. -
No time or username recorded for External Lists
I'm using an external list which is displaying empty values for the Created and Modified fields. The effect is
'Created At '
and
'Modified At '
Is there something I can do to rectify this situation? When a record on an external DB is modified or added through the External List it would be common to want to track this. I'm guessing this is a custom solution.
Love them all...regardless. - Buddhahttp://office.microsoft.com/en-in/sharepoint-help/differences-between-native-and-external-lists-HA102771000.aspx
Native List Feature
Supported in External Lists?
More information
Add, modify, and delete index columns
No
Can be defined in the external data source.
If this helped you resolve your issue, please mark it Answered -
Hello folks,
Many times we need to retrieve records for given lists of PKs (or FKs), as:
p_pk_list := '11,22,33';
We work in 10g
A co-worker of mine had a good idea (I thought) to "help" the optimizer and build a recordset in the FROM clause and use it later in WHERE
SELECT ...
FROM tableName a,
(SELECT REGEXP_SUBSTR(p_pk_list, '[^,]+',1,ROWNUM) p_pk_id
FROM dual
CONNECT BY ROWNUM <= LENGTH(p_pk_list ) - LENGTH(REPLACE(p_pk_list ,','))) d_pk
WHERE
a.ID=d_pk.p_pk_id; -- (1)
The tragedy is that it takes 4 seconds to retrieve 5 records from the table (no other joins). The table has about 40 columns though and there are about 51000 records. With the SELECT REGEXP_SUBSTR in the WHERE clause, it's a bit worse.
If (1) is replaced by:
a.ID IN (11,22,33,44,55);
the execution takes 0.04 seconds.
My questions are:
1. Is this a bad idea to select records for a given list of PKs or FKs? Should one just go for one PK/FK instead?
2. Why the stiff performance penalty?
3. Ideally, it would be nice if this would work:
a.ID IN (p_array);
where p_array would be an array of integers
Any elegant sollutions?
Thanks a lot.
DanCheck the explain plan for both statements.
I would wager that the overhead you experience is due to the fact that you are comparing apples to oranges here.
(SELECT REGEXP_SUBSTR(p_pk_list, '[^,]+',1,ROWNUM) p_pk_id
FROM dual
CONNECT BY ROWNUM <= LENGTH(p_pk_list ) - LENGTH(REPLACE(p_pk_list ,','))) d_pkreturns a string.
a.ID IN (11,22,33,44,55);Is a list of numbers.
If you check the explain plan for the regexp version, you should see an implicit conversion being done for you (converting the number column into a string for comparison) which means you can't use any indexes defined on a.id.
If you want to use an array of numbers here's an approach using a built in array of numbers.
declare
v_number_list sys.odcinumberlist default sys.odcinumberlist();
begin
v_number_list.extend;
v_number_list(v_number_list.count) := 100;
v_number_list.extend;
v_number_list(v_number_list.count) := 200;
for vals in
select *
from all_objects
where object_id in
select column_value
from table(cast(v_number_list as sys.odcinumberlist))
loop
dbms_output.put_line(vals.object_name);
end loop;
end;
25 /
I_TYPED_VIEW1
I_NTAB2
PL/SQL procedure successfully completed.
ME_XE?Otherwise do an explicit TO_NUMBER on the regexp query so that you can use any indexes defined on the table in question. -
Unable to install SQL Server Express 2008 R2 - Errors "Failed to retrieve data for this request"
As domain admin I am attempting to install "SQL Server 2008 R2 with SP2" but it keeps failing with "Failed to retrieve data for this request".
The installation never actually starts, it errors before then.
It displays the same error even if I run the System Configuration Checker.
The summary.txt for the install displays the following text:
Overall summary:
Final result: Failed: see details below
Exit code (Decimal): -1554760125
Exit facility code: 852
Exit error code: 15939
Exit message: Failed to retrieve data for this request.
Start time: 2014-08-15 16:49:52
End time: 2014-08-15 16:50:06
Requested action: RunRules
Machine Properties:
Machine name: servername
Machine processor count: 8
OS version: Windows Server 2008 R2
OS service pack: Service Pack 1
OS region: United States
OS language: English (United States)
OS architecture: x64
Process architecture: 64 Bit
OS clustered: Yes
Product features discovered:
Product Instance Instance ID
Feature Language
Edition Version Clustered
Package properties:
Description: SQL Server Database Services 2008 R2
ProductName: SQL Server 2008 R2
Type: RTM
Version: 10
SPLevel: 1
Installation location: c:\84122ef5b6d9cdcd3b2ac48cec\x64\setup\
Installation edition: EXPRESS
User Input Settings:
ACTION: RunRules
CONFIGURATIONFILE:
ENU: True
FARMACCOUNT: <empty>
FARMADMINPORT: 0
FARMPASSWORD: *****
FEATURES:
HELP: False
INDICATEPROGRESS: False
INSTANCENAME: <empty>
PASSPHRASE: *****
QUIET: False
QUIETSIMPLE: False
RULES: GLOBALRULES,SqlUnsupportedProductBlocker,PerfMonCounterNotCorruptedCheck,Bids2008InstalledCheck,BlockInstallSxS,AclPermissionsFacet,FacetDomainControllerCheck,SSMS_IsInternetConnected,FacetWOW64PlatformCheck,FacetPowerShellCheck
UIMODE: AutoAdvance
X86: False
Configuration file: C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20140815_164944\ConfigurationFile.ini
Detailed results:
Rules with failures:
Global rules:
There are no scenario-specific rules.
Rules report file: The rule result report file is not available.
Exception summary:
The following is an exception stack listing the exceptions in outermost to innermost order
Inner exceptions are being indented
Exception type: Microsoft.SqlServer.Management.Sdk.Sfc.EnumeratorException
Message:
Failed to retrieve data for this request.
Data:
HelpLink.ProdName = Microsoft SQL Server
HelpLink.BaseHelpUrl = http://go.microsoft.com/fwlink
HelpLink.LinkId = 20476
DisableWatson = true
Stack:
at Microsoft.SqlServer.Management.Sdk.Sfc.Enumerator.Process(Object connectionInfo, Request request)
at Microsoft.SqlServer.Chainer.Infrastructure.SqlDiscoveryDatastoreInterface.ProcessDTbl(DataTable dt, Int32 level)
at Microsoft.SqlServer.Chainer.Infrastructure.SqlDiscoveryDatastoreInterface.CollectSqlDiscoveryData(String machineName)
at Microsoft.SqlServer.Chainer.Infrastructure.SqlDiscoveryDatastoreInterface.LoadData(IEnumerable`1 machineNames, String discoveryDocRootPath, String clusterDiscoveryDocRootPath)
at Microsoft.SqlServer.Configuration.SetupExtension.RunDiscoveryAction.ExecuteAction(String actionId)
at Microsoft.SqlServer.Chainer.Infrastructure.Action.Execute(String actionId, TextWriter errorStream)
at Microsoft.SqlServer.Setup.Chainer.Workflow.ActionInvocation.ExecuteActionHelper(TextWriter statusStream, ISequencedAction actionToRun)
Inner exception type: Microsoft.SqlServer.Configuration.Sco.SqlRegistryException
Message:
The network path was not found.
Data:
WatsonData = [email protected]rror
Stack:
at Microsoft.SqlServer.Configuration.Sco.SqlRegistry.CreateBaseKey(ServiceContainer ctx, String machineName, IntPtr hKey, String keyName, RegistryAccess access, RegistryView
view)
at Microsoft.SqlServer.Configuration.Sco.SqlRegistry.GetLocalMachine(ServiceContainer ctx, String machineName, RegistryAccess access, RegistryView view)
at Microsoft.SqlServer.Discovery.DiscoveryEnumObject.GetSql2kMsiInstanceListInHive(String machineName, RegistryView regView)
at Microsoft.SqlServer.Discovery.DiscoveryEnumObject.LoadSql2kInstanceList(String machineName)
at Microsoft.SqlServer.Discovery.Product.GetData(EnumResult erParent)
at Microsoft.SqlServer.Management.Sdk.Sfc.Environment.GetData()
at Microsoft.SqlServer.Management.Sdk.Sfc.Enumerator.GetData(Object connectionInfo, Request request)
at Microsoft.SqlServer.Management.Sdk.Sfc.Enumerator.Process(Object connectionInfo, Request request)Inner exception type: Microsoft.SqlServer.Configuration.Sco.SqlRegistryException
Message:
The network path was not found.
Data:
WatsonData = [email protected]rror
Above message says that your registry is not consistent and some of the parameters are missing from registry.Or
Account installing SQL server does not have permission to access this. I think case can be here that account with which you logged into your system to install SQL Server might not have certain privileges. Can you take help
of domain admin account add it as a local administrator in this machine always right click on setup file and select run as administrator. Before this make sure you remove all SQL Server components from add remove program
I strongly recommend you to have a good look at below thread
http://support.microsoft.com/kb/2000257/en-us
Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it.
My TechNet Wiki Articles -
SEQUENCE Select within an SQL Query with an ORDER BY statement
Does anyone know why you cannot use an ORDER BY statement within an SQL query when also selecting from a SEQUENCE? My query was selecting production data as a result of a filtered search. I want to take the results of the filtered search and create a transaction. I have a sequence for generating transaction numbers where I select NEXTVAL. Since I could possibly obtain multiple, yet distinct, rows based upon my search criteria, I wanted to use an ORDER BY statement to simplify and order the resulting row(s).
I was able to get the SQL select with SEQUENCE.NEXTVAL to work without the ORDER BY, so I know that my SQL is correct. Thanks in-advance.Okay,
I understand. You want the sequence assigned first and the you want to ORDER BY. You
can do this using pipelined functions. See here:
CREATE OR REPLACE TYPE emp_rec_seq AS OBJECT (
seq NUMBER,
ename VARCHAR2 (20),
job VARCHAR2 (20),
sal NUMBER
CREATE OR REPLACE TYPE emp_tab_seq AS TABLE OF emp_rec_seq;
CREATE OR REPLACE FUNCTION get_emp_with_sequence
RETURN emp_tab_seq PIPELINED
IS
my_record emp_rec_seq := emp_rec_seq (NULL, NULL, NULL, NULL);
BEGIN
FOR c IN (SELECT dummy.NEXTVAL seq, ename, job, sal
FROM emp)
LOOP
my_record.seq := c.seq;
my_record.ename := c.ename;
my_record.job := c.job;
my_record.sal := c.sal;
PIPE ROW (my_record);
END LOOP;
RETURN;
END get_emp_with_sequence;after that, you can do a select like this:
SELECT seq, ename, job, sal
FROM TABLE (get_emp_with_sequence)
order by enamewhich will get you this:
SEQ ENAME JOB SAL
1053 BLAKE MANAGER 2850
1054 CLARK MANAGER 2450
1057 FORD ANALYST 3000
1062 JAMES CLERK 950
1055 JONES MANAGER 2975
1052 KING MANAGER 20000
1060 MARTIN SALESMAN 1250
1063 MILLER CLERK 1300
1064 DKUBICEK MANAGER 12000
1056 SCOTT ANALYST 3000
1058 SMITH CLERK 800
1061 TURNER SALESMAN 1500
1059 WARD SALESMAN 1250Denes Kubicek
http://deneskubicek.blogspot.com/
http://htmldb.oracle.com/pls/otn/f?p=31517:1
-------------------------------------------------------------------
Maybe you are looking for
-
Hi Everyone, I am unable to configure an ESB service to enqueue into an MQ queue. I have SOA Suite 10.1.3.3 and MQSeries installed on my machine (winxp), and I am working with JDeveloper 10.1.3.3. I am looking everywhere but cannot find a good guide
-
Bbandtalk sip setup cant make outbound calls
hi i have extracted the sip settings for my bbandtalk service and loaded them into my 3cx server and it has registered fine. However, I cant make outbound calls. It comes up with a message saying 'sorry you cannot make or receive calls on this line'?
-
Sync photos from two separate iCloud accounts
How do I sync photos from two separate iCloud accounts onto my PC?
-
Can't download updates on Creative Cloud
I suddenly can't download any updates, etc. I keep getting this error message: The address wasn't understood Firefox doesn't know how to open this address, because the protocol (aam) isn't associated with any program. You might need to install oth
-
Questions on image size and duration
im putting still pictures into the video timeline. Is 640x480 the proper size for TV? Is there a way to size the images in FCP or do i have to do it in photoshop? Also, im trying to make a really really quick flashing sequence of photos, but when i t