Can I change sql statement for some query runtime?
Hi All!
The problem that I have to implement report with query like this: select * from a where b in (?,?,?). The number of parameters depends on user choice. On the client side it will be a list of check boxes. Is there any way to implement such report? I can see just one way so far - to modify sql statement runtime.
Thanks!
hello,
create a user-parameter myListe or myWhere (wee examples below) and change your query to
select ... from ... where b in (&<myList>)
or even better
select ... from ... &<myWhere>
now you can pass in the constructed list or where clause. you can also construct the values in the afterParameterform-Trigger
regards,
philipp
Similar Messages
-
Changing sql-statement before executing query
I want to change the sql-statement of a query just before it is executed.
I have tried it with a query redirector/sessionevent listener, but I could get it to work.
Do you have any examples.
I want to change the tablename in a sql-statement like this:
before
select id from emp
after
select id from emp_v
Any examples out there to do this?... I am using SAP NetWeaver BI 7.0
Monique -
Powershell - SQL statement for WMI query
Need to input / update sql database, two main tables: server and diskDrive
The Primary key for server table is server_id which is also a foreign key in diskDrive table.
There is no primary key set in the diskDrive table.
I am able to insert all of the basic data in the server table no problem.
What I need help creating/understanding is how to account for the servers with multiple drives.
Here is my command for accounting for all drive information:
$diskDrive = gwmi -query "select * from Win32_Volume where DriveType='3' AND DriveLetter IS NOT NULL" | Select @{Name="Device";Expression={$_.DriveLetter}},`
@{Name="Capacity";Expression={[math]::round(($($_.Capacity)/1GB),2)}},`
@{Name="FreeSpace";Expression={[math]::round(($($_.FreeSpace)/1GB),2)}},`
@{Name="UsedSpace";Expression={[math]::round((($_.Capacity - $_.FreeSpace)/1GB),2)}},`
@{Name="PercentFree";Expression={[math]::round(($($_.FreeSpace)/$($_.Capacity)*100),2)}}
My thought is to create an exist statement to determine if I need to insert or update the Database:
$ServerExist = "Select server_id from server where server_name = '$ServerInfo.csname'"
if ($ServerExist) {
update statement
} else {
#Create SQL Insert Statement with your values
$insert_stmt = "INSERT INTO Server(server_name, domain_name, Manufacturer, Model, Memory)
VALUES ('$($Output.Name)','$($Output.Domain)','$($Output.Manufacturer)','$($Output.Model)','$($Output.TotalPhysicalMemory)')" -replace "\s+"," "
$cmd.CommandText = $insert_stmt
## Invoke the Insert statement
$cmd.ExecuteNonQuery()
I have tested the insert statement and that works fine. However I have not implemented the $diskDrive aspect of the insert.
Although there will be a slight difference between the insert and update statement for the diskDrive table, still need to work out the iteration aspect for sql statement.
Items that will need to be inserted/updated per drive:
Server_id
DriverLetter
Capacity
FreeSpace
UsedSpace
PercentFree
Given my $diskDrive query, I think there needs to be While($diskDrive) statement that will iterate through the drive info and then insert/update until While is finished.
However I’m not sure how that is accomplished and hoping to get some help.
Please let me know if any other information is needed.
Thanks,
Jr. AdminHello jrv,
The problem is my limited experience in powershell and how to iterate through the $diskDrive variable and pull the specific drive information including the server_id and inserting or updating the diskDrive table accordingly.
I was able to figure out how to do the insert for one specific wmi entry but in regards to the disk drive, i'm not sure how to work the scripting to run through each drive, insert/update and continue until all drives have been accounted for.
Please let me know if you need any other information. I will consider posting later on SQL forum.
Thanks,
Jr. Admin -
How can I change the state for normal. All I get is a question mark.
I can't change the normal state for my site. The button for color of text for the normal state is a question mark. Is there a way to reset this?
Thanks. I am trying to change the appearance of a hyperlink on a web page. Specifically, I want to change the default text color from blue to another color. I can change the color for the other states of the hyperlink (rollover, etc.) but the attempt to change the normal state of the hyperlink is unsuccessful because the color box for that state is a question mark. Bill
-
I can't change the volume for some of my musics
Hi it's me again :/
Everything is in the title ! I can change the volume of each podcast I download, and some of my musics. But for some other musics, I can't do anything about that, the ipod plays at one level volume only.
Do you know if it's somehow related to the basic extension (.mp3, .wav, .wmv ...) ?
I tought Itunes converts music formats if it's necessary but maybe I have to be careful with this ? I can't really pinpoint the problem because I haven't my pc with me for a while now (itunes isn't installed in the computers of university).
Thanks a lot for any helpThe earphones must be pushed very hard into the iPod. So hard, that the white part of the plug must touch the iPod in order for the external speakers to turn off. You will hear a click.
If you do a forum search, you will find this same solution. If it does not work, you will need to take your iPod to an Apple store or call the Apple iPod tech support if still under warranty or you have Apple Care. -
Why can't I change the content for some songs when I click the Get Info button?
Why can't I change the content for some songs when I click the Get Info button? The information on the song, artist, genre is grayed out and will not allow me to alter the information.
Hi htechadmin,
Revcevied your PM and noted all details, Many Thanks.
Getting this addressed by the team, either they will reply to you, here, or they shall email Or Call you.
Regards,
LP -
How Can I Retrieve SQL Statement From The User ?
Hi
I want to know, how can I make the user can enter the SQL statement from himself ?? in this code he can't enter it. Only he can display the SQL that i wrote it...
this is my Code:
import java.sql.*;
public class db_testing {
static final String DRIVER = "com.mysql.jdbc.Driver";
static final String DATABASE_URL = "jdbc:mysql://localhost/S204111933";
public static void main(String[] args) {
Connection cn=null;
Statement st= null;
ResultSet rset=null;
try{
Class.forName(DRIVER);
cn=DriverManager.getConnection(DATABASE_URL, "root", "admin");
st=cn.createStatement();
rset=st.executeQuery("select * from employee");
ResultSetMetaData metadata=rset.getMetaData();
System.out.println("The begining: ");
for(int i=1;i<=metadata.getColumnCount();i++)
System.out.print(metadata.getColumnName(i)+"\t");
System.out.println();
System.out.println();
while(rset.next()){
for(int i=1;i<=metadata.getColumnCount();i++)
System.out.print(rset.getObject(i)+"\t\t");
System.out.println();}
catch(Exception e){
e.printStackTrace();
finally{
try{
cn.close();
st.close();
rset.close();
catch(Exception e1){
e1.printStackTrace();
}The following changes in the code will make the user to give the input
import java.sql.*;
public class db_testing {
static final String DRIVER = "com.mysql.jdbc.Driver";
static final String DATABASE_URL = "jdbc:mysql://localhost/S204111933";
public static void main(String[] args) {
Connection cn=null;
Statement st= null;
ResultSet rset=null;
try{
Class.forName(DRIVER);
cn=DriverManager.getConnection(DATABASE_URL, "root", "admin");
// st=cn.createStatement();
// rset=st.executeQuery("select * from employee");
PreparedStatement pstmt=null;
pstmt=cn.prepareStatement("select * from employee where id=?");
pstmt.setInt(1,Integer.parseInt(args[0]));
rset=pstmt.executeQuery();
ResultSetMetaData metadata=rset.getMetaData();
System.out.println("The begining: ");
for(int i=1;i<=metadata.getColumnCount();i++)
System.out.print(metadata.getColumnName(i)+"\t");
System.out.println();
System.out.println();
while(rset.next()){
for(int i=1;i<=metadata.getColumnCount();i++)
System.out.print(rset.getObject(i)+"\t\t");
System.out.println();}
catch(Exception e){
e.printStackTrace();
finally{
try{
cn.close();
st.close();
rset.close();
catch(Exception e1){
e1.printStackTrace();
} -
Preparing Dynamic SQL statement for inserting in Pro*C
Hi Friends,
From quite some time i am struggling writing Dynamic SQL statement for dynamic insert and update in Pro*C.
Can somebody go through my code and suggest me the rigth way of doing.
Right now it throws an error saying " Error while updating ORA-00904: invalid column name "
Please help me.
Girish.
int main()
EXEC SQL BEGIN DECLARE SECTION;
char *uid ="scott/tiger";
static char sqlstmt[129];
struct /* DEPT record */
int dept_num;
char dept_name[15];
char location[14];
} dept_rec;
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER SQLERROR DO sql_error();
EXEC SQL CONNECT :uid;
dept_rec.dept_num = 50;
strcpy(dept_rec.dept_name,"ADMIN");
strcpy(dept_rec.location,"IN");
strcpy(sqlstmt,"UPDATE dept set DNAME = dept_rec.dept_name where DEPTNO = dept_rec.dept_num");
EXEC SQL EXECUTE IMMEDIATE:sqlstmt;
EXEC SQL COMMIT;
exit(0);
void sql_error()
printf("\nError while updating %s",sqlca.sqlerrm.sqlerrmc);
EXEC SQL ROLLBACK;
}A bit rusty here but this is how I see it.
Think of it this way ..
all Oracle is going to see is:
UPDATE dept set DNAME = dept_rec.dept_name where DEPTNO = dept_rec.dept_num
Its NOT going to know what dept_rec.dept_name is or dept_rec.dept_num is ..
it doesnt go back and fill in those values.
You need something like
strcpy(sqlstmt,"UPDATE dept set DNAME = \"");
strcat(sqlstmt,dept_rec.dept_name);
strcat(sqlstmt,"\" where DEPTNO = ");
strcat(sqlstmt,dept_rec.dept_num);
printf(sqlsmt); # Just to be sure the update statement look right during testing. -
APP-ALR-04106: Please correct the user-defined SQL statement for this alert
Hi All,
I have created an alert for engineering module in R12. It got tested and was working fine. when the user testing it, while trigger the alert getting the error, "APP-ALR-04106: Please correct the user-defined SQL statement for this alert".
when verified the alert, it got verified and ran also. It parsed the query successfully and when run it fetched few records.
Need help in resolving the issue.
Thanks in advance.
Regards,
sri
Edited by: user10939296 on Jan 18, 2010 1:16 AMHi Sri;
I have already gone through the Note: 948037.1. But this note is related to 11i. The solution provided in the Note is for 11i.
I am facing this issue in R12. Is this patch applicable to R12?I belive its not. But u can check Solution part 4 for your instance, at least it can give you idea. The other note in metalink related bug and all for R11 too.
I belive its better way to rise Sr while waiting other forum user response to that thread
Regard
Helios -
Problem with SQL Statement for Result Filtering
Dear Visual Composer Experts,
Here is another Question from me: I have a SQL Query that is working as the data service
Select AB.AgingBandID, AB.AgingBand,
Sum(Case when priority='Emergency' then '1' Else 0 End) as [Emergency],
Sum(Case when priority='Ugent' then '1' Else 0 End) as Ugent,
Sum(Case when priority='High' then '1' Else 0 End) as High,
Sum(Case when priority='Medium' then '1' Else 0 End) as Medium,
Sum(Case when priority='Low' then '1' Else 0 End) as Low
from DimAgingBand AB left outer join
(Select AgingBandID , priority , yeardesc
from vNotifications where YearDesc = (select year(getdate())-1)) as vN
on AB.AgingBandID=vN.AgingBandID
where AB.AgingBandID<>'1'
Group by AB.AgingBandID, AB.AgingBand
Order by AB.AgingBandID
That would return me a table as in the following:
Agingband E U H M L
< 1week 0 0 0 0 1
1 - 2 weeks 0 0 0 0 0
2 - 4weeks 0 0 0 0 1
> 1month 8 2 1 1 6
Now that I would like to add some parameters to filter the result, so I modify the query and put it in the SQL Statement input port of the same data service. The query is like this:
"Select AB.AgingBandID, AB.AgingBand,Sum(Case when priority='Emergency' then '1' Else 0 End) as [Emergency],Sum(Case when priority='Ugent' then '1' Else 0 End) as Ugent,Sum(Case when priority='High' then '1' Else 0 End) as High,Sum(Case when priority='Medium' then '1' Else 0 End) as Medium,Sum(Case when priority='Low' then '1' Else 0 End) as Low from DimAgingBand AB left outer join (Select AgingBandID , priority , yeardesc from vNotifications where YearDesc like '2009%' and Branch like '" & if(STORE@selectedBranch=='ALL', '%', STORE@selectedBranch) & "' and MainWorkCentre like '%') as vN on AB.AgingBandID=vN.AgingBandID where AB.AgingBandID<>'1' Group by AB.AgingBandID, AB.AgingBand Order by AB.AgingBandID"
However this input port query keeps giving me error as NullPointerException. I have actually specified a condition where the query will run if only STORE@selectedBranch != u2018u2019.
I have other filtering queries working but they are not as complicated query as this one. Could it be possible that query in the input port cannot handle left outer join?
Could it be anything else?
Help is very much appreciated.
Thanks & Regard,
SarahHi,
Thank you very much for your replys. I've tested if the dynamic value of the condition is integer, it's OK
But if the ClassID type is not integer, it's string, I write a SQL Statement like:
"Select DBADMIN.Class.ClassName from DBADMIN.Class where DBADMIN.Class.ClassID = '1' "
or with dynamic condition:
"Select DBADMIN.Class.ClassName from DBADMIN.Class where DBADMIN.Class.ClassID = '"&@ClassID&"'"
or I write the SQL Statement for insert/update/delete data,
I always have errors.
I've tested if the dynamic value of the condition is integer, it's OK
Do you know this problem ?
Thank you very much & kindly regards,
Tweety -
SQL statement for calculating performance targets
Hi
I have taken of the admin of a database which stores project goals and scores. I have to develop a way to calculate how well all projects meet these scores. The table concerned is called goal and looks like this:
goal
goal_name
project_code
current_value
good_value
bad_value
This can be for many different goals, for example if a project wants to get up a goal of having no more than 5 bugs in the project. I can also set a bad value, say 20, so if any projects have 20 or more bugs, triggers or alerts can be sent So I can enter into this table. The reason for putting 5 for good not 20 is because these scores are to be realistic.
project_code = foo
goal_name = software bugs
good_value = 5
bad_value = 20
However, some goals may have the values switched and be in a much higher range, or may even be a percentage. For example one for number of sales could be
project_code = foo
goal_name = software sales
good_value = 200
bad_value = 50
or project delay
project_code = foo
goal_name = sproject delay
good_value = 0%
bad_value = 50%
i am trying to develop a SQL statement so I can get a % score of how well a goal is performing, so I can see
What is the goal % for all foo goals
Or what is the goal % for goal 'software sales'
And also more importantly, how well are the goals doing globally.
The requirement for doing this is using a single SQL statement, well, one SQL statement for the requirements I listed above, so for example the semantics are
SELECT average(goal perforance) WHERE .... project = foo .... or goal = software sales... etc
I am having trouble doing this, I have been banging my head against mydesk all day. the biggest thing is thowing me off is that the good value can be higher or lower than the bad value, and I am having trouble visualizing how to but this conditional statement in SQL
One more thing, the percentage returned should never be more than 0% or 100%.
If anyone has any ideas or pointers, please help me out,
Thanks for your time,
Message was edited by:
user473327I am having trouble doing this, I have been banging
my head against mydesk all day. the biggest thing is
thowing me off is that the good value can be higher
or lower than the bad value, and I am having trouble
visualizing how to but this conditional statement in
SQLI haven't looked at your requirements in detail cos I don't have time for such cumbersome tasks. However, you could have two UNION'd select statements, one which caters for the good > bad and one which caters for the good < bad. Also and alternative would be the use of DECODE or CASE statements in your select which are good for switching things around based on conditions.
;) -
Nested SQL statements for complex, detailed queries.
Is it possible to write nested SQL statements for complex, detailed queries. A nested query
has a WHERE clause that includes a SELECT statement ? Is it true or false ?Hi wahid,
Here are pretty good examples:
http://www.databasejournal.com/features/mssql/article.php/3464481/Using-a-Subquery-in-a-T-SQL-Statement.htm
http://technet.microsoft.com/en-us/library/aa213252(v=sql.80).aspx
Regards Harsh -
How to find SQL Statements for BW queries ?
Experts,
Is there a way, we can see what SQL statement BW queries creates ?
please Help.Hi,
use sql trace: transaction ST05.
ask your database admin. He can control the database session.
=> for oracle: you can see the session also in the sap gui.
Sven -
Need help on SQL Statement for UDF
Hi,
as I am not so familiar with SQL statements on currently selected values, I urgently need help.
The scenario looks as follows:
I have defined two UDFs named Subgroup1 and Subgroup2 which represent the subgroups dependent on my article groups. So for example: When the user selects article group "pianos", he only sees the specific subgroups like "new pianos" and "used pianos" in field "Subgroup1". After he has selected one of these specific values, he sees only the specific sub-subgroups in field "Subgroup2", like "used grand pianos".
I have defined UDTs for both UDFs. The UDT for field "Subgroup1" has a UDF called "ArticleGroup" which represents the relation to the article group codes. The UDT for field "Subgroup2" has a UDF called "Subgroup1" which represents the relation to the subgroups one level higher.
The SQL statement for the formatted search in field "Subgroup1" looks as follows:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP1] T0 WHERE T0.[U_ArticleGroup] = (SELECT $[OITM.ItmsGrpCod])
It works fine.
However, I cannot find the right statement for the formatted search in field "Subgroup2".
Unfortunately this does NOT WORK:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2] T0 WHERE T0.[U_Subgroup1] = (SELECT $[OITM.U_Subgroup1])
I tried a lot of others that didn't work either.
Then I tried the following one:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2] T0 WHERE T0.[U_Subgroup1] = (SELECT T1.[Code] FROM [dbo].[@B_SUBGROUP1] T1 WHERE T1.[U_ArticleGroup] = (SELECT $[OITM.ItmsGrpCod]))
Unfortunately that only works as long as there is only one specific subgroup1 for the selected article group.
I would be sooooo happy if there is anyone who can tell me the correct statement for my second UDF!
Thanks so much in advance!!!!
Edited by: Corinna Hochheim on Jan 18, 2010 10:16 PM
Please ignore the "http://" in the above statements - it is certainly not part of my SQL.
Please also ignore the strikes.Hello Dear,
Use the below queries to get the values:
Item Sub Group on the basis of Item Group
SELECT T0.[Name] FROM [dbo].[@SUBGROUP] T0 WHERE T0.[U_GroupCod] =$[OITM.ItmsGrpCod]
Item Sub Group 1 on the basis of item sub group
SELECT T0.[Name] FROM [dbo].[@SUBGROUP1] T0 WHERE T0.[U_SubGrpCod]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP] T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp])
Sub group 2 on the basis of sub group 1
SELECT T0.[Name] FROM [dbo].[@SUBGROUP2] T0 WHERE T0.[U_SubGrpCod1]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP1] T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp1])
this will help you.
regards,
Neetu -
Need SQL statement for this logic....
Hi,
I want a SQL statement for updating the following changed last number .
Cuurently its:
SELECT * FROM TEST;
LAST NUMBER CHANGED LAST NUMBER
123518
12355265
123674659
9087648970
After updating with the required SQL statement table should look like
LAST NUMBER CHANGED LAST NUMBER
123518 0000123518
12355265 0012355265
123674659 0123674659
9087648970 9087648970
the last number should be appended with ZEROs and the length of changed last number should be 10 always. Hope its clear.
Appreciate your help.
Thanks in advance
Devenderselect last_number, lpad(to_char(last_number), 10 , '0') FROM test
Maybe you are looking for
-
EBS 11.5.10.2 service control script issue after cloning
Hi All, I had almost completed with the cloning of a 11.5.10.2 from one node to another node (both single nodes in Linux) while starting up the service control script I am getting the following exit status of 1in the Target Machine.. [oracle@vision V
-
System is not receiving partial quantity in MIGO.
Hi Everyone During receiving the partial quantity in MIGo,system gives me following error. Deficit of PU Ordered quantity 5 BAG : 2000380 1000 1002 GREEN TIP Can u please tell me to get rid of this error so that the system could receive the partial q
-
Java.util.Date getNewEndTime()
Jdeveloper 11.1.2.1.0 I am using the method getNewEndTime() insise this method public void onDataChange(DataChangeEvent dcv) that is called when I drag a bar in a scheduling gantt. Inside the method onDataChange(......) there is also java.util.Date g
-
ICloud Photo Library doesn't load photos on cellular
Hi, I tried searching for this issue but I didn't find anything so I'm trying to ask here. I have this problem with iCloud Photo Library on my iPhone, when I'm on cellular the pictures won't load and I only see blurry thumbnails with and exclamation
-
Joining a Windows domain failing
I am trying to set up a Windows domain on a fresh install of Leopard Server updated to 10.5.1. The domain seems to run, but when I attempt to join the domain with a client running XP Professional, authentication using an administrator account seems t