Need Heip For SQL Query
Hi Friends,
I am too muchconfused about an sql query. I've created a html page where I select one radio button . The value of this radio button is passed to the query.Now the out put of the query is used in developing the output.
For illustration I show you the source code.
Radio Button Selection page.
<form action="service.html" method="post"> <h3><strong>Services Available</strong></h3> <p> <label> <input type="radio" name="service" value="si" /> Institutions</label> <br /> <label> <input type="radio" name="service" value="sc" /> Corporate_Offices</label> <br /> <label> <input type="radio" name="service" value="sr" /> Restaurent_Cafe</label> <br /> </p> <label> <input type="submit" value="Submit" /> </label> </form>
Now the query page-
<sql:query var="empList" scope="session"> select <c:out value="${param.service}" /> from map_service where cityname = ? <sql:param value="${param.cityname}" /> </sql:query>
Now I need to generate output with the given below value in the next page-
<c:out value="${param.service}" />
This value show value as si, sc sr only where I need the database table value as per selection.
I am really confused that what I should write as <c:out value="${...
My database table has attributes as cityname, si, sc, sr. etc.
when some one select si from radio button the value of radio button is passed to sql query and the value which is selected on the table after query should be used in developing output result please help.
Dear Friend Is it not possible for any of you to give me a clue that if I've to get the output of *?* from the query what I can write in syntax.
<sql:query var="empList" scope="session">
select ? from map_service
where cityname = ?
<sql:param value="${param.service}" />
<sql:param value="${param.cityname}" />
</sql:query>
<c:out value="${empList.param.service}" />Output of the value of ? from the database select ? from map_service Any idea
Similar Messages
-
Need help for SQL Query last 5 mins Records.
I need the data between the last five minutes from a table which contains Timeid Column and data type is date.
select sysdate,(sysdate-((mod(extract(minutes from systimestamp),5)+5)/24/60)-((extract(second from systimestamp))/24/60/60)) Start_date,
(sysdate-((mod(extract(minutes from systimestamp),5))/24/60)-((extract(second from systimestamp))/24/60/60)) End_Date;
Suppose now the current time is 01:20:00PM then the output should be from
Current Date & Time Start Date & Time End Date & Time
10/18/2007 01:20:00 10/18/2007 01:10:01 10/18/2007 01:15:00
Suppose now the current time is 01:20:01 then the output should be from
Current Date & Time Start Date & Time End Date & Time
10/18/2007 01:20:01 10/18/2007 01:15:01 10/18/2007 01:20:00
The output i am getting where as i need the output shown above.
Current Date & Time Start Date & Time End Date & Time
10/18/2007 01:20:01 10/18/2007 01:14:59 10/18/2007 01:19:59SQL> select sysdate,
2 sysdate -
3 (decode(mod(to_number(to_char(sysdate,'sssss')),300),0,300,
4 mod(to_number(to_char(sysdate,'sssss')),300))+300)/(24*60*60 )
5 st_time,
6 sysdate -
7 decode(mod(to_number(to_char(sysdate,'sssss')),300),0,300,
8 mod(to_number(to_char(sysdate,'sssss')),300))/(24*60*60 )
9 end_time
10 from dual;
SYSDATE ST_TIME END_TIME
18-oct-2007 16:39:46 18-oct-2007 16:30:00 18-oct-2007 16:35:00
SQL> /
SYSDATE ST_TIME END_TIME
18-oct-2007 16:39:59 18-oct-2007 16:30:00 18-oct-2007 16:35:00
SQL> /
SYSDATE ST_TIME END_TIME
18-oct-2007 16:40:00 18-oct-2007 16:30:00 18-oct-2007 16:35:00
SQL> /
SYSDATE ST_TIME END_TIME
18-oct-2007 16:40:01 18-oct-2007 16:35:00 18-oct-2007 16:40:00 -
Hi Friends,
I am using below query to genearet one report.
{code}
distinct a.plan_id,
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = a.plan_id)
"EXT_PAN_REF",
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = b.depends_on_ba_plan_id)
"EXT_PAN_REF1",
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = c.drp_plan_id)
"EXT_PAN_REF2",
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = d.srp_plan_id)
"EXT_PAN_REF3",
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = e.DRP_TO_DRP_PLAN_ID)
"EXT_PAN_REF4",
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = f.srp_plan_id)
"EXT_PAN_REF5"
FROM BK9_T_BUSINESS_ACTIVITY a,
BK9_T_BA_DEPENDENCY b,
BK9_T_BA_DRP_DEP c,
BK9_T_BA_SRP_DEP d,
BK9_T_DRP_DEPENDENCY e,
BK9_T_SYSTEM_DEPENDENCY f
WHERE a.plan_id = b.ba_to_ba_plan_id
AND a.plan_id = c.ba_plan_id
AND a.plan_id = d.ba_plan_id
AND c.drp_plan_id = e.DRP_TO_DRP_PLAN_ID
AND e.DRP_TO_DRP_PLAN_ID = f.drp_plan_id
{code}
My output is like this :
{code}
22767 19093 19095 19049 19049 19059
22767 19093 19095 19049 19049 19060
22767 19093 19095 19062 19062 19060
22767 19093 19095 19062 19062 19061
22768 19094 19093 19062 19062 19060
22768 19094 19093 19062 19062 19061
{code}
But What i am looking is like this.
{code}
22767 19093 19095 19049 19049 19059
22767 19060
22767 19093 19095 19062 19062 19060
22767 19061
22768 19094 19093 19062 19062 19060
22768 19061
{code}
Please help.Hi,
Could you please illuminate our minds and spend a bit of time in explaining the logic? That will be much easier without reading the crystal ball which nobody has it here.
Please read: Re: 2. How do I ask a question on the forums?
And please provide sample data (create table and insert statement), description of the logic, database version and everything else which is specified in the FAQ
Regards.
Al -
Need approach for SQL query.
Hi,
This is my requirement:
Want to know whether the employee is in active assignment irrespective of year.
For example : he might have started his new assignment as of that financial year or even before. i want to check whether he is in active assignment in that year. how to approach?
Scenario:
Started an new assignement as of year 2000.Till date he is in the same assignment till date. If i check in the year 2004 it should give his status that he was in active assignment or not.
Please guide me on the same.It's been quite something since i worked on this. So, my guess is that it would be something like this.
SELECT *
FROM per_assignments_f asg
WHERE <your date> BETWEEN asg.effective_start_date AND asg.effective_end_date
AND active_flag = <whatever value is stored for active flag> -
Need help with SQL Query with Inline View + Group by
Hello Gurus,
I would really appreciate your time and effort regarding this query. I have the following data set.
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
Please Ignore '----', added it for clarity
I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
The query should return the following data set
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
The following is my query. I am kind of lost.
select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
from (
select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
from INVOICE
group by sequence_id,check_date, check_number, invoice_number, vendor_number
) A, INVOICE B
where A.sequence_id = B.sequence_id
Thanks,
NickIt looks like it is a duplicate thread - correct me if i'm wrong in this case ->
Need help with SQL Query with Inline View + Group by
Regards.
Satyaki De. -
Hello,
I need Oracle Payroll SQL Query with result:
First_name, Last_name, Payment_amount, Pay_date, Payroll_Frequency, Employement_status
Any Help would be greatful appreciatedYou will need the following tales.
per_all_people_f, per_all_assignments_f,pay_run_results,pay_run_result_values
Query would e something like :
select papf.first_name,
papf.last_name,
prrv.*
From apps.per_all_people_f papf
apps.per_all_assignments_f paaf
apps.pay_run_results prr,
apps.pay_run_result_values prrv
Where papf.person_id = paaf.person_id
and papf.business_group_id = paaf.business_group_id
and papf.current_employee_flag = 'Y'
and paaf.primary_flag ='Y'
and paaf.assignment_type = 'E'
and trunc(sysdate) between papf.effective_start_date and papf.effective_end_date
and trunc(sysdate) between paaf.effective_start_date and paaf.effective_end_date
and prr.assignment_id = paaf.assignment_id -
Need to adjust SQL query for left outer join in Crystal Reports 2008.
I need to change this SQL 2005 query.....
SELECT omnicell_anl.DeviceIDsLastMetricTable.member_id, omnicell_anl.DeviceIDsLastMetricTable.[Device Name],
omnicell_anl.DeviceIDsLastMetricTable.Account, omnicell_anl.labeledLastMetrics.PROPERTY_NAME,
omnicell_anl.labeledLastMetrics.latest_monitor_value
FROM omnicell_anl.DeviceIDsLastMetricTable LEFT OUTER JOIN
omnicell_anl.labeledLastMetrics ON omnicell_anl.DeviceIDsLastMetricTable.member_id = omnicell_anl.labeledLastMetrics.member_id
WHERE
omnicell_anl.labeledLastMetrics.PROPERTY_NAME = ?MyProperty
To this query in Crystal Reports Report Writer:
SELECT omnicell_anl.DeviceIDsLastMetricTable.member_id, omnicell_anl.DeviceIDsLastMetricTable.[Device Name],
omnicell_anl.DeviceIDsLastMetricTable.Account, omnicell_anl.labeledLastMetrics.PROPERTY_NAME,
omnicell_anl.labeledLastMetrics.latest_monitor_value
FROM omnicell_anl.DeviceIDsLastMetricTable LEFT OUTER JOIN
omnicell_anl.labeledLastMetrics ON omnicell_anl.DeviceIDsLastMetricTable.member_id = omnicell_anl.labeledLastMetrics.member_id AND
omnicell_anl.labeledLastMetrics.PROPERTY_NAME = ?MyProperty
I can't seem to get the left outer join function of Crystal Reports to emulate the same SQL query in SQL 2005. Any ideas on how I can create this same query in Crystal 2008?
Thanks,
Dominic
Edited by: Dominic Carissimi on Oct 28, 2008 7:55 PM
Edited by: Dominic Carissimi on Oct 28, 2008 7:56 PMIf you want the list of values for command level parameter then you need to add another command like
select PropertyField from table
and delete the links between this command and the existing command.
Now go to field explorer and edit the command level parameter and make it as dynamic and add the property field from newly added command.
Hope this helps!
Raghavendra -
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? -
Need a SCCM SQL Query Report for Installed Software with Packages and Applications.
I need a report that will show the number of installs of all of the workstations applications and packages over a given period of time.
This will let us know how effective our deployments are and how well the on-demand software is being adopted.
Any help?Your Install Source might be an option as most SCCM deployments will install from C:\Windows\ccmcache\xx [where xx is a random folder name]. Most software vendors will put an install source in the registry, but not all do, so it won't be completely accurate.
When software is installed manually, the install source path won't be C:\Windows\ccmcache\xx.
Here is a SQL query I have for Install Source:
SELECT v_GS_COMPUTER_SYSTEM.Name0 as 'Computer Name', v_GS_INSTALLED_SOFTWARE.ProductName0 as 'Software Title', v_GS_INSTALLED_SOFTWARE.InstallSource0 as 'Install Source', v_GS_INSTALLED_SOFTWARE.ProductVersion0 as 'Version', v_GS_INSTALLED_SOFTWARE.InstalledLocation0
as 'Installed Location', v_GS_INSTALLED_SOFTWARE.InstallDate0 as 'Install Date'
FROM v_GS_COMPUTER_SYSTEM INNER JOIN v_GS_INSTALLED_SOFTWARE ON v_GS_COMPUTER_SYSTEM.ResourceID = v_GS_INSTALLED_SOFTWARE.ResourceID
WHERE v_GS_INSTALLED_SOFTWARE.ProductName0 like '%Office 365 Pro%'
ORDER BY v_GS_COMPUTER_SYSTEM.Name0 -
Hi all,
I have data in the following manner:
CASE_NUMBER HOURS FLAG
1000 10 0
1000 20 0
1000 30 1
1000 40 0
1000 50 1
Here I need to Calculate the total hours for a Case_number till i see the flag as 1.
Here the result must be 10+20+30 Hrs
Another Example
CASE_NUMBER HOURS FLAG
2000 10 1
2000 20 1
Here the result must be only 10.
I am struggling to write a SQL query for this.
Anyones help will be very much greatful
Thanks in Advance
Regards,
Sengathir SubbarayanLook up analytical functions.
something like sum(hours) OVER (PARTITION BY case_number ORDER BY something)
will give you the sum for all rows.
Then you probably want to "throw away" those rows after the flag maybe by summing the flag column too, and throw away all those where the flag is greater than 1 and where it is equal to 1 except for the first one.
I suspect you actually have some other column (other than the number of hours) that define your order - that's what you put in the ORDER BY.
Jon -
Help needed in framing SQL query.
Hi,
I have table having following schema:
PRODUCT_ID INT
DATE DATETIME
ITEMS_SOLD INT
This table contains data for a week (sunday to saturday). I want to write an SQL query to get (filter out) PRODUCT_ID of products which has same no. of ITEMS_SOLD for all 7 days. Also for given PRODUCT_ID I need to find the longest period of successive days where the no. of ITEMS_SOLD is same for all days in this period. Eg.(PRODUCT_ID 23 was sold as following along the week in no. of units sold: 4,6,6,6,6,7,4 .So the longest period is *4 days* from Monday to Thursday.) The first condition is special case of second condition where no. of days is 7.
Any help to get the SQL query will be appreciated.
Thanks,
Akshay.PRODUCT_ID DATE ITEMS_SOLD
1 10/10/2011 3
1 11/10/2011 3
1 12/10/2011 3
1 13/10/2011 3
1 16/10/2011 5
2 10/10/2011 4
2 11/10/2011 4
2 12/10/2011 4
2 13/10/2011 4
2 14/10/2011 4
2 15/10/2011 4
2 16/10/2011 4
Output:
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
1 3 4
2 4 7
Explanation of results:
The table to be queried contains data for 1 week: from 10/10/2011(Sunday) to 16/10/2011(Saturday). Now, product with PRODUCT_ID '1' was sold on dates 10,11,12,13,16. Out of these 5 days 3 units were sold on 4 successive days (from 10-13). So output should be like :
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
1 3 4
as longest period of successive days is 4 where same no. of units were sold i.e 3 units (other period is of 1 day on 16th ).
For PRODUCT_ID 2 we have only one period of 7 days where 4 units were sold each day. So we output :
PRODUCT_ID ITEMS_SOLD NO_OF_DAYS
2 4 7
Other case where same PRODUCT_ID have different units sold on each day should be ignored.
I hope that clarifies the problem more. Let me know in case I have missed out anything which should have been mentioned.
-Akshay. -
Create a validation for SQL Query (updateable report)
Hello
I have a need for creating a validation on a SQL Query (updateable report)- type region
1)
When a row get populated i don't want same values to be populated in the second row.(as shown in first 2 rows)
Also, I don't want to have a value that falls in range in between 100 and 1000 for the period falls in the previous. (as shown in third row)
i.e
Type_id
Lower_Limit Upper_Limit Date_From Date _To
1
100 1000 1/1/2013 12/31/2013
2
100 1000 1/1/2013 12/31/2013
3
101 500 2/1/2013 10/31/2013
appreciate any help
thanks
kpThis example could help:
http://apex.oracle.com/pls/otn/f?p=31517:214
Denes Kubicek
http://deneskubicek.blogspot.com/
http://www.opal-consulting.de/training
http://apex.oracle.com/pls/otn/f?p=31517:1
------------------------------------------------------------------- -
I have a table with Columns as as below
id number primary key
object_name varchar2(100)
object_value varchar2(100)
Data is stored as follows
id object_name object_value
10 prop_num 436
20 city dallas
40 Misc 1 90
50 Misc 1 desc min amount
60 Misc 2 700
70 Misc 2 desc interest amount
80 Misc 3
80 Misc 3 desc
SQL should return result as shown below
id object_name object_value
10 prop_num 436
20 city dallas
40 min amount 90
50 interest amount 700
I have done this through plsql code by creating temp table. But I need to do it in a sql query. I am stuck here
Any pointers/help is appreciated
Thanks
Edited by: user9327712 on Mar 11, 2010 8:14 AMI have a table where the ids are stored.
*"object name"* column values are actually another table columns stored as rows here. So in our example prop_num, city,Misc 1, Misc 1 desc, Misc 2, Misc 2
desc,Misc 3 , Misc 3 desc are all columns. These would not change any time
The column object_value has values stored for respective columns.
436, dallas , 90 , min amount , 700 , interest amount are all column values. So these can change.
id object_name object_value
10 prop_num 436
20 city dallas
40 Misc 1 90
50 Misc 1 desc min amount
60 Misc 2 700
70 Misc 2 desc interest amount
80 Misc 3
90 Misc 3 desc
Edited by: user9327712 on Mar 11, 2010 9:57 AM
Edited by: user9327712 on Mar 11, 2010 10:00 AM
Edited by: user9327712 on Mar 11, 2010 10:00 AM -
Need generic dynamic sql query to generate nodes depending on dealer levels
Input table:
create table #test(dealerid integer ,dealerlvl integer)
insert into #test values(1,1)
insert into #test values(1,2)
insert into #test values(1,3)
insert into #test values(1,4)
insert into #test values(2,1)
insert into #test values(2,2)
insert into #test values(2,3)
insert into #test values(2,4)
insert into #test values(2,5)
insert into #test values(2,6)
go
create table #test2(dealerid integer,node integer,prntnode integer,dealerlvl integer)
insert into #test2 values (1,234,124,2)
insert into #test2 values (1,123,234,1)
insert into #test2 values (1,238,123,2)
insert into #test2 values (1,235,238,3)
insert into #test2 values (1,253,235,4)
insert into #test2 values (2,21674,124,3)
insert into #test2 values (2,1233,21674,1)
insert into #test2 values (2,2144,1233,2)
insert into #test2 values (2,2354,2144,3)
insert into #test2 values (2,24353,2354,4)
insert into #test2 values (2,245213,24353,5)
insert into #test2 values (2,2213,245213,6)
Expected result :
I have two test case here with dealerID1 and dealerID 2
Result for DealerID1
Result needed for DealerID2:
the levels for dealers might change (Dealer1 has 4 levels, and Dealer 2 has 6 levels) so i need to create an dynamic sql query which lists each node as separate columns depending on the levels.
I have hacked the query to give the result I need
select a.dealerid,a.node as Lvl1,b.node as lvl2,c.node as lvl3,d.node as lvl4
from #test2 a
join #test2 b on a.node=b.prntnode
join #test2 c on b.node=c.prntnode
join #test2 d on c.node=d.prntnode
where a.dealerid=1 and a.dealerlvl=2
select a.dealerid,a.node asLvl1,
b.node as lvl2,c.node as lvl3,d.node as lvl4,e.node as lvl5,f.node as lvl6--,a.dealerlvl,a.dealerid
from #test2 a
join #test2 b on a.node=b.prntnode
join #test2 c on b.node=c.prntnode
join #test2 d on c.node=d.prntnode
join #test2 e on d.node=e.prntnode
join #test2 f on e.node=f.prntnode
where a.dealerid=2 and a.dealerlvl=3
I am sure there is a better way to do this with dynamic sql. please help.
Thanks-- Dynamic PIVOT
DECLARE @T AS TABLE(y INT NOT NULL PRIMARY KEY);
DECLARE
@cols AS NVARCHAR(MAX),
@y AS INT,
@sql AS NVARCHAR(MAX);
-- Construct the column list for the IN clause
SET @cols = STUFF(
(SELECT N',' + QUOTENAME(y) AS [text()]
FROM (SELECT DISTINCT dealerlvl AS y FROM dbo.test2) AS Y
ORDER BY y
FOR XML PATH('')),
1, 1, N'');
-- Construct the full T-SQL statement
-- and execute dynamically
SET @sql = N'SELECT *
FROM (SELECT dealerid, dealerlvl, node
FROM dbo.Test2) AS D
PIVOT(MAX(node) FOR dealerlvl IN(' + @cols + N')) AS P;';
EXEC sp_executesql @sql;
GO -
Complete novice needs help getting SQL Query into Crystal Reports XI
Post Author: MissMarnie
CA Forum: Data Connectivity and SQL
So I was given an intro level web course and a monster reference guide in prep to format a report. One of our developers wrote me everything I need for the report into a SQL Query and now I'm supposed to format it in CR XII literally do not know what to do from here. I'm able to set up the correct server as a datasource, if that's useful, but I don't know how to make the querey into a bunch of formattable fields in CR. If anyone can walk me through this, I'd be so grateful. I've attempted to look up SQL query in both the help and the book but I keep hitting a wall. The help dialog says things like "press this button" with no reference to what "this button" is. I'm sure it's obvious to the knowledgeable but I'm in a complete fog. Thanks in advancePost Author: synapsevampire
CA Forum: Data Connectivity and SQL
IF you're trying to get assistance with setting up a query as the source for a report, try posting your Crystal version and the database type.
Different software works differently.
In CR 9 and above, under the connection to the database you'll see Add Command. Select that and you can paste the query in.
As for not knowing how to generate a report, that requires experience, there's no generic solution of course..
-k
Maybe you are looking for
-
How can you set up smiple video chatting on a website
Hey, I'm trying to learn how to set up video chatting for a website. I was wondering how I would even go about starting this.
-
Creating materialized view in Designer 9i
When I create a materialized view in Designer 9i it is created with 'WITH ROWID' while Oracle default is 'WITH PRIMARY KEY'. Can I configure Designer to generate mviews 'WITH PRIMARY KEY'?
-
Javascript sort() function not working correctly
I have an image gallery that automatically loads via a PHP readdir function which populates an array, and then I have a Javascript sort() function which sorts the images in order numerically. In Chrome and Safari, the images display as numbered in th
-
I am following some code on face recognition. I have my main class which is pretty straight forward import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FR extends JFrame { static Image[] trainingImages; static
-
How to pick invoice document from R/3.
Hi gurus, How to pick Invoice Documents from R/3 to BI. I am unable to find them in any of the datasources. Anyone please explain me. Regards, V N.