Query Required For sort
CREATE TABLE COUNTRIES(CID INT,CNAME VARCHAR(100))
INSERT INTO COUNTRIES VALUES(1,'AUSTRALIA')
INSERT INTO COUNTRIES VALUES(2,'INDIA')
INSERT INTO COUNTRIES VALUES(3,'FRANCE')
INSERT INTO COUNTRIES VALUES(4,'BERLIN')
SELECT * FROM COUNTRIES
o/p
CID CNAME
2 INDIA
1 AUSTRALIA
4 BERLIN
3 FRANCE
here India should be always first position remaining countries values should be in sorted order
You can use a conditional sorting =>
SELECT *
FROM COUNTRIES
ORDER BY CASE WHEN CNAME = 'INDIA'
THEN 0
ELSE 1 END,
CNAME
Olaf Helper
[ Blog] [ Xing] [ MVP]
Similar Messages
-
Dear Expert
I want the Query for to convert Value in to words,the value is the document total value.HI,
Try This It may help you
->> Create 1 UDF in Header on Requrie Documents (ex. Marketing Documents).
->> Create 3 Function in MSSQL Server Management.
->> Create 1 FMS in Query Generator and save as Query Manager then Assign to UDF for Amount in Words.
for example:
Create UDF in Header on Marketing Documents.
->> Choose Tools on Top menu.
->> User - Defined Fields. -> User Manage Fields.
->> Open the User Manage Fields Widnow.
->> Marketing Documents. -> Title.
->> Select Title and Click Add button in Bottom on User Manage Fields Window.
->> Create Amount in Words UDF(Code, Discription and Type - Character) and Add the UDF.
Create Function in MSSQL Server Management.
Check this Link, (have 3 Functions in Link).
http://techcreeze.blogspot.com/2008/11/convert-amount-into-words-according-to_15.html
1st Funciton - to Convert one Digit Number to words
2nd Funciton - to convert 2 digit number to words.
3rd Funciton - to convert amt in numbers to words.
->> Open the MSSQL Server Management Window.
->> Choose your Company database and Create NEW Query.
->> Create 3 Function Queries one by one.
->> Create 3 NEW Query Tab and 1st one put the 1st Function then Run the Function. and
2nd New Query tab put the 2nd Function then Run the Function.
3rd New Query tab put the 3rd Function then Run the Function.
Create FMS in Query Generator and Save as Query Manager.
->> Adminstration.
->> Reports. -> Query Generator.
->> Open the Query Generator and put the below FMS query.
for example : Purchase Order Doc. Toal(in wrods).
declare @Doc_total numeric (19,6)
set @Doc_total=$http://OPOR.DocTotal
select dbo.fNumToWords (@Doc_total)
->> Assign the FMS in UDF on Purchase Order.
->> Auto Refresh of Document Total.
Ex.
1. Goto the UDF and Clcik Shift+Alt+F2.
2. Select the SEARCH BY SAVED QUERY.
3. Assign the FMS Query.
4. Select the AUTO REFRESH WHEN FIELD CHENGES.
5. Select Document Total.
6. Check the Display Saved Values
I am including here, source code of functions required for converting Number into words according to Indian or Nepali Numbering style. In Indian or Nepali Numbering style, 100000 is 1 Lakh and 100 Lakhs or 10000000 is 1 Crore. This makes the numbering style different from English and International Numbering Style.
1. Function to Convert one Digit Number to words.
CREATE Function dbo.fConvertDigit(@decNumber decimal)
returns varchar(6)
as
Begin
declare
@strWords varchar(6)
Select @strWords = Case @decNumber
When '1' then 'One'
When '2' then 'Two'
When '3' then 'Three'
When '4' then 'Four'
When '5' then 'Five'
When '6' then 'Six'
When '7' then 'Seven'
When '8' then 'Eight'
When '9' then 'Nine'
Else ''
end
return @strWords
end
2. Function to convert 2 digit number to words.
CREATE Function dbo.fConvertTens(@decNumber varchar(2))
returns varchar(30)
as
Begin
declare @strWords varchar(30)
--Is value between 10 and 19?
If Left(@decNumber, 1) = 1
begin
Select @strWords = Case @decNumber
When '10' then 'Ten'
When '11' then 'Eleven'
When '12' then 'Twelve'
When '13' then 'Thirteen'
When '14' then 'Fourteen'
When '15' then 'Fifteen'
When '16' then 'Sixteen'
When '17' then 'Seventeen'
When '18' then 'Eighteen'
When '19' then 'Nineteen'
end
end
else -- otherwise it's between 20 and 99.
begin
Select @strWords = Case Left(@decNumber, 1)
When '0' then ''
When '2' then 'Twenty '
When '3' then 'Thirty '
When '4' then 'Forty '
When '5' then 'Fifty '
When '6' then 'Sixty '
When '7' then 'Seventy '
When '8' then 'Eighty '
When '9' then 'Ninety '
end
Select @strWords = @strWords + dbo.fConvertDigit(Right(@decNumber, 1))
end
--Convert ones place digit.
return @strWords
end
3. Function to convert amt in numbers to words. (Built with the help of above 2 functions)
CREATE function dbo.fNumToWords (@decNumber decimal(12, 2))
returns varchar(300)
As
Begin
Declare
@strNumber varchar(100),
@strRupees varchar(200),
@strPaise varchar(100),
@strWords varchar(300),
@intIndex integer,
@intAndFlag integer
Select @strNumber = Cast(@decNumber as varchar(100))
Select @intIndex = CharIndex('.', @strNumber)
if(@decNumber>99999999.99)
BEGIN
RETURN ''
END
If @intIndex > 0
begin
Select @strPaise = dbo.fConvertTens(Right(@strNumber, Len(@strNumber) - @intIndex))
Select @strNumber = SubString(@strNumber, 1, Len(@strNumber) - 3)
If Len(@strPaise) > 0 Select @strPaise = @strPaise + ' paise'
end
Select @strRupees = ''
Select @intIndex=len(@strNumber)
Select @intAndFlag=2
while(@intIndex>0)
begin
if(@intIndex=8)
begin
Select @strRupees=@strRupees+dbo.fConvertDigit(left(@decNumber,1))+' Crore '
Select @strNumber=substring(@strNumber,2,len(@strNumber))
Select @intIndex=@intIndex-1
end
else if(@intIndex=7)
begin
if(substring(@strNumber,1,1)='0')
begin
if substring(@strNumber,2,1)<>'0'
begin
if (@strRupees<>NULL and substring(@strNumber,3,1)='0' and substring(@strNumber,4,1)='0' and substring(@strNumber,5,1)='0' and substring(@strNumber,6,1)='0' and substring(@strNumber,7,1)='0' and @intAndFlag=2 and @strPaise=NULL)
begin
Select @strRupees=@strRupees+' and ' +dbo.fConvertDigit(substring(@strNumber,2,1))+' Lakh '
Select @intAndFlag=1
end
else
begin
Select @strRupees=@strRupees+dbo.fConvertDigit(substring(@strNumber,2,1))+' Lakh '
end
Select @strNumber=substring(@strNumber,3,len(@strNumber))
Select @intIndex=@intIndex-2
end
else
begin
Select @strNumber=substring(@strNumber,3,len(@strNumber))
Select @intIndex=@intIndex-2
end
end
else
begin
if(substring(@strNumber,3,1)='0' and substring(@strNumber,4,1)='0' and substring(@strNumber,5,1)='0' and substring(@strNumber,6,1)='0' and substring(@strNumber,7,1)='0' and @intAndFlag=2 and @strPaise='')
begin
Select @strRupees=@strRupees+' and ' + dbo.fConvertTens(substring(@strNumber,1,2))+' Lakhs '
Select @intAndFlag=1
end
else
begin
Select @strRupees=@strRupees+dbo.fConvertTens(substring(@strNumber,1,2))+' Lakhs '
end
Select @strNumber=substring(@strNumber,3,len(@strNumber))
Select @intIndex=@intIndex-2
end
end
else if(@intIndex=6)
begin
if(substring(@strNumber,2,1)<>'0' or substring(@strNumber,3,1)<>'0' and substring(@strNumber,4,1)='0' and substring(@strNumber,5,1)='0' and substring(@strNumber,6,1)='0' and @intAndFlag=2 and @strPaise='')
begin
if len(@strRupees) <= 0
begin
if convert(int,substring(@strNumber,1,1)) = 1
begin
Select @strRupees=@strRupees+'' + dbo.fConvertDigit(substring(@strNumber,1,1))+' Lakh '
Select @intAndFlag=2
end
else
begin
Select @strRupees=@strRupees+'' + dbo.fConvertDigit(substring(@strNumber,1,1))+' Lakhs '
Select @intAndFlag=2
end
end
else
begin
if convert(int,substring(@strNumber,1,1)) = 1
begin
Select @strRupees=@strRupees+' and' + dbo.fConvertDigit(substring(@strNumber,1,1))+' Lakh '
Select @intAndFlag=1
end
else
begin
Select @strRupees=@strRupees+' and' + dbo.fConvertDigit(substring(@strNumber,1,1))+' Lakhs '
Select @intAndFlag=1
end
end
end
else
begin
if convert(int,substring(@strNumber,1,1)) = 1
begin
Select @strRupees=@strRupees+dbo.fConvertDigit(substring(@strNumber,1,1))+' Lakh '
end
else
begin
Select @strRupees=@strRupees+dbo.fConvertDigit(substring(@strNumber,1,1))+' Lakhs '
end
end
Select @strNumber=substring(@strNumber,2,len(@strNumber))
Select @intIndex=@intIndex-1
end
else if(@intIndex=5)
begin
if(substring(@strNumber,1,1)='0')
begin
if substring(@strNumber,2,1)<>'0'
begin
if(substring(@strNumber,3,1)='0' and substring(@strNumber,4,1)='0' and substring(@strNumber,5,1)='0' and @intAndFlag=2 and @strPaise='')
begin
Select @strRupees=@strRupees+' and ' +dbo.fConvertDigit(substring(@strNumber,2,1))+' Thousand '
Select @intAndFlag=1
end
else
begin
Select @strRupees=@strRupees+dbo.fConvertDigit(substring(@strNumber,2,1))+' Thousand '
end
Select @strNumber=substring(@strNumber,3,len(@strNumber))
Select @intIndex=@intIndex-2
end
else
begin
Select @strNumber=substring(@strNumber,3,len(@strNumber))
Select @intIndex=@intIndex-2
end
end
else
begin
if(substring(@strNumber,3,1)='0' and substring(@strNumber,4,1)='0' and substring(@strNumber,5,1)='0' and @intAndFlag=2 and @strPaise='')
begin
Select @strRupees=@strRupees+' and '+dbo.fConvertTens(substring(@strNumber,1,2))+' Thousand '
Select @intAndFlag=1
end
else
begin
Select @strRupees=@strRupees+dbo.fConvertTens(substring(@strNumber,1,2))+' Thousand '
end
Select @strNumber=substring(@strNumber,3,len(@strNumber))
Select @intIndex=@intIndex-2
end
end
else if(@intIndex=4)
begin
if ( (substring(@strNumber,3,1)<>'0' or substring(@strNumber,4,1)<>'0') and substring(@strNumber,2,1)='0' and @intAndFlag=2 and @strPaise='')
begin
Select @strRupees=@strRupees+' and' + dbo.fConvertDigit(substring(@strNumber,1,1))+' Thousand '
Select @intAndFlag=1
end
else
begin
Select @strRupees=@strRupees+dbo.fConvertDigit(substring(@strNumber,1,1))+' Thousand '
end
Select @strNumber=substring(@strNumber,2,len(@strNumber))
Select @intIndex=@intIndex-1
end
else if(@intIndex=3)
begin
if substring(@strNumber,1,1)<>'0'
begin
Select @strRupees=@strRupees+dbo.fConvertDigit(substring(@strNumber,1,1))+' Hundred '
Select @strNumber=substring(@strNumber,2,len(@strNumber))
if( (substring(@strNumber,1,1)<>'0' or substring(@strNumber,2,1)<>'0') and @intAndFlag=2 )
begin
Select @strRupees=@strRupees+' and '
Select @intAndFlag=1
end
Select @intIndex=@intIndex-1
end
else
begin
Select @strNumber=substring(@strNumber,2,len(@strNumber))
Select @intIndex=@intIndex-1
end
end
else if(@intIndex=2)
begin
if substring(@strNumber,1,1)<>'0'
begin
Select @strRupees=@strRupees+dbo.fConvertTens(substring(@strNumber,1,2))
Select @intIndex=@intIndex-2
end
else
begin
Select @intIndex=@intIndex-1
end
end
else if(@intIndex=1)
begin
if(@strNumber<>'0')
begin
Select @strRupees=@strRupees+dbo.fConvertDigit(@strNumber)
end
Select @intIndex=@intIndex-1
end
continue
end
if len(@strRupees)>0 Select @strRupees=@strRupees+ ' rupees '
IF(len(@strPaise)<>0)
BEGIN
if len(@strRupees)>0 Select @strRupees=@strRupees + ' and '
END
Select @strWords = IsNull(@strRupees, '') + IsNull(@strPaise, '')
select @strWords = @strWords + ' only'
Return @strWords
End
Regards
Balaji Sampath -
Query required for JE posted with the customer
Dear Experts,
Following is the scenario - Accountant passes Journal Entries once in a while with regard to customers also, i would require a alert for the scenario.
Whenever the user posts a JE with regard to a customer alert has to generate to the manager else a query report is required would do.
SaravananHi,
You can use the below as an alert for Manual Journal Entries that has been created the last 2 days with posting to Business Partner account.
SELECT t0.transid, t0.shortname
FROM JDT1 T0 INNER JOIN OJDT T1 ON T0.TransId = T1.TransId
WHERE shortname <> account and T1.createdate > getdate()-2 and t0.transtype = 30
If you want to have a different date range just change the '-2' to the amount of days you want, if you only want entries created today, just remore it. If you prefer it to be by posting date rather than by creaation (system) date, just change createdate to refdate.
Hope it helps,
Jesper -
Query required for below situation.
Hi All,
I have two table
T1 --> deal_site_id, subsection_id
T2 --> deal_site_id, subsection_id, catalog_id
requirement is first I need to check all the subsection_id in table T1 depending upon one deal_site_id.
Then what ever subsection_id I get from table T1 I need to check if those are available in table T2. If they are available then do nothing but if they are not available in table T2 then delete the row from table T1.
I've tried to write the query like below but stuck with exception.
DELETE FROM (SELECT * FROM T1 lid inner join T2 ld
ON LID.DEAL_SITE_ID = LD.DEAL_SITE_ID
WHERE lid.deal_site_id = 3070
AND LD.SUBSECTION_ID NOT IN (SELECT DISTINCT liod.subsection_id from T1 liod where liod.deal_site_id = 3070 )
this is giving me an exception like ORA-01752: cannot delete from view without exactly one key-preserved table
Please help me to write this query. Thanks in advance.
Regards,
Subhadeep
Edited by: sumajumd on Feb 2, 2012 3:08 AMHi, Subhadeep,
That sounds like:
DELETE FROM t1
WHERE deal_site_id = 3070 -- or whatever
AND subsection_id NOT IN (
SELECT subsection_id
FROM t2
WHERE deal_site_id = t1.deal_site_id
AND subsection_id IS NOT NULL -- If necessary
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
In the case of a DML operation (such as DELETE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using. -
Below is the condition for which a query is to be written.
as of now this the query i have written. am getting the orderids which satisfy this rule but the output should include all those orderids which already satisfy the rule.(i.e the current o/p contains those orderids which share a common circuitid and have same start and end dates. the output required should include this as well as those orderids tat do not share circuitids.
or
the o/p should contain those orderids which do not fall into any of these categories)
The Rule:
For the Entity Circuit Orders if the Circuit Id is same for two different order IDs then the Order Start Date for the Order Id having Order Status as Installed should be same as the Order End Date for the Order Id having Order Status as Retired.
Tthe query:
select order_id from managed_element1 where order_status = 'I' and order_start_date in
(select order_end_date from managed_element1 where circuit_id in
(SELECT circuit_id FROM managed_element1 where order_status='R' GROUP BY circuit_id))The data is as below
Order_id circuit_id start_date end_date order_status
ORDER_67 BORDER_2 03/05/06 05/09/06 R
ORDER_7 BORDER_6 10/26/06 I
ORDER_11 BORDER_7 12/05/06 12/06/07 I
ORDER_1 BORDER_2 05/09/06 05/19/06 R
ORDER_2 BORDER_2 05/19/06 I
ORDER_3 BORDER_3 04/03/06 05/20/06 R
ORDER_4 BORDER_3 05/20/06 I
ORDER_5 BORDER_4 02/05/06 05/06/06 R
ORDER_6 BORDER_4 05/05/06 I
ORDER_7 BORDER_5 10/22/02 02/23/03 R
ORDER_8 BORDER_5 02/23/03 I
ORDER_9 BORDER_6 03/12/06 09/26/06 R
ORDER_10 BORDER_6 09/26/0610/26/06 R -
Logic required for Sort in ALV
Hi All,
I am dowloding the ALV report layout in excel sheet thorough mailing functionality.
I want to implenemnt the dynamic sort. Here I am writing this.but i want the logic for below code.
CALL FUNCTION 'LT_DBDATA_READ_FROM_LTDX'
EXPORTING
I_TOOL = 'LT'
IS_VARKEY = W_VARKEY_EU
TABLES
T_DBFIELDCAT = IT_DBFIELDCAT_EU
T_DBSORTINFO = IT_DBSORTINFO
T_DBFILTER = IT_FILTER_LAYOUT
T_DBLAYOUT = IT_DB_LAYOUT.
LIT_DBSORTINFO[] = IT_DBSORTINFO[].
SORT LIT_DBSORTINFO[] BY KEY1.
DELETE ADJACENT DUPLICATES FROM LIT_DBSORTINFO[] COMPARING KEY1.
LOOP AT LIT_DBSORTINFO[].
CLEAR: LW_SPOS,
LW_UP,
LW_DOWN,
LW_SUBTOT,
LW_COMP,
LW_EXPA,
LW_GROUP.
CLEAR IT_DBSORTINFO[].
READ TABLE IT_DBSORTINFO WITH KEY
KEY1 = LIT_DBSORTINFO-KEY1
PARAM = 'SPOS'.
IF SY-SUBRC = 0.
LW_SPOS = IT_DBSORTINFO-VALUE.
ENDIF.
CLEAR IT_DBSORTINFO.
READ TABLE IT_DBSORTINFO WITH KEY
KEY1 = LIT_DBSORTINFO-KEY1
PARAM = 'UP'.
IF SY-SUBRC = 0.
LW_UP = IT_DBSORTINFO-VALUE.
ENDIF.
CLEAR IT_DBSORTINFO.
READ TABLE IT_DBSORTINFO WITH KEY
KEY1 = LIT_DBSORTINFO-KEY1
PARAM = 'DOWN'.
IF SY-SUBRC = 0.
LW_DOWN = IT_DBSORTINFO-VALUE.
ENDIF.
CLEAR IT_DBSORTINFO.
READ TABLE IT_DBSORTINFO WITH KEY
KEY1 = LIT_DBSORTINFO-KEY1
PARAM = 'SUBTOT'.
IF SY-SUBRC = 0.
LW_SUBTOT = IT_DBSORTINFO-VALUE.
ENDIF.
CLEAR IT_DBSORTINFO.
READ TABLE IT_DBSORTINFO WITH KEY
KEY1 = LIT_DBSORTINFO-KEY1
PARAM = 'COMP'.
IF SY-SUBRC = 0.
LW_COMP = IT_DBSORTINFO-VALUE.
ENDIF.
CLEAR IT_DBSORTINFO.
READ TABLE IT_DBSORTINFO WITH KEY
KEY1 = LIT_DBSORTINFO-KEY1
PARAM = 'EXPA'.
IF SY-SUBRC = 0.
LW_EXPA = IT_DBSORTINFO-VALUE.
ENDIF.
CLEAR IT_DBSORTINFO.
READ TABLE IT_DBSORTINFO WITH KEY
KEY1 = LIT_DBSORTINFO-KEY1
PARAM = 'GROUP'.
IF SY-SUBRC = 0.
LW_GROUP = IT_DBSORTINFO-VALUE.
ENDIF.
LOOP AT IT_ALV_DATA FROM W_LOOP_FROM_EU TO W_LOOP_TO_EU.
LW_TABIX = SY-TABIX.
READ TABLE IT_FIELDCAT INTO LW_FIELDCAT WITH KEY
FIELDNAME = LIT_DBSORTINFO-KEY1.
IF SY-SUBRC = 0.
ASSIGN COMPONENT SY-TABIX OF
STRUCTURE IT_ALV_DATA TO <LFS>.
IF SY-SUBRC = 0.
CLEAR LW_CHAR.
LW_CHAR = <LFS>.
IF LW_SPOS= 'SPOS'.
LOGIC Required
ENDIF.
ELSEIF LW_OPTION = 'DOWN'.
LOgic required
ENDIF.
ENDIF.
ENDLOOP.
ENDLOOP.
regards,
Ajay reddyHai,
Let
1)general data
2)all customers
3)company code data
4)sales organization data
are the check box names,Then
Just use the piece of code below:
<b>IF general data = 'X'.
COUNT = COUNT + 1.
ENDIF.
IF all_customers = 'X'.
COUNT = COUNT + 1.
ENDIF.
IF company_code_data = 'X'.
COUNT = COUNT + 1.
ENDIF.
IF sales_organization_data = 'X'.
COUNT = COUNT + 1.
ENDIF.</b>
Now check whether more than one Check Boxes are selected or not
<b>IF COUNT GT 1.
"* Do the oprations what ever you want here
ENDIF.</b>
<b>Reward points if it helps you.</b>
Regds,
Rama chary.Pammi -
Query Requirement for Stock on hand.
Hi All,
Actually I am have written a query for showing a running total for an Item with all Sales Order and Purchase Order order by ship date (due date).
SELECT T0.[ItemCode], T0.[ShipDate],t2.[CardCode],t4.[OnHand],-T0.[OpenQty]*t4.[NumInSale] as StockMovt FROM RDR1 T0 INNER JOIN ORDR T2 ON T0.DocEntry = T2.DocEntry INNER JOIN OITM T4 ON T0.[ItemCode]=t4.[ItemCode] WHERE T0.[ItemCode] =[%0] and T2.[DocStatus] ='o'
UNION
SELECT T1.[ItemCode], T1.[ShipDate],t3.[CardCode], t5.[OnHand], T1.[OpenQty] as StockMovt FROM POR1 T1 INNER JOIN OPOR T3 ON T1.DocEntry = T3.DocEntry INNER JOIN oitm t5 ON T1.[ItemCode]=t5.[ItemCode] WHERE T1.[ItemCode]=[%0] and T3.[DocStatus] = 'o' ORDER BY [ShipDate]
What i require is the additional field which shows the cumulative or running total for each record. Can anyone please help in how it can be achived.
Thanks & Regards
ShivaHi Prasanna,
I made some modification to ur query and its perfectly working. I still have the other query...can you please help me.
The out put that you have asked for is as follows
# ItemCode ShipDate CardCode OnHand StockMovt
1 BAS3B 04.06.09 AUCHRA 14,320.00 -108
2 BAS3B 04.06.09 BLUMER 14,320.00 0
3 BAS3B 04.06.09 GREENTsup 14,320.00 0
4 BAS3B 05.06.09 bizzy 14,320.00 -12
5 BAS3B 05.06.09 BROWNT 14,320.00 -120
6 BAS3B 18.06.09 GOODVI 14,320.00 0
7 BAS3B 26.06.09 COLMAN 14,320.00 -15,000.00
8 BAS3B 30.06.09 GREENTsup 14,320.00 3,000.00
9 BAS3B 21.07.09 GREENTsup 14,320.00 5,000.00
10 BAS3B 03.08.09 BEALES 14,320.00 -12
11 BAS3B 05.08.09 ACORN 14,320.00 -6
12 BAS3B 16.08.09 JLEWBS 14,320.00 -120
13 BAS3B 22.08.09 GREENTsup 14,320.00 1,000.00
14 BAS3B 22.08.09 GREENTsup 14,320.00 2,000.00
15 BAS3B 25.08.09 BEALES 14,320.00 -6
16 BAS3B 25.08.09 GREENTsup 14,320.00 2,000.00
17 BAS3B 27.08.09 BEALES 14,320.00 -6
18 BAS3B 27.08.09 ELIZAS 14,320.00 -24
19 BAS3B 01.10.09 GATES 14,320.00 -120
20 BAS3B 15.01.10 GREENTsup 14,320.00 2,000.00
Further to this I need a running total for the stock movement. Basically it nothing but the difference between the last two columns.
Regards
Shiva -
Query required for xml processing.
This data is present in clob i need to extract the below mentioned field.
expected query is
select
extractvalue( xmltype(table1.column1), '/UserProfileSnapshot/UserInfo/Attribute[@name="Users.Display Name"]' )
from table1
first line is incorrect <?xml version = '1.0' encoding = 'UTF-8'?>
Can anyone please help me in making a query for this incorrect clob data.
As we cannot change this first line in data.
"<?xml version = '1.0' encoding = 'UTF-8'?>
<UserProfileSnapshot key="224" version="1.0">
<UserInfo>
<Attribute name="Users.Display Name">testfuturedate102, Mr. user</Attribute>
<Attribute name="USR_UDF_HR_ORG_ID">202</Attribute>
<Attribute name="Users.Xellerate Type">End-User</Attribute>
<Attribute name="Users.Role">Employee</Attribute>
<Attribute name="Users.First Name">user</Attribute>
<Attribute name="Users.Status">Active</Attribute>
<Attribute name="USR_UDF_LOCATION_ID">1737</Attribute>
<Attribute name="Users.Provisioned Date">2013-04-23 10:04:48 -0400</Attribute>
<Attribute name="Title">MR.</Attribute>
<Attribute name="USR_UDF_LOCATION_CODE">HR- New York</Attribute>
<Attribute name="Country">US</Attribute>
<Attribute name="State">NY</Attribute>
<Attribute name="Users.Password Reset Attempts Counter">0</Attribute>
<Attribute name="Users.Disable User">0</Attribute>
<Attribute name="Users.Change Password At Next Logon">1</Attribute>
<Attribute name="USR_CN_GENERATED">0</Attribute>
<Attribute name="USR_UDF_EFFECTIVE_START_DATE">2013-03-08 00:00:00 -0500</Attribute>
<Attribute name="Postal Code">10001</Attribute>
<Attribute name="Users.Update Date">2013-04-23 10:04:48 -0400</Attribute>
<Attribute name="Employee Number">2335</Attribute>
<Attribute name="USR_UDF_DEPARTMENT_NAME">Vision Corporation</Attribute>
<Attribute name="Users.Last Name">testfuturedate102</Attribute>
<Attribute name="Users.End Date">4712-12-31 00:00:00 -0500</Attribute>
<Attribute name="Hire Date">2013-02-28 00:00:00 -0500</Attribute>
<Attribute name="USR_UDF_PERSON_ID">31967</Attribute>
<Attribute name="USR_UDF_IS_MANAGER">N</Attribute>
<Attribute name="Users.Creation Date">2013-04-23 10:04:48 -0400</Attribute>
<Attribute name="Street">500 Madison Ave</Attribute>
<Attribute name="Users.User ID">31967</Attribute>
<Attribute name="USR_UDF_CITY">New York</Attribute>
<Attribute name="Users.Lock User">0</Attribute>
<Attribute name="Users.Updated By Login" key="4">OIMINTERNAL</Attribute>
<Attribute name="Users.Created By Login" key="4">OIMINTERNAL</Attribute>
<Attribute name="Users.Login Attempts Counter">0</Attribute>
<Attribute name="Organizations.Organization Name" key="4">Integra</Attribute>
</UserInfo>
</UserProfileSnapshot>"As said in {thread:id=2545133}, the quotes are certainly not the issue.
This works fine for me on 11.2.0.2 :
SQL> insert into table1 (column1)
2 values (
3 '<?xml version = ''1.0'' encoding = ''UTF-8''?>
4 <UserProfileSnapshot key="224" version="1.0">
5 <UserInfo>
6 <Attribute name="Users.Display Name">testfuturedate102, Mr. user</Attribute>
7 <Attribute name="USR_UDF_HR_ORG_ID">202</Attribute>
8 <Attribute name="Users.Xellerate Type">End-User</Attribute>
9 <Attribute name="Users.Role">Employee</Attribute>
10 <Attribute name="Users.First Name">user</Attribute>
11 <Attribute name="Users.Status">Active</Attribute>
12 <Attribute name="USR_UDF_LOCATION_ID">1737</Attribute>
13 <Attribute name="Users.Provisioned Date">2013-04-23 10:04:48 -0400</Attribute>
14 <Attribute name="Title">MR.</Attribute>
15 <Attribute name="USR_UDF_LOCATION_CODE">HR- New York</Attribute>
16 <Attribute name="Country">US</Attribute>
17 <Attribute name="State">NY</Attribute>
18 <Attribute name="Users.Password Reset Attempts Counter">0</Attribute>
19 <Attribute name="Users.Disable User">0</Attribute>
20 <Attribute name="Users.Change Password At Next Logon">1</Attribute>
21 <Attribute name="USR_CN_GENERATED">0</Attribute>
22 <Attribute name="USR_UDF_EFFECTIVE_START_DATE">2013-03-08 00:00:00 -0500</Attribute>
23 <Attribute name="Postal Code">10001</Attribute>
24 <Attribute name="Users.Update Date">2013-04-23 10:04:48 -0400</Attribute>
25 <Attribute name="Employee Number">2335</Attribute>
26 <Attribute name="USR_UDF_DEPARTMENT_NAME">Vision Corporation</Attribute>
27 <Attribute name="Users.Last Name">testfuturedate102</Attribute>
28 <Attribute name="Users.End Date">4712-12-31 00:00:00 -0500</Attribute>
29 <Attribute name="Hire Date">2013-02-28 00:00:00 -0500</Attribute>
30 <Attribute name="USR_UDF_PERSON_ID">31967</Attribute>
31 <Attribute name="USR_UDF_IS_MANAGER">N</Attribute>
32 <Attribute name="Users.Creation Date">2013-04-23 10:04:48 -0400</Attribute>
33 <Attribute name="Street">500 Madison Ave</Attribute>
34 <Attribute name="Users.User ID">31967</Attribute>
35 <Attribute name="USR_UDF_CITY">New York</Attribute>
36 <Attribute name="Users.Lock User">0</Attribute>
37 <Attribute name="Users.Updated By Login" key="4">OIMINTERNAL</Attribute>
38 <Attribute name="Users.Created By Login" key="4">OIMINTERNAL</Attribute>
39 <Attribute name="Users.Login Attempts Counter">0</Attribute>
40 <Attribute name="Organizations.Organization Name" key="4">Integra</Attribute>
41 </UserInfo>
42 </UserProfileSnapshot>'
43 );
1 row inserted
SQL>
SQL> select x.*
2 from table1 t
3 , xmltable(
4 '/UserProfileSnapshot/UserInfo'
5 passing xmltype(t.column1)
6 columns userdisplay_name varchar2(30) path 'Attribute[@name="Users.Display Name"]'
7 , user_role varchar2(30) path 'Attribute[@name="Users.Role"]'
8 ) x ;
USERDISPLAY_NAME USER_ROLE
testfuturedate102, Mr. user Employee -
Query required for the below result format:
Table(DATA):
Bank_id Device_type Status date Station_status
1011 N Y 3/23/2012 DOWN
1011 N Y 3/23/2012 up
1011 N y 3/23/2012 up
1011 E Y 3/23/2012 down
1011 E I 3/23/2012 down
1011 W Y 3/23/2012 up
1012 N Y 3/23/2012 DOWN
1012 N Y 3/23/2012 up
1012 N y 3/23/2012 up
1012 E Y 3/23/2012 down
1012 E I 3/23/2012 down
1012 W Y 3/23/2012 up
1013 N Y 3/23/2012 DOWN
1013 N Y 3/23/2012 up
1013 N y 3/23/2012 up
1013 E Y 3/23/2012 down
1013 E I 3/23/2012 down
1013 W Y 3/23/2012 up
(SELECT QUERY RESULT SHOULD BE LIKE THIS):Report result:
Bank_id----Date-----TOTAL---UP_STATUS--DOWN_STATUS-----DEVICE
1011 3/23/2012 6 3 3 N<2>N<1>,E<0>E<2>,W<1>W<0>
1012 3/23/2012 6 3 3 N<2>N<1>,E<0>E<2>,W<1>W<0>
1013 3/23/2012 6 3 3 N<2>N<1>,E<0>E<2>,W<1>W<0>
N<2>N<1>,E<0>E<2>,W<1>W<0> this mean(INDICATES)
In N 2 UP 1 DOWN
IN E 0 up 2 down
In W 1 up 0 down
SCRIPTS:
CREATE TABLE FIMS_TEST
BANK_ID VARCHAR2(10 BYTE),
DEVICE_TYPE VARCHAR2(10 BYTE),
STATUS VARCHAR2(1 BYTE),
DATE_TS DATE,
STATION_STATUS VARCHAR2(10 BYTE)
INSERT SCRIPT:
SET DEFINE OFF;
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1011', 'N', 'Y', TO_DATE('03/26/2012 16:30:48', 'MM/DD/YYYY HH24:MI:SS'), 'DOWN');
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1011', 'N', 'Y', TO_DATE('03/26/2012 16:32:26', 'MM/DD/YYYY HH24:MI:SS'), 'UP');
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1011', 'N', 'Y', TO_DATE('03/26/2012 16:32:55', 'MM/DD/YYYY HH24:MI:SS'), 'UP');
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1011', 'E', 'Y', TO_DATE('03/26/2012 16:33:51', 'MM/DD/YYYY HH24:MI:SS'), 'DOWN');
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1011', 'I', 'Y', TO_DATE('03/26/2012 16:34:15', 'MM/DD/YYYY HH24:MI:SS'), 'DOWN');
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1011', 'W', 'Y', TO_DATE('03/26/2012 16:34:39', 'MM/DD/YYYY HH24:MI:SS'), 'UP');
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1012', 'N', 'Y', TO_DATE('03/26/2012 16:35:13', 'MM/DD/YYYY HH24:MI:SS'), 'DOWN');
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1012', 'N', 'Y', TO_DATE('03/26/2012 16:35:56', 'MM/DD/YYYY HH24:MI:SS'), 'UP');
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1012', 'N', 'Y', TO_DATE('03/26/2012 16:36:48', 'MM/DD/YYYY HH24:MI:SS'), 'UP');
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1012', 'E', 'Y', TO_DATE('03/26/2012 16:37:17', 'MM/DD/YYYY HH24:MI:SS'), 'DOWN');
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1012', 'E', 'I', TO_DATE('03/26/2012 16:37:42', 'MM/DD/YYYY HH24:MI:SS'), 'DOWN');
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1012', 'W', 'Y', TO_DATE('03/26/2012 16:38:10', 'MM/DD/YYYY HH24:MI:SS'), 'UP');
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1013', 'N', 'Y', TO_DATE('03/26/2012 16:38:37', 'MM/DD/YYYY HH24:MI:SS'), 'DOWN ');
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1013', 'N', 'Y', TO_DATE('03/26/2012 16:39:23', 'MM/DD/YYYY HH24:MI:SS'), 'UP');
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1013', 'N', 'Y', TO_DATE('03/26/2012 16:39:54', 'MM/DD/YYYY HH24:MI:SS'), 'UP');
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1013', 'E', 'Y', TO_DATE('03/26/2012 16:40:19', 'MM/DD/YYYY HH24:MI:SS'), 'DOWN');
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1013', 'E', 'I', TO_DATE('03/26/2012 16:40:53', 'MM/DD/YYYY HH24:MI:SS'), 'DOWN');
Insert into TEST.FIMS_TEST
(BANK_ID, DEVICE_TYPE, STATUS, DATE_TS, STATION_STATUS)
Values
('1013', 'W', 'Y', TO_DATE('03/26/2012 16:41:17', 'MM/DD/YYYY HH24:MI:SS'), 'UP');
COMMIT;thanks in advance
can any one help me please -
Query needed for sorting by time value
Hi Folks
We have table it consists two columns like below
Job_name varchar2(50)
Scheduled_time date
The filed scheduled time keep date and time value like below
25-Jul-2009 4:00:10 AM
26-Jul-2009 4:00:01 PM
27-Jul-2009 4:00:00 PM
28-Jul-2009 4:05:00 PM
01-Jul-2009 4:06:00 PM
02-Jun-2009 4:15:40 AM
We need output as sorting by time value NOT date value. Expected output to be below
25-Jul-2009 4:00:10 AM
02-Jun-2009 4:15:40 AM
27-Jul-2009 4:00:00 PM
26-Jul-2009 4:00:01 PM
28-Jul-2009 4:05:00 PM
01-Jul-2009 4:06:00 PM
I am using oracle 10G
Thanks in AdvanceHere's how :
SQL> create table job_table (job_name varchar2(50) not null, scheduled_time date);
Table created.
SQL> insert into job_table
2 values ('Job_abc',to_date('25-JUL-2009 04:00:00','DD-MON-YYYY HH24:MI:SS'));
1 row created.
SQL> insert into job_table
2 values ('Job_fdw',to_date('02-JUN-2009 04:15:40','DD-MON-YYYY HH24:MI:SS'));
1 row created.
SQL> insert into job_table
2 values ('Job_fxj',to_date('27-JUL-2009 03:59:00','DD-MON-YYYY HH24:MI:SS'));
1 row created.
SQL> insert into job_table
2 values ('Job_rjt',to_date('20-JUL-2009 14:59:00','DD-MON-YYYY HH24:MI:SS'));
1 row created.
SQL> commit;
Commit complete.
SQL> alter session set nls_date_format='DD-MON-YYYY HH:MI:SS AM';
Session altered.
SQL> select job_name, scheduled_time from job_table
2 order by to_char(scheduled_time,'HH24:MI:SS');
JOB_NAME SCHEDULED_TIME
Job_fxj 27-JUL-2009 03:59:00 AM
Job_abc 25-JUL-2009 04:00:00 AM
Job_fdw 02-JUN-2009 04:15:40 AM
Job_rjt 20-JUL-2009 02:59:00 PM
SQL> -
Why Data Sort is required for Merge Join Transformation
hi,
In my understanding Merge Join works very similar to T SQL joins. But I am trying to understand why Sort is a compulsory requirement? I have looked into following article but not helpful
http://technet.microsoft.com/en-us/library/ms137653(v=sql.105).aspx
aamertaimor
aamertaimorMerge Join is going to walk through two sets in the order that you gave in your input or using the Sort transformation. So, it loads one record from one input and one record from the second input. If the keys match, it will output the row with information
from both inputs. If the left input has a value that is less than the value in right input, then either the row from the left input is sent out with no right input information (if there is an outer join) or if the join is an inner join, the
Merge Join component will get the next row from Left input. If the right input has a value that is less than the value that in the left input, then if there is a full outer join, output the right input with no left input information otherwise, get the
next row from the right input.
Here is the beauty, SSIS only needs to retain a couple rows in memory.
What if Microsoft decided that there is no requirement for sorting? Then in order for the Merge join to work is that it would load all of the rows from one input into memory and then the Merge Join would look up the row in memory. That means
a large amount of memory would be needed.
By the way, if you want Merge Join behavior without the sort, use a Lookup component.
Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com -
How to search in BI 7.1 query designer for the required key figures & chars
Hi All,
Can anyone plz tell me how to search in BI 7.1 query designer for the required key figures & characteristics. I have the query being built on a multiprovider which has many cubes.
So, i have a huge list of key figures and characteristics. I am not able to search for the required one by the name or the technical name.
How can we search and pick the required object from the enormous list of the Mutliprovider in the Bex Query Designer??
Thanks
PhaniThere is not a search feature available. You have to do an educated guess under what dimension your infoobject could be and select.
-
Which authorizations are required for assigning a query to a role?
Hi everybody,
we try to set up some roles for "reporting power users". These guys should be alble to define new queries using BEx (works fine) and also should be able to assign these new defined queries to a role, so other users can use these roles.
The idea is simple, but we're searching for the right authorization object (or - as i suppose - set of authorization objects) that enables the user to assign a query to a role (using that "enter to a role" button in the open / save dialog).
At the moment, the user can user that button, and the role, he should the query assigned to is shown. After selecting the role and clicking button "create" it take some seconds and a message "error when saving. entry has not been created" is shown.
Obviously, there is a problem with writing the role (or adding the new information to that role).
So, could anyone help me and provide me with a list of authorization objects that are required.
Thanks in advance,
AlfredS_RFC
S_TCODE
S_USER_GRP
S_BDS_D
S_OD_SEND
S_RS_AUTH
S_RS_BCS
S_RS_COMP
S_RS_COMP1
S_RS_FOLD
S_RS_ICUBE
S_RS_MPRO
The above mentioned authorization objects are enough to add in the role and required for the accessing a query.
particularly, S_RS_COMP, S_RS_COMP1, S_RS_MPRO, S_RS_ICUBE are the most important auth objects which are directly getting involved in authorization of a query in a role.
SO, you have to assign the respective info area, info cube and info providers names in these auth objects.
The same scenario , i am using in my project to give access to the queries in all the areas for my end users.
The values and access/authorizations restrictions is up to your project requirement.
Hope this would help you. -
Help required for improving performance of the Query
Hello SAP Techies,
I have MRP Query which shows Inventory projection by Calendar Year/Month wise.
There are 2 variables Plant and Material in free charateristics where it has been restricted by replacement of Query result .
Another query is Control M Query which is based on multiprovider. Multiprovider is created on 5 cubes.
The Query is taking 20 -15 Mins to get the result.
Due to replacement path by query result for the 2 variables first the control M Query is excuted. Business wanted to see all those materials in MRP query which are allocated to base plant hence they designed the query to use replacement Path by Query result. So it will get all the materials and plants from the control M query and will find the Invetory projection for the same selection in MRP query.
Is there any way I can improve the performance of the Query.
Query performance has been discussed innumerable times in the forums and there is a lot of information on the blogs and the WIKI - please search the forums before posting and if the existing posts do no answer your question satisfactorily then please raise a new post - else almost all the answers you get will be rehashed versions of previous posts ( and in most cases without attribution to the original author )
Edited by: Arun Varadarajan on Apr 19, 2011 9:23 PMHi ,
Please see if you can make these changes currently to the report . It will help in improving the performance of the query
1. Select the right read mode.
Reading data during navigation minimizes the impact on
the application server resources because only data that
the user requires will be retrieved.
2. Leverage filters as much as possible. Using filters contributes to
reducing the number of database reads and the size of the result set,
hereby significantly improving query runtimes.
Filters are especially valuable when associated with u201Cbig
dimensionsu201D where there is a large number of characteristics such as
customers and document numbers.
3. Reduce RKFs in the query to as few as possible. Also, define
calculated & RKFs on the Infoprovider level instead of locally within the query.
Regards
Garima -
Is aggregate DB index is required for query performance
Hi,
Cube mange tab when i check for the aggregate DB index it shows red, here my doubt is, is the DB index is required for query performance
is the check statics should be in green?
Please let me know
Regards,
KiranHi,
Yes it improves the reports performance..
Using the Check Indexes button, you can check whether indexes already exist and whether these existing indexes are of the correct type (bitmap indexes).
Yellow status display: There are indexes of the wrong type
Red status display: No indexes exist, or one or more indexes are faulty
You can also list missing indexes using transaction DB02, pushbutton Missing Indexes. If a lot of indexes are missing, it can be useful to run the ABAP reports SAP_UPDATE_DBDIFF and SAP_INFOCUBE_INDEXES_REPAIR.
See SAP Help
http://help.sap.com/saphelp_nw2004s/helpdata/en/80/1a6473e07211d2acb80000e829fbfe/content.htm
Thanks
Reddy
Maybe you are looking for
-
Hello, I want to create a custom color swatch panel for Illustrator. But I cant figure out a way to add swatches to the panel and drag/drop them into file. Kindly guide me to an example or the steps required to build such a panel. I'm new to flex sdk
-
How to display %complete in WBS summary bars
I need to show the percent complete in my group summary bars but it only shows when the Duration % column is shown, then it is not correct, some groups with no activies started show some percent complete
-
Hello DMS Gurus, I'm trying to figure out how to control DIR so that if the document type does not have a status network defined, the Not Released red light does not show up on the DIR. I thought maybe if I created a status for my document type but
-
MacBook Pro Software Update 1.1 Refuses to Install
Ok well I have a very annoying problem. Since the 18th, I've been getting daily notices about the MacBook Pro Software Update 1.1 thing, and daily I have been saying "OK, go ahead and interrupt what I'm doing, install it and then leave me alone." And
-
How to change program from own develop class to $tmp
hi, i m creating one program and stored under the development class ZFM. how can i change my own development class to $tmp(local object)i don;t want to use development class ZFM changed to $tmp