Help with mysql query plz anyone i am begging!!!
Hi everyone pls forgive me i am new to java. can someone pls tel me where i am going wrong wit this mysql query?
<sql:query var="parish" maxRows="1" dataSource="jdbc/gav">
SELECT ParishName, OwnerOccupierHousehold, OwnerOccupierPercOfOverall, OwnerOccupierCo2Emissions,
SocialRentedHousehold, SocialRentedPercOfOverall, SocialRentedCo2Emissions, PrivateRentedHousehold,
PrivateRentedPercOfOverall, PrivateRentedCo2Emission, TotalHouseholds, TotalPerc, Average,
Total2001, TotalEstimatedTotal2006, EmissionsPerPerson, EmissionPerHousehold, EmissionsPerParish,
EnergyChampionsNeeded, NumberOfPeopleAtWork, NumberOfSchoolAgeChildren
FROM base_data as b
WHERE b.id = ? <sql:param value="${param.id}"/>
<sql:param value="${param.id}"/>
</sql:query>
<c:set var="parish" scope="request" value="${parish.rows[0]}"/>
here is the error i get:
java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
please any help would be appreciated!!! Thanks in advance guys .
here is my code for the form on the index page:
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<sql:query var="parish" dataSource="jdbc/gav">
SELECT id, ParishName FROM base_data
</sql:query>
<form action="response.jsp">
Select a Parish: <select name="id">
<c:forEach var="parish" items="${parish.rows}">
<option value="${parish.id}">${parish.ParishName}</option>
</c:forEach>
</select><br><input type="submit" value="submit" name="submit" /></form>
here is the code for the response page:
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<sql:query var="parish" maxRows="1" dataSource="jdbc/gav">
SELECT b.id, b.ParishName, b.OwnerOccupierHousehold, b.OwnerOccupierPercOfOverall, b.OwnerOccupierCo2Emissions,
b.SocialRentedHousehold, b.SocialRentedPercOfOverall, b.SocialRentedCo2Emissions, b.PrivateRentedHousehold,
b.PrivateRentedPercOfOverall, b.PrivateRentedCo2Emission, b.TotalHouseholds, b.TotalPerc, b.Average,
b.Total2001, b.TotalEstimatedTotal2006, b.EmissionsPerPerson, b.EmissionPerHousehold, b.EmissionsPerParish,
b.EnergyChampionsNeeded, b.NumberOfPeopleAtWork, b.NumberOfSchoolAgeChildren
FROM base_data as b
WHERE b.id = ? <sql:param value="${param.id}"/>
</sql:query>
<c:set var="parish" scope="request" value="${parish.rows[0]}"/>
i display the results like this : ${parish.EmissionsPerParish}
the user should be able to select a parish from a form and then sql query created and then i want to show the row results on the response page.
could you tell me where so should be a simple process although not simple enough as it may seem.
thanks for the advice keith
Similar Messages
-
Need help with MySQL Query...Again
Ok so I get this error when I enter "springfield" and "MA" for the city and state.
This server program accepts either a 'zipcode' or 'city, state' depending on the choice # passed to it.
I just need to be able to perform the query.
Thanks!!
java.sql.SQLException: Unknown column 'springfield' in 'where clause'
Error4
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2975)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1695)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3020)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2949)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:959)
at ThreadConnect.run(ZipcodeServer.java:84)Here is my code:
import java.sql.*;
import java.io.*;
import java.net.*;
public class ZipcodeServer {
static void runServer() {
ServerSocket server;
Socket connection;
try {
System.out.println("Creating Server Socket " + 5000 + " . . . ");
server = new ServerSocket(5000);
System.out.println("SUCCESS!!!");
while (true) {
System.out.println("Waiting for connection.");
connection = server.accept();
System.out.println("Done");
ThreadConnect t = new ThreadConnect(connection);
t.start();
} catch (IOException e) {
System.out.println("Error5");
e.printStackTrace();
public static void main(String args[]) {
ZipcodeServer.runServer();
class ThreadConnect extends Thread {
Socket connection;
DataOutputStream output;
DataInputStream input;
ThreadConnect(Socket x) {
connection = x;
public void run() {
try {
input = new DataInputStream(connection.getInputStream());
output = new DataOutputStream(connection.getOutputStream());
try {
int choice = input.readInt();
String city, state;
int zipcode;
if (choice == 1) {
int zc = input.readInt();
DatabaseConnection.connect();
DatabaseConnection.rs = DatabaseConnection.s
.executeQuery("SELECT City,State FROM Zipcodes "
+ "WHERE ZipCode = " + zc);
while (DatabaseConnection.rs.next()) {
state = DatabaseConnection.rs.getString("State");
output.writeUTF(state);
output.flush();
city = DatabaseConnection.rs.getString("City");
output.writeUTF(city);
output.flush();
} else if (choice == 2) {
city = input.readUTF();
state = input.readUTF();
DatabaseConnection.connect();
DatabaseConnection.rs = DatabaseConnection.s
.executeQuery("SELECT ZipCode FROM Zipcodes "
+ "WHERE City = " + city + " AND State = "
+ state);
while (DatabaseConnection.rs.next()) {
zipcode = DatabaseConnection.rs.getInt("ZipCode");
output.writeInt(zipcode);
output.flush();
} catch (Exception e) {
System.out.println("Error4");
e.printStackTrace();
} finally {
DatabaseConnection.close();
} catch (IOException e) {
System.out.println("Error3");
e.printStackTrace();
class DatabaseConnection {
static Connection con;
static Statement s;
static ResultSet rs;
static String driver = "com.mysql.jdbc.Driver";
static String url = "jdbc:mysql://***.****.******/***";
static String user = "*******";
static String password = "********";
static void connect() {
try {
Class.forName(driver).newInstance();
System.out.println("Loaded Driver");
con = DriverManager.getConnection(url, user, password);
System.out.println("Connected to database\n");
con.setAutoCommit(false);
s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
} catch (Throwable e) {
System.out.println("Error2");
e.printStackTrace();
static void close() {
try {
rs.close();
s.close();
con.close();
System.out.println("\nDisconnected From Database");
} catch (Throwable e) {
System.out.println("Error1");
e.printStackTrace();
}R.Baldwin7 wrote:
I tried it. Still getting the same error.
Code no looks like:
else if (choice == 2) {
city = input.readUTF();
state = input.readUTF();
DatabaseConnection.connect();
PreparedStatement ps = DatabaseConnection.con.prepareStatement("SELECT ZipCode FROM Zipcodes "
+ "WHERE City = " + city + " AND State = "
+ state);
DatabaseConnection.rs = ps.executeQuery();
while (DatabaseConnection.rs.next()) {
zipcode = DatabaseConnection.rs.getInt("ZipCode");
output.writeInt(zipcode);
output.flush();
Read the API docs and the JDBC Tutorials for the proper way to use a PreparedStatement. It may "work" to add the quotes, but it is definately not the right way to do it. What happens if the city entered contains an apostrophe? Your statement will be broken again. Like I said, use a PreparedStatement and use it right. -
17.
hi iam preparing for certification
Consider the following query:
SELECT deptno, ename, salary salary, average,
salary-average difference
FROM emp, (SELECT deptno dno, AVG(salary) average FROM emp
GROUP BY deptno)
WHERE deptno = dno
ORDER BY 1, 2;
Which of the following statements is correct?
1. The query will fail because no alias name is provided for the subquery.
2. The query will fail because a column selected inside the subquery is referenced outside the scope of the subquery.
3. The query will work without errors.
4. GROUP BY cannot be used inside a subquery.
ans:c
when i execute the above query iam receiving an error at line 6
why?
thank u
rajivAs a sidenote, the select works on 10g1.
WITH emp AS (SELECT OBJECT_id deptno, OBJECT_name ename, OBJECT_id salary
FROM user_objects)
SELECT deptno, ename, salary salary, average, salary - average difference
FROM emp, (SELECT deptno dno, AVG (salary) average
FROM emp
GROUP BY deptno)
WHERE deptno = dno
ORDER BY 1, 2;C. -
Help with MYSQLi Query and WHILE statement
Hi,
Not sure what is wrong here but the same record is printed in the while loop 11 times (the amount of records in the table).
<?php
//Main Connection & Query
//Database Connection & Error
$con_host = 'X';
$con_username = 'X';
$con_password = 'X';
$con_database = 'X';
$con = mysqli_connect($con_host, $con_username, $con_password, $con_database);
?>
<?php
//Query
$sql = "SELECT * FROM equipment ORDER BY name ASC";
$query = mysqli_query($con, $sql);
$row = mysqli_fetch_assoc($query);
$row_count = mysqli_num_rows($query);
//Create Variables
$name = $row['name'];
$size = $row['size'];
$quantity = $row['quantity'];
$protection = $row['protection'];
$location = $row['location'];
$sublocation = $row['sublocation'];
$bc = $row['BC'];
$id = $row['id'];
?>
<!doctype html>
<html>
<link href="stylesheets/main_stylesheet.css" rel="stylesheet" type="text/css">
<link href='http://fonts.googleapis.com/css?family=Slabo+27px' rel='stylesheet' type='text/css'>
<!-- Favicon -->
<link rel="shortcut icon" type="image/png" href="images/icon.png" />
<style type="text/css">
</style>
<head>
<meta charset="utf-8">
<title>Print Equipment List</title>
<link href="stylesheets/print_stylesheet.css" rel="stylesheet" type="text/css">
<script src="sorttable.js"></script>
<!--<body onload="window.print()">-->
</head>
<body>
<div class="print_button no-print" onClick="window.print()">Print</div>
<div class="print_text no-print">Select the sorting of the list by clicking on the table categories and click the print button below</div>
<div class="print_a4page">
<div class="print_header">
<div class="print_header_logo"><img src="images/logo.png" width="306" height="43"></div>
<div class="print_header_text" id="header_text">Drama Database</div>
<div class="print_header_info">List printed: <script type="text/javascript">
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
document.write(day + "/" + month + "/" + year);</script>
<br>
Total records:
<?php echo $row_count ?></div>
</div>
<div class="print_header_divider">Equipment List</div>
<div class="print_body">
<div>
<form name="users" method="post">
<div class="table_print">
<table width="100%" border="0" cellpadding="5" class="sortable">
<tr class="table_header_print">
<th width="15%" scope="col">Name</th>
<th width="12%" scope="col">Size</th>
<th width="9%" scope="col">Quantity</th>
<th width="12%" scope="col">Protection</th>
<th width="17%" scope="col">Location</th>
<th width="12%" scope="col">Sublocation</th>
<th width="11%" scope="col">Barcode</th>
<th width="12%" scope="col">Internal ID</th>
</tr>
<?php do { ?>
<tr class="table_body">
<td><?php echo $name ?></td>
<td><?php echo $size ?></td>
<td><?php echo $quantity ?></td>
<td><?php echo $protection ?></td>
<td><?php echo $location ?></td>
<td><?php echo $sublocation ?></td>
<td><?php echo $bc ?></td>
<td><?php echo $id ?></td>
</tr>
<?php } while ($row = mysqli_fetch_assoc($query));?>
</table>
</form>
</div>
</div>
</div>
</body>
</html>Still getting the same issue.
As I see it, the way you have suggested is just rearanging things right?
here is a screenshot of the outcome:
And here is the improved code:
<?php
//Main Connection & Query
//Database Connection & Error
$con_host = 'X';
$con_username = 'X';
$con_password = 'X';
$con_database = 'X';
$con = new mysqli($con_host, $con_username, $con_password, $con_database);
?>
<?php
//Query
$sql = "SELECT * FROM equipment ORDER BY name ASC";
$result = $con->query($sql);
$row = $result->fetch_assoc();
$row_count = $result->num_rows;
//Create Variables
$name = $row['name'];
$size = $row['size'];
$quantity = $row['quantity'];
$protection = $row['protection'];
$location = $row['location'];
$sublocation = $row['sublocation'];
$bc = $row['BC'];
$id = $row['id'];
?>
<!doctype html>
<html>
<link href="stylesheets/main_stylesheet.css" rel="stylesheet" type="text/css">
<link href='http://fonts.googleapis.com/css?family=Slabo+27px' rel='stylesheet' type='text/css'>
<!-- Favicon -->
<link rel="shortcut icon" type="image/png" href="images/icon.png" />
<style type="text/css">
</style>
<head>
<meta charset="utf-8">
<title>Print Equipment List</title>
<link href="stylesheets/print_stylesheet.css" rel="stylesheet" type="text/css">
<script src="sorttable.js"></script>
<!--<body onload="window.print()">-->
</head>
<body>
<div class="print_button no-print" onClick="window.print()">Print</div>
<div class="print_text no-print">Select the sorting of the list by clicking on the table categories and click the print button below</div>
<div class="print_a4page">
<div class="print_header">
<div class="print_header_logo"><img src="images/logo.png" width="306" height="43"></div>
<div class="print_header_text" id="header_text">Drama Database</div>
<div class="print_header_info">List printed: <script type="text/javascript">
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
document.write(day + "/" + month + "/" + year);</script>
<br>
Total records:
<?php echo $row_count ?></div>
</div>
<div class="print_header_divider">Equipment List</div>
<div class="print_body">
<div>
<form name="users" method="post">
<div class="table_print">
<table width="100%" border="0" cellpadding="5" class="sortable">
<tr class="table_header_print">
<th width="15%" scope="col">Name</th>
<th width="12%" scope="col">Size</th>
<th width="9%" scope="col">Quantity</th>
<th width="12%" scope="col">Protection</th>
<th width="17%" scope="col">Location</th>
<th width="12%" scope="col">Sublocation</th>
<th width="11%" scope="col">Barcode</th>
<th width="12%" scope="col">Internal ID</th>
</tr>
<?php while ($row = $result->fetch_assoc()) { ?>
<tr class="table_body">
<td><?php echo $name ?></td>
<td><?php echo $size ?></td>
<td><?php echo $quantity ?></td>
<td><?php echo $protection ?></td>
<td><?php echo $location ?></td>
<td><?php echo $sublocation ?></td>
<td><?php echo $bc ?></td>
<td><?php echo $id ?></td>
</tr>
<?php } ?>
</table>
</form>
</div>
</div>
</div>
</body>
</html> -
I need help with SQL query (if it can be accomplished with query at all).
I'm going to create a table with structure similar to:
Article_Name varchar2(30), Author_Name varchar2(30), Position varchar2(2). Position field is basicly position of an article author in the author list, e.g. if there is one author, his/her position is 0, if 2, then 1st author is 0, second is 1, etc.
Article_Name Author_Name Position
Outer Space Smith 0
Outer Space Blake 1
How can I automate creation of Position, based on number of authors on the fly? Let's say I have original table without Position, but I want to create a new table that will have this information.
RegardsIf you have an existing table whose structure doesn't tell you what position the author is in, what's the algorithm you'd use to determine who was the first author, the second author, etc? If you issue a select query on a table without providing an "order by" clause, Oracle makes no guarantees about the order in which it retrieves rows.
As an aside, why would you store position number in a varchar2 field? If it's a number, it ought to be stored as a number.
Justin -
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. -
Need urgent help with the query - Beginer
Hello - I need help with a query to populate data in a table.Here is the scenario.
Source1
MnthID BranchCod CustID SegCode FXStatus ProfStatus Profit
200712 B1 C1 20 Y Y 100
Source2
MnthID BranchCod CustID ProdCode ProdIndex
200712 B1 C1 12 1
200712 B1 C2 12 0
Destination
MnthID BranchCod SegCode ProdCode CountSegCust CountProdCust ProfitProdCust
Condition and Calculations:
1)Source1 customer are base customers.If Source2 has customers who is not in source1 then that customer's record should not be fetched.
2)SegCode, FX Status, ProfStatus is one variable in destination table. [ SegCode = SegCode+ FXStatus (if FXStatus = Y)+ ProfStatus (if FXStatus = Y) ]
3)CountSegCust = CountCustID Groupby MnthID,BranchCod,SegCode Only.
4)CountProdCust = CountCustID Groupby MnthID,BranchCod,SegCode,ProdCode (when ProdIndex = 1)
5)ProfitProdCust = Sum of Profit of Customers Groupby MnthID,BranchCod,SegCode,ProdCode (when ProdIndex = 1)
Apologies for bad formatting.
Thanks in advance!!A total guess indeed.
It's not clear whether some aggregation can be done (summing counts of grouped data might cause some customers being counted more than once)
insert into destination
select mnthid,branchcod,segcode,prodcode,countsegcust,countprodcust,profitprodcust
from (select s1.mnthid,
s1.branchcod,
s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end segcode,
s2.prodcode,
count(s1.custid) over (partition by s1.mnthid,
s1.branchcod,
s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
order by null
) countsegcust,
count(case proindex when 1
then custid
end
) over (partition by s1.mnthid,
s1.branchcod,
s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
s2.prodcode
order by null
) countprodcust,
sum(case proindex when 1
then profit
end
) over (partition by s1.mnthid,
s1.branchcod,
s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
s2.prodcode
order by null
) profitprodcust,
row_number() over (partition by s1.mnthid,
s1.branchcod,
s1.segcode || case s1.fxstatus when 'Y' then s1.fxstatus || s1.profstatus end
s2.prodcode
order by null
) the_row
from source1 s1,source2 s2
where s1.mnthid = s2.mnthid
and s1.branchcod = s2.branchcod
and s1.custid = s2.custid
where the_row = 1Regards
Etbin -
Please, need help with a query
Hi !
Please need help with this query:
Needs to show (in cases of more than 1 loan offer) the latest create_date one time.
Meaning, In cases the USER_ID, LOAN_ID, CREATE_DATE are the same need to show only the latest, Thanks!!!
select distinct a.id,
create_date,
a.loanid,
a.rate,
a.pays,
a.gracetime,
a.emailtosend,
d.first_name,
d.last_name,
a.user_id
from CLAL_LOANCALC_DET a,
loan_Calculator b,
bv_user_profile c,
bv_mr_user_profile d
where b.loanid = a.loanid
and c.NET_USER_NO = a.resp_id
and d.user_id = c.user_id
and a.is_partner is null
and a.create_date between
TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
order by a.create_dateTake a look on the syntax :
max(...) keep (dense_rank last order by ...)
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions056.htm#i1000901
Nicolas. -
Please need help with this query
Hi !
Please need help with this query:
Needs to show (in cases of more than 1 loan offer) the latest create_date one time.
Meaning, In cases the USER_ID, LOAN_ID, CREATE_DATE are the same need to show only the latest, Thanks!!!
select distinct a.id,
create_date,
a.loanid,
a.rate,
a.pays,
a.gracetime,
a.emailtosend,
d.first_name,
d.last_name,
a.user_id
from CLAL_LOANCALC_DET a,
loan_Calculator b,
bv_user_profile c,
bv_mr_user_profile d
where b.loanid = a.loanid
and c.NET_USER_NO = a.resp_id
and d.user_id = c.user_id
and a.is_partner is null
and a.create_date between
TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
order by a.create_datePerhaps something like this...
select id, create_date, loanid, rate, pays, gracetime, emailtosend, first_name, last_name, user_id
from (
select distinct a.id,
create_date,
a.loanid,
a.rate,
a.pays,
a.gracetime,
a.emailtosend,
d.first_name,
d.last_name,
a.user_id,
max(create_date) over (partition by a.user_id, a.loadid) as max_create_date
from CLAL_LOANCALC_DET a,
loan_Calculator b,
bv_user_profile c,
bv_mr_user_profile d
where b.loanid = a.loanid
and c.NET_USER_NO = a.resp_id
and d.user_id = c.user_id
and a.is_partner is null
and a.create_date between
TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
where create_date = max_create_date
order by create_date -
I created a blogging tool for my students to use as I teach
them internet safety and cyber citizenship. I am no CF master, but
I dabble a little bit here and there. I need some help with this
query. It is running extremely slow, which means I have probably
created some horrendous loop in this query. If any one out there
has a better solution for this query, I and my middle school
students would be extremely grateful.
Here's what I would like it to do. I have two tables, one for
the blog messages and another for comments. The comments are linked
to their respective blog messages through a common database field.
When someone clicks on a link to read a student's blog, a query
runs which pulls all of the blog messages for that user, the
comments, and it also counts the number of comments entries for
each message so that I can place a total # of comments under each
blog message.Not sure why you have this like this: (Select
count(commentid) from comments where comments.blogid = blog.blogid)
or this twice: blog.blogusersid = #fname#
You need to make sure that the comments.blogid and
blog.blogid fields are indexed. Does this query work any faster?
<cfquery Name="Myblog" datasource="blog">
SELECT b.blogid, b.btitle, b.bcontent, b.bdate,
b.blogusersid, b.fname, b.lname, b.blogpict, b.pictlocation,
b.userid, c.commentid, c.blogid, b.lastupdated, COUNT(c.commentid)
AS cc
FROM blog AS b
INNER JOIN comments AS c ON c.blogid = b.blogid
WHERE b.blogusersid = #fname#
GROUP BY b.blogid, b.btitle, b.bcontent, b.bdate,
b.blogusersid, b.fname, b.lname, b.blogpict, b.pictlocation,
b.userid, c.commentid, c.blogid, b.lastupdated
ORDER BY b.bdate
</cfquery>
..... but I'm not sure that you will be getting the comment
count that you want with either query.
Phil -
Hi guys can someone help with a query regarding the 'podcast app' why do they not have all the episodes that relate to one show available why only half or a selected amount
THanks...but some days they have all the episodes right back to the very first show...ive downloaded a few but they are only available every now and then which makes no sense...why not have them available the whole time ??
-
select CASE WHEN TO_NUMBER(SUBSTR(TO_CHAR(START_TIME_TIMESTAMP,'DDMMYYYY HH24:MM:SS'),13,2))>0 AND TO_NUMBER(SUBSTR(TO_CHAR(START_TIME_TIMESTAMP,'YYYYMMDD HH24:MM:SS'),13,2)) <14
THEN TO_DATE(CONCAT(SUBSTR(TO_CHAR(START_TIME_TIMESTAMP,'YYYYMMDD HH24:MM:SS'),13,2)||'00',SUBSTR(TO_CHAR(START_TIME_TIMESTAMP,'YYYYMMDD HH24:MI:SS'),16)||'00'),'DD-MM-YYYY HH24:MI:SS') end
from table;
i have written this query.whats wrong with this query..........
the error is "literal does not match format string"
Reegards soumenWhy does your date_format loose, ununify and not fix ?
And what is your exact requirement?
>>
CASE WHEN
TO_NUMBER(SUBSTR(TO_CHAR(START_TIME_TIMESTAMP,'DDMMYYYY HH24:MM:SS'),13,2))>0
AND TO_NUMBER(SUBSTR(TO_CHAR(START_TIME_TIMESTAMP,'YYYYMMDD HH24:MM:SS'),13,2)) <14
<<
This is
CASE WHEN TO_CHAR(START_TIME_TIMESTAMP,'MM') between '01' and '13'
>>
THEN TO_DATE(CONCAT(SUBSTR(TO_CHAR(START_TIME_TIMESTAMP,'YYYYMMDD HH24:MM:SS'),13,2)
||'00',
SUBSTR(TO_CHAR(START_TIME_TIMESTAMP,'YYYYMMDD HH24:MI:SS'),16)||'00'),
'DD-MM-YYYY HH24:MI:SS')
<<
This is
TO_DATE(
TO_CHAR(START_TIME_TIMESTAMP,'MM"00"SS"00"),
'DD-MM-YYYY HH24:MI:SS')
Obviously, format is not matching !
SQL> select to_char(sysdate,'MM"00"SS"00') from dual;
TO_CHAR(
06004900
SQL> select to_date('06004900','DD-MM-YYYY HH24:MI:SS') from dual;
select to_date('06004900','DD-MM-YYYY HH24:MI:SS') from dual
ERROR at line 1:
ORA-01861: literal does not match format string -
PROCEDURE Mktg_Obj_Cmpgn(p_attr_tbl_nm IN attr.attr_tbl_nm%TYPE,p_actn_cd IN chg_log.actn_cd%TYPE) IS
v_tbl_nm varchar2(100);
v_actn_cd varchar2(4);
BEGIN
v_tbl_nm := p_attr_tbl_nm;
v_actn_cd := p_actn_cd;
--dbms_output.put_line(v_tbl_nm);
IF v_actn_cd = 'CRET' THEN
SELECT to_clob(XMLELEMENT("requestmessage",XMLATTRIBUTES(xmlforest(
seq_pblsh_rqst.nextval AS "publish_id")),
XMLAGG(XMLELEMENT("campaign",XMLATTRIBUTES(XMLFOREST(chg.actn_cd AS "ACTION",
pgm.program_idseq AS "parententityvalue",
ent_sbsrb.ENT_ID AS "entid",
pgm.campaign_idseq AS "campaignid",
bus_unt.portfolio_subtype_id AS "campaignsegment",
pgm_typ.pgm_type_nm AS "campaigntype",
LKP.lookup_key_desc AS "campaignclass",
pgm.editor_userid AS "campaignlastmodifiedby",
pgm.edited_dtm AS "campaignlastmodifieddate",
pgm.mkt_initv_proc_tx AS "campaignlink",
ofr.offer_idseq AS "offerlink")))),
XMLAGG(XMLELEMENT("PROCESSCODE", XMLATTRIBUTES(XMLFOREST(action as "link",PROGRAM.program_idseq AS "parententityvalue",
ENT_SBSRB_ATTR.ent_id AS "entid"))))))AS "v_clob" into v_clob1
FROM dual,
chg_log chg,
program pgm,
ent_sbsrb_attr ent_sbsrb,
business_unit bus_unt,
program_type pgm_typ,
offer ofr,
(SELECT lookup_keyword,lookup_key_desc,lookup_type
FROM lookup_key
WHERE lookup_type = 'PRTFL_CMPGN_ID')LKP
WHERE chg.attr_id = ent_sbsrb.attr_id
and chg.parnt_ent_val_tx = to_char(pgm.program_idseq)
and pgm.business_unit_idseq = bus_unt.business_unit_idseq
and pgm.pgm_type_cd = pgm_typ.pgm_type_cd
and ofr.program_idseq = pgm.program_idseq
and pgm.pgm_cls_cd(+) = LKP.lookup_keyword;
END IF;
end Mktg_Obj_Cmpgn;
I have this procedure within a package. v_clob1 is declared in packagebody as a CLOB variable. when i try to compile it i am getting the below given error.can anyone please help me?
(1): PL/SQL: ORA-19208: parameter 1 of function XMLELEMENT must be aliased
(2): PL/SQL: SQL Statement ignoredhi sir,
wanna ask u guyz one query
let say i have table name account(parent) and service(child)
account
id name status
1 john 0
2 ki 1
3 kdf 2
service
id trans_id name status
1 1 et 9999
1 2 eee 2222
2 3 ere 999
2 4 wew 0
i plan to use something like this
delete account from account t1,service t2 where t1id=t2.id and t1.status<>0;
but sql command not correct so plz help me
now i need a query to delete records from service table only but
account.status <> 0 and accound.id=service.id
i dunt want to delete record from account table
so can u help me with this query
thanks
Message was edited by:
mani_um -
Weird problem with mysql query and data table buttons !!!!
Hi,
I'm using jsc 2 update 1 on windows and mysql 4.1 . I have a page with a data table. One column of the data table contains "Details" buttons.
Source query for the table is :
SELECT tbl_tesserati.idtbl_tesserati idTesserato,
tbl_tesserati.num_tessera,
tbl_tesserati.nome,
tbl_societa.codice_meccanografico
FROM tbl_tesserati
INNER JOIN tbl_rel_tesserato_discipline_societa ON tbl_tesserati.idtbl_tesserati = tbl_rel_tesserato_discipline_societa.id_tesserato
INNER JOIN tbl_cariche ON tbl_rel_tesserato_discipline_societa.id_carica = tbl_cariche.idtbl_cariche
INNER JOIN tbl_qualifiche ON tbl_rel_tesserato_discipline_societa.id_qualifica = tbl_qualifiche.idtbl_qualifiche
INNER JOIN tbl_discipline ON tbl_rel_tesserato_discipline_societa.id_disciplina = tbl_discipline.idtbl_discipline
INNER JOIN tbl_societa ON tbl_rel_tesserato_discipline_societa.id_societa = tbl_societa.idtbl_societa
LEFT JOIN tbl_province ON tbl_societa.provincia_sede_sociale = tbl_province.idtbl_province
LEFT JOIN tbl_comuni ON tbl_societa.comune_sede_sociale = tbl_comuni.idtbl_comuni
LEFT JOIN tbl_rel_tesserato_discipline_praticate ON tbl_rel_tesserato_discipline_praticate.tessera_id=
tbl_rel_tesserato_discipline_societa.idtbl_rel_tesserato_discipline
LEFT JOIN tbl_discipline_praticate ON tbl_discipline_praticate.idtbl_disciplina_praticate=tbl_rel_tesserato_discipline_praticate.disciplina_praticata_id
WHERE
tbl_tesserati.cognome LIKE ?
AND tbl_tesserati.nome LIKE ?
AND tbl_rel_tesserato_discipline_societa.id_societa LIKE ?
AND tbl_tesserati.idtbl_tesserati LIKE ?
AND tbl_cariche.idtbl_cariche LIKE ?
AND tbl_qualifiche.idtbl_qualifiche LIKE ?
AND tbl_tesserati.data_nascita >= ?
AND tbl_tesserati.data_nascita<= ?
AND tbl_discipline.idtbl_discipline LIKE ?
AND codice_affiliazione LIKE ?
AND tbl_societa.denominazione LIKE ?
AND YEAR(tbl_rel_tesserato_discipline_societa.data_scadenza) LIKE ?
AND (tbl_province.nome LIKE ? OR tbl_province.nome IS NULL)
AND ( tbl_comuni.nome LIKE ? OR tbl_comuni.nome IS NULL)
The tbl_tesserati.data_nascita is a mysql date field.
The click event handler code for the "Details" Button is:
public String btnModificaTesserato_action() {
try{
TableRowDataProvider rowData= (TableRowDataProvider)getBean("currentRowTesserati");
getRequestBean1().setId_tesserato((Long)rowData.getValue("idTesserato"));
} catch(Exception ex) {
log("errore nella query",ex);
return "dettaglioTesseratoSocieta";
}When i run the project and open the page the table is correctly rendered and populated with some rows. But when i click on details button nothing happens, the page is simply reloaded.
If i set a breakpoint in the code line TableRowDataProvider rowData= (TableRowDataProvider)getBean("currentRowTesserati");the debbuger does not stop the code execution ! As if the button was never clicked!
I tried to modify the source query to :
SELECT tbl_tesserati.idtbl_tesserati idTesserato,
tbl_tesserati.num_tessera,
tbl_tesserati.nome,
tbl_societa.codice_meccanografico
FROM tbl_tesserati
INNER JOIN tbl_rel_tesserato_discipline_societa ON tbl_tesserati.idtbl_tesserati = tbl_rel_tesserato_discipline_societa.id_tesserato
INNER JOIN tbl_cariche ON tbl_rel_tesserato_discipline_societa.id_carica = tbl_cariche.idtbl_cariche
INNER JOIN tbl_qualifiche ON tbl_rel_tesserato_discipline_societa.id_qualifica = tbl_qualifiche.idtbl_qualifiche
INNER JOIN tbl_discipline ON tbl_rel_tesserato_discipline_societa.id_disciplina = tbl_discipline.idtbl_discipline
INNER JOIN tbl_societa ON tbl_rel_tesserato_discipline_societa.id_societa = tbl_societa.idtbl_societa
LEFT JOIN tbl_province ON tbl_societa.provincia_sede_sociale = tbl_province.idtbl_province
LEFT JOIN tbl_comuni ON tbl_societa.comune_sede_sociale = tbl_comuni.idtbl_comuni
LEFT JOIN tbl_rel_tesserato_discipline_praticate ON tbl_rel_tesserato_discipline_praticate.tessera_id=
tbl_rel_tesserato_discipline_societa.idtbl_rel_tesserato_discipline
LEFT JOIN tbl_discipline_praticate ON tbl_discipline_praticate.idtbl_disciplina_praticate=tbl_rel_tesserato_discipline_praticate.disciplina_praticata_id
WHERE
tbl_tesserati.cognome LIKE ?
AND tbl_tesserati.nome LIKE ?
AND tbl_rel_tesserato_discipline_societa.id_societa LIKE ?
AND tbl_tesserati.idtbl_tesserati LIKE ?
AND tbl_cariche.idtbl_cariche LIKE ?
AND tbl_qualifiche.idtbl_qualifiche LIKE ?
AND tbl_tesserati.data_nascita >= ?
OR tbl_tesserati.data_nascita<= ?
AND tbl_discipline.idtbl_discipline LIKE ?
AND codice_affiliazione LIKE ?
AND tbl_societa.denominazione LIKE ?
AND YEAR(tbl_rel_tesserato_discipline_societa.data_scadenza) LIKE ?
AND (tbl_province.nome LIKE ? OR tbl_province.nome IS NULL)
AND ( tbl_comuni.nome LIKE ? OR tbl_comuni.nome IS NULL)
Using this query everything works well !! The click handler works and the debugger too !!
I changed only the AND in OR !!!
I also tried to change mysql-x-x-connector driver but without solving my problem.
Can someone help me ?
Thanks
GiorgioYou'll find that it is more to do with the way MySql deals with dates than anything else! Depending on how your date field is setup, then try using a BETWEEN statement for those 2 lines in your first query e.g.
AND ( tbl_tesserati.data_nascita BETWEEN ? AND ?)
The date column needs to be in the ISO format to work. If you examine your second query output, you might discover that the output is only going to refer to one parameter (probably the OR one). Did you manage to view the output logs from the application server? You would have got an idea from there with a message like stating a conversion error'.
Alternatively, you could try using the to_days() function and convert it directly to a number which would be a lot easier to deal with. For example:
AND to_days(tbl_tesserati.data_nascita >= ? )
AND to_days( tbl_tesserati.data_nascita<= ? )
Or try the BETWEEN version with to_days() and see what you get.
More info about date formatting (v5) here:
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_to-days
Before I forget, sometimes you may need to treat dates as Strings rather 'Long' as you did.
As a matter of interest, did you try your query in a different piece of software?
If my queries are a little more complicated, I tend to try MySql queries out in the free MySql query browser and also double check in another to verify certain issues. I found it easier to develop SQL in a seperate program then import the final version to JSC making the required modifications for parameters.
Message was edited by:
aerostra -
I have a planning query with Material in the Rows, 0CALMONTH and Amount in the Columns.
For a query selection the user puts in only version and month Date range say 04/2009 - 03/2010. What I would like to happen is initially present the user with 3 empty rows where they input the Material and the different amounts going across for the selected 12 months. Initially there is no planning data and all my efforts fail I think because I do not have any available values for material to plan against. Is this possible?
I have another similar query, but I have fixed values on the left.
Can anyone help with this?Hi thanks for your patience.
I am trying to get a planning query with 3 empty rows to start. The User inputs the Month Range. In each row I would like and empty field for Material input and empty key figure fields for each of the months in the range. I have a similar query already, but instead of starting with no Materials I have fixed materials and it works fine. It's just a problem when I'm starting out with no materials. Any ideas? Thanks for your help.
Month 1 Month 2 Month 3,
Material, Amount, Amount, Amount, ...
Material, Amount, Amount, Amount, ...
Material, Amount, Amount, Amount, ...
Maybe you are looking for
-
my epson printer only prints the part of email that shows on my screen before scrolling down. i have checked with epson tech and it is not a printer problem. can you help?
-
Using a Statefull Session Bean with RMI on Multiple JSP pages
Heya all, i have a JBoss server running with a statefull bean on it. I want to use it on my JSP pages. But every time I start my JSP-page a NEW INSTANTION of the bean is created! For each user using my page, I want ONE bean. Is there anyway to do thi
-
Hi, I have a servlet which handles a simple process. The retrieved value is put in session and displayed in a jsp. When 2 instances of a same jsp (like in multi user access) pass on the request to this servlet, the retrieval is correct for both insta
-
Re: HELP! i cannot open my facebook application.
i also experience the same problem..my unit is BB curve 8520? im from manila philippines
-
Hi SD/XI masters, I have a problem regarding IDOC / SO generation. 2 SOs are being generated for a single PO Number. We have a mapping in XI that checks the PO number if it already exists in SAP. If it already exists, the IDOC ORDERS05.ORDCHG will be