How to return a specific value in an if statement
Hi all,
Need some help regarding a report Im creating. I am a total newbie to SQL so I guess this question is really simple to all of you.
I have a column, UDF58, in a table that can have 3 different values, 10, 25 and 35.
If the value is 10 I want the formula to return 1.
If the value is 25 it should return 2 and if it is 35 the return should be 3
I tried the following:
IF :UDF58=10 THEN RETURN :UDF10='1';
I do not get any error message when compiling but it do not return any value at all....
Patrik
Do not know if you are dealing with number or varchar2 column, so here are two ways -- there are others...
SQL> create table t (udf58 number);
Table created.
SQL> insert into t values(10);
1 row created.
SQL> insert into t values (25);
1 row created.
SQL> insert into t values(35);
1 row created.
SQL> commit;
Commit complete.
SQL> select trunc(udf58/10) from t;
TRUNC(UDF58/10)
1
2
3
3 rows selected.
SQL> create table a (udf58 varchar2(10));
Table created.
SQL> insert into a select * from t;
3 rows created.
SQL> commit;
Commit complete.
SQL> select substr(udf58,1,1) from a;
SUBSTR(UDF
1
2
3
3 rows selected.
SQL>
Similar Messages
-
How to edit the records value fetched by select statement query in sqldever
How to edit the records value fetched by select statement query in sqldever 2.1.1.
EX-
SELECT * FROM emp WHERE ename like 'Jaga%'
Edited by: user9372056 on Aug 31, 2010 2:16 AMHi,
Although some forum members may be using that tool, there is still a dedicated forum for SQL Developer.
SQL Developer
Maybe your chances are better there.
Regards
Peter -
How to create a specific value in applescript
Hello guys,
My question goes as follows:
i want to create a value that is : 2001-12-01
--script on--
set days1 to 01
set months to 12
set years1 to 2001
set specialvalue to years1 & "-" & months1 & "-" & days1
--specialvalue should be 2001-12-01
--but in fact it returns a weird value in which - is still between apostrophes
--how do i get specialvalue? because it is used as a repeat function and i need them in that order
--script off--
thanks in advanceHello guys,
My question goes as follows:
i want to create a value that is : 2001-12-01
--script on--
set days1 to 01
set months to 12
set years1 to 2001
set specialvalue to years1 & "-" & months1 & "-" & days1
--specialvalue should be 2001-12-01
--but in fact it returns a weird value in which - is still between apostrophes
--how do i get specialvalue? because it is used as a repeat function and i need them in that order
--script off--
thanks in advance -
How to return a bool value from MyBrokerProcess
To make MyPlugin work in Adobe Reader X in Protected Mode On, i have created a Broker Process(MyBrokerProcess.exe)
Plugincode(C++)--->BrokerProcess(C#)---->Helper(C#)
MyPlugin has 4 button, when i click on each button a Window(System.Window.Form) will open and perform its task.
1.While i trying to close the ActivePDF document , if any of the Windows(System.Window.Form) is open i will display the message saying("Choose YES to Close this Window first Before Closing the ActiveDoc and Choose NO to continue without closing Window and ActiveDoc"). This is taken care in Helper Class(C#)
2.If the user choose "Yes", then the Helper functin will return 'true' to MyBrokerProcess.
3.Inturn MyBrokerProcess has to return this bool value to the PluginCode(C++) which is the only place to access Acrobat API function to close the ActiveDocument.
Now i am clueless as to how i have to return this bool value from MyBrokerProcess to PluginCode. Or is there any other way to accomplish the above task. Please some one help me to solve this issue.
Thanks in advance.Hi Richard,
This is what i tried to do. But i couldnot make MyPlugin work in Protected Mode On.
Plugincode(C++)<--->BrokerProcess(C#)<---->Helper(C#)
I added a simple Process between Plugin(C++)code and Helper(C#)code.
Previously it was like
Plugincode(C++) <----> Helper(C#)
Thanks and Regards,
Chetan. -
Return Into. Can I return the old value in an update statement?
Hello - I have an update statement and I need the value of a field, prior to the update. Is it possible to use the Return Into to do this? Or do I have to have a separate select statement prior to the update statement in order to store that value in a variable?
Thanks!RETURNING INTO is valid for an UPDATE, but it returns the new value, not the old value.
SCOTT @ nx102 Local> select * from a;
COL1
4
Elapsed: 00:00:00.00
SCOTT @ nx102 Local> ed
Wrote file afiedt.buf
1 declare
2 l_old_col1 number;
3 begin
4 update a
5 set col1=col1+1
6 returning col1 into l_old_col1;
7 dbms_output.put_line( l_old_col1 );
8* end;
SCOTT @ nx102 Local> /
5
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.00If you are trying to track historical changes, have you looked at Workspace Manager? That can be far easier than writing your own change tracking code...
Justin -
How to get a specific value from a mult-value returning procedure
Hi,
We're using Oracle 11.1.
I have a procedure that I'm calling in a query that looks like the following:
PROCEDURE tcmenc1_clean_codes (
p_icd_code_1_source IN VARCHAR2,
p_icd_code_2_source IN VARCHAR2,
p_icd_code_3_source IN VARCHAR2,
p_claim_code_1_src IN VARCHAR2,
p_claim_code_2_src IN VARCHAR2,
p_claim_code_3_src IN VARCHAR2,
p_revenue_code_1_src IN VARCHAR2,
p_cpt_code_1_src IN VARCHAR2,
p_icd_code_1_std OUT VARCHAR2, <------------------------Just want this one.
p_icd_code_2_std OUT VARCHAR2,
p_icd_code_3_std OUT VARCHAR2,
p_icd_code_1_std OUT VARCHAR2,
p_icd_code_2_std OUT VARCHAR2,
p_icd_code_3_std OUT VARCHAR2,
p_revenue_code_1_std OUT VARCHAR2,
p_hcpcs_code_std OUT VARCHAR2,
p_cpt_code_std OUT VARCHAR2,
p_generic_cd_std OUT VARCHAR2
)I'd like to return only the p_icd_code_1_std value. how can I do this?
Can I just use:
PROCEDURE tcmenc1_clean_codes (input1, input2, input 3,...,
p_icd_code_1_std => output1);Also If I don't have inputs for all my inputs, can I specify just the fields I want to input?I'm not sure I understand what you mean by target?
I thought about using a function to pass parameters to this procedure and then have another input parameter that would determine
which output parameter to use.
I just wanted to see if there was a cleaner way to do this. -
How to return javascript function value to jsp page
Hi i want to retrieve values from javascript function to jsp page, how can i do that ? i am trying this but its not working
<script language="javascript" type="text/javascript" src="/feedback/common/scripts/config.js"></script>
<script language="javascript" type="text/javascript" src="/feedback/common/scripts/richtext.js"></script>
<td>
<jsp:param id="description" value= "<%=request.initRTE('', '')%>"/>
</td>
here this initRTE function is used for displaying rich text editor .....i want to retrieve back the contetnt written in this editor and save it to DB.
Please help.
Edited by: xtech on Apr 4, 2008 12:00 PMsurely i will do that but my app is still not working.....
here is my code
</td>
<td align="left">
<script language="javascript" type="text/javascript" src="/feedback/common/scripts/config.js"></script>
<script language="javascript" type="text/javascript" src="/feedback/common/scripts/richtext.js"></script>
<h:inputHidden id="introtext" value= "<%=request.getParameterValues(description)%>">
<script>
initRTE('','');
</script>
</td>
in java script function i am geeting the text content
function initRTE(rtePreloadContent, rteCSS) {
rtePreloadContent=document.getElementById('surveyinfo:introtext').value;
startRTE(rtePreloadContent);
menuBuilder();
var description= document.getElementById(rteFormName).value;
return description;
basically i want to get the text written in text editor in jsp and want to send it to DB.(Here initRTE() function is calling rich text editor)
i have downloaded this editor from this url
http://freerichtexteditor.com/page/4.htm
and trying to embed it in my app. -
How to limit a specific value for an attribute in OIM during AD recon.
Hello,
User with same attribute have diffrent values in target system. When trying to reconcile the user i wouod like to rconcile only one value but not all of them. Even though we reconcile all the values for that atribute, we do not want to display them in child form.
Ex: There is an attrubute in Active directory called "idLevel" having diffrent values like 2, 3, 4, 40 .
This is multilevel attribute in OIM which displayed in Child form.
I want to disaplay ONLY idLevel values 40 in OIM child form. Right now when I reconcile this attribute for the user all the values are getting populated.
PLease let me know if we can achieve this.
ThanksHate to say it, but I don't think you can without writing your own recon code.
-Kevin -
I am new to scripting (literally started reading/learning scripting a few hours ago), and I am stuck in trying to get my current script/command to filter a specific date range.
* Note: I am working with Server 2003 and 2008; because of the environment I am in, a lot of scripts (such as Powershell and VBScript) don't work; trying to stick with command line, as it appears to be the only thing that functions correctly in my environment
I am trying to search the System log in event viewer, for the most recent server reboot. Here is the command that I am currently running:
===========================================================
C:\Windows\System32\cscript C:\Windows\System32\eventquery.vbs /L System /FI "id eq 1074"
===========================================================
When run, the output looks like this:
===========================================================
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved
Listing the events in 'system' log of host 'xxxxxxxxxxxxxxx'
Type Event
Date Time Source
Information 1074
12/18/2013 2:48:06 AM USER32
Information 1074
11/20/2013 3:25:04 AM USER32
Information 1074
10/23/2013 2:06:09 AM USER32
===========================================================
What I would like it to do is only show events that have happened in the last seven days, as well as show the event details if it does find an event that matches the criteria.
Any help would be greatly appreciated. Thanks!
NickI would prefer using Powershell , you can use below code
function Get-EventViewer
param(
[string[]]$ComputerName = $ENV:COMPUTERNAME,[string]$LogName,[int]$eventid
$Object =@()
foreach ($Computer in $ComputerName)
$ApplicationEvents = get-eventlog -logname $LogName -cn $computer -after (Get-Date).AddDays(-7) | ?{$_.eventid -eq "$eventid" }
foreach ($event in $ApplicationEvents) {
$Object += New-Object -Type PSObject -Property @{
ComputerName = $Computer.ToUpper();
TimeGenerated = $event.TimeGenerated;
EntryType = $event.EntryType;
Source = $event.Source;
Message = $event.Message;
$column1 = @{expression="ComputerName"; width=12; label="ComputerName"; alignment="left"}
$column2 = @{expression="TimeGenerated"; width=22; label="TimeGenerated"; alignment="left"}
$column3 = @{expression="EntryType"; width=10; label="EntryType"; alignment="left"}
$column4 = @{expression="Source"; width=15; label="Source"; alignment="left"}
$column5 = @{expression="Message"; width=100; label="Message"; alignment="left"}
$Object|format-table $column1, $column2, $column3 ,$column4 ,$column5
$Object.GetEnumerator() | Out-GridView -Title "Event Viewer"
You can do a function call like
Get-EventViewer -LogName system -ComputerName "computername" -eventid "2017" -
How to read a specific value or a portion of text using utl_file.
hi,
I have a small requirement which goes as follows. I have a text file which is a resultof the sql query and it contains 16 columns as PIPE delimited text . I am using the UTL_FILE package concept to read the data. In general when we use the UTL_FILE.GET_LINE we read the entire line of text. But i need to read the 10th column of the query or the PIPE delimited text .
Please advice.
My query goes something like this:
declare
f utl_file.file_type;
s long;
c number := 0;
begin
f := utl_file.fopen('ABC_EXTRACTS','sample1.txt','R');
loop
utl_file.get_line(f,s);
insert into s values (s);
c := c + 1;
end loop;
exception
when NO_DATA_FOUND then
utl_file.fclose(f);
dbms_output.put_line('No. of rows inserted : ' || c);
end;Why don't you use varchar2 instead of long data type. I doubt you can read a portion from a file using utl_file but after doing the fetch you can do substring over the varchar2 variable and retrieve just the 10th column.
sample sql:
If your DB is 10g or higher, you can use the below regular expression to retrieve value based on your need.
PRAZY@11gR1> select regexp_substr('111|222|333|444|555|666|777|888|999|000|aaa|bbb|','[^|]+',1,10) from dual;
REG
000
Elapsed: 00:00:00.00Btwn, if the text file has fixed number of columns at all time, why don't you use a external table instead?
Regards,
Prazy
Edited by: Prazy on Mar 22, 2010 4:11 PM -
How to return highest/lowest value in a group of accounts?
Hi gurus,
I'm facing a requirement where in HFM, I need to set the value of an account to be the same as the highest value of a group of other accounts (POV is the same, all accounts are lowest level in hierarchy).
So basically, I need a rule/script/function that enables me to say: "look up the values of account 1, account 2 and account 3 for this point of view, and set the value of account 4 to be whatever is the highest of the values of accounts 1, 2 and 3".
I would be extremely grateful for any insights and assistance. I'm sure this is possible in VBScript....
br
SamuliIndeed this is possible in VBScript.
You don't have handy Max/Min functions in VBscript but given that you've only got three inputs, you can easily compare one number against the other two and deduce the maximum from there.
First of all, get the data from the 3 intersections you want using GetCell
Var1 = HS.GetCell("POVExpression")
Var2 = HS.GetCell("POVExpression")
Var3 = HS.GetCell("POVExpression")
Then do a simple comparison of the three values using something like below
If Var1 >= Var2 And Var1 >= Var3 Then
VarMax = Var1
ElseIf Var2 >= Var1 And Var2 >= Var3 Then
VarMax = Var2
Else
VarMax = Var3
End If
The maximum value will be in the variable VarMax. You can now use HS.Exp to to assign that variable to the desired account -
How to return a Vector value??
Hi
This is the code of the function:
public void extractLinks(Vector tmp) throws ParserException {
Node node;
LinkTag linkTag;
for (NodeIterator e = parser.elements();e.hasMoreNodes();) {
node = e.nextNode();
if (node instanceof LinkTag) {
linkTag = (LinkTag)node;
tmp.add(linkTag.toString());
}And this is the call in JSP file:
MyLinkExtractor linkExtractor = new MyLinkExtractor(request.getParameter("urlfield"));
linkExtractor.extractLinks(links);
for (int i = 0; i<links.size(); i++)
out.println(links.get(i));
}The problem apears in the line where I call function extractLinks with parameter links
I don't know what is the real problem, because I just get a list of exceptions in browser, when I run the aplication.
I think that the problem is in the transfer of values of the parameter.
I'm beginner, so pleas help me.
Thank you!!Hi,
I did this and the error report is still the same.
javax.servlet.ServletException: myapp.MyLinkExtractor.extractLinks(Ljava/util/ArrayList;)Ljava/util/ArrayList;
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:457)
at org.apache.jsp.treeview$jsp._jspService(treeview$jsp.java:96)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1011)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106)
at java.lang.Thread.run(Thread.java:536)
This is the complete error message, which I get from the Tomcat into my browser.
Thank you for helping.
Bozidar -
How to return the result set of multiple select statements as one result set?
Hi All,
I have multiple select statements in my stored procedure that I want to return as one result set
for instance
select id from tableA
union
select name from table b
but union will not work because the result sets datatypes are not identical so how to go about this ?
ThanksYou have to CAST or CONVERT (or implicitly convert) the columns to the same datatype. You must find a datatype that both columns can be converted to without error. In your example I'm guessing id is an int and name is a varchar or nvarchar.
Since you didn't convert the datatypes, SQL will use its data precedence rules and attempt to convert name to an int. If any row contains a row that has a value in name that cannot be converted to an int, you will get an error. The solution is
to force SQL to convert the int to varchar. So you want something like
select cast(id as varchar(12)) from tableA
union
select name from tableb
If the datatypes are something other that int or varchar, you must find a compatable datatype and then convert one (or both) of the columns to that datatype.
Tom -
When I run the following code
set nocount on
declare @i table(id int identity(1,1) primary key, sDate datetime)
while((select count(*) from @i)<10000)
begin
insert into @i(sDate) select getdate()
end
select top 5 sDate, count(id) selectCalls
from @i
group by sDate
order by count(id) desc
I get the following results.
sDate selectCalls
2014-07-30 14:50:27.510 406
2014-07-30 14:50:27.527 274
2014-07-30 14:50:27.540 219
2014-07-30 14:50:27.557 195
2014-07-30 14:50:27.573 170
As you can see the select getdate() function returned same time up to the milisecon 406 time for the first date value. This started happening when we moved our applications to a faster server with four processors. Is this correct or am I
going crazy?
Please let me know
BilalObserve that adding 2 ms is accurate only with datetime2. As noted above, datetime does not have ms resolution:
set nocount on
declare @d datetime, @i int, @d2 datetime2
select @d = getdate(), @i = 0, @d2 = sysdatetime()
while(@i<10)
begin
select @d2, @d, current_timestamp, getdate(), sysdatetime()
select @d = dateadd(ms,2,@d), @i = @i+1, @d2=dateadd(ms,2,@d2)
end
2014-08-09 08:36:11.1700395 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
2014-08-09 08:36:11.1720395 2014-08-09 08:36:11.173 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
2014-08-09 08:36:11.1740395 2014-08-09 08:36:11.177 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
2014-08-09 08:36:11.1760395 2014-08-09 08:36:11.180 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
2014-08-09 08:36:11.1780395 2014-08-09 08:36:11.183 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
2014-08-09 08:36:11.1800395 2014-08-09 08:36:11.187 2014-08-09 08:36:11.170 2014-08-09 08:36:11.170 2014-08-09 08:36:11.1700395
DATE/TIME functions:
http://www.sqlusa.com/bestpractices/datetimeconversion/
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
Select only one specific value from two values contained in an item in form
hi ,
i am newly creating a form.
in the all item i an displaying on control block,
in one item "dummy.formule" i am taking the value as '1-xyz' where 1 is nummer and xyz is naam
or '99-fgj'.
but for the next block i want to write a query in which in the where condition i need to use the nummer from dummy.formule.this query is dymannically created at run time.
i am wrting this query in the when validate of the "dummy.formule" .
how i get the specific value that i required?923315 wrote:
hi ,
i am newly creating a form.
in the all item i an displaying on control block,
in one item "dummy.formule" i am taking the value as '1-xyz' where 1 is nummer and xyz is naam
or '99-fgj'.
but for the next block i want to write a query in which in the where condition i need to use the nummer from dummy.formule.this query is dymannically created at run time.
i am wrting this query in the when validate of the "dummy.formule" .
how i get the specific value that i required?First look at it. dynamically create pop list at run time. close it.
what you mean by "naam" ?
If the value has a specific format like as you write "1-xyz,99-fgj". you can use instr function and substr function to cut it out..
Hope this helps.
Maybe you are looking for
-
Os X crashes when uploading images - parental controls?
hey world we've had this issue for a while now where our imac crashes when my daughter attempts to upload an image to her tumblr page. this isn't just a browser crash - its one of those doozys where the whole screen goes grey and we get the message a
-
Mini Running Increasingly Slow
Hi, I have had a look on the forums but am unable to find a definitive answer. My Mac Mini is running more and more slowly. It is taking an age to open any apps and even web pages. I have more than 10% free on the internal HDD and use an external HDD
-
Can't Update Information for ONE album?
I'm having a problem with iTunes. I can't update the information (album art, album name, album artist, etc.) for the album. Well, when I click "Get Info" for the album I can edit the information, but nothing changes. Further, I can't change the infor
-
Hello all: Last night something very strange happened to our television. I was watching a show, and then I left the room for a moment-- when I came back, the picture was severely distorted. The audio is still crystal clear, but the screen looks lik
-
I have a date range that must be populated (From before To Date). I would like to highlight both date fields when reporting the message. HOw do I do this? Right now my code is.... if (compareResult > 0) // From Date is After To Date - INVALID