Is it possible to use ActiveRecord named_scopes to create one query with sql OR clauses?
When I use
Model.scope1.scope2
generated query is conjunction of these scopes.
Why doesnt this delete work to delete the whole record:
$query = 'DELETE FROM tblEvents WHERE index = $_GET["id"]';
$result = mysql_query($query, $db) or die(mysql_error($db));
Where index is variable of type int, auto_incremented in MySQL?
Is it possible to use the criteria api to load a set of parent objects along with a filtered, eagerly loaded set of child objects? I'm trying to query a list of categories and at the same time load the categories products that start with the letter M. The query below gives me the results I want but the Products are not eagerly loaded, that is NHibernate performs additional queries when I enumerate the Product collection:
var categoriesWithProducts = session.CreateCriteria<Category>()
.SetFetchMode("Products", FetchMode.Eager)
.CreateCriteria("Products")
.Add(Expression.Like("Name", "M%"))
.List<Category>();
What am I missing here?
Following is my SQL fiddle:
http://sqlfiddle.com/#!2/f9bae/1
In which i am trying to check if the whole name is being verified by lookup table or not and if there is any error then it should get replaced by the correct value but the problem i am facing is that if any name contains more than one wrong values then query only update one part of that name and leave the rest unchanged , kindly let me know how can i modify my query for update so it'll update the whole name as per lookup table correct values.
Thanks,
Hi everyone,
I have just made the update/add/delete part for the "Closure table" way of organizing query hierarchical data that are shown on page 70 in this slideshare: http://www.slideshare.net/billkarwin/sql-antipatterns-strike-back
However, I have a bit of an issue getting the full tree back as an multidimensional array from a single query.
Here's what I would like to get back:
array (
'topvalue' = array (
'Subvalue',
'Subvalue2',
'Subvalue3' = array ('Subvalue 1',
'Subvalue 2',
'Subvalue 3'
)
);
);
This question goes along with another one of my post that I already accepted
How do I get the "date number" in php
2010-08-24 20:00:00.000
I want to assign the current date number to a variable $current_date_num so I can use it in my query to compare what is already in the database.
$query ="SELECT * FROM Reservations WHERE [Room_ID] = '$field' AND [Meeting Start] > '$current_date_num' ORDER BY [Meeting Start] asc ";
Open up TFS Pending Changes. Can you add / remove columns to that display? I thought it was tied to the selected query, but change the columns in that query did nothing for the results displayed in Pending Changes.
This is my query
SELECT Fullname, rank, id_no, TIN, birthdate,
hair, eyes, Blood, height, weight, marks, name, address
FROM [******_DOMAIN\****_*****].*******view
Problem is, source table has too many duplicates, how do I my limit query to the latest row on the database?
I'm using SQL Server 2008.
Thanks In advance
My next problem is that the view shows me a birthdate string format of yyyymmdd, I need to change it to mm/dd/yyyy can please provide me a function? using the same string above?
Why Nibernate HQL can not handle the following query:
from Deal D where (D.ApprovalDate + INTERVAL 1 Year) < current_timestamp() < (D.RenewalDate + INTERVAL -1 Year)
knowing that INTERVAL and YEAR are keywords in MySQL, so this is kind of mixing Sql within Hql (unless Hql can handle date functions like so and I don't know) . The dialect is MySQLDialect
Its perfectly valid to execute this query
SELECT '2005-01-01' + INTERVAL 1 Year;
I am doing this in my code,
HOST = '192.168.1.3'
PORT = 50007
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
query_details = {"page" : page, "query" : query, "type" : type}
s.send(str(query_details))
#data = eval(pickle.loads(s.recv(4096)))
data = s.recv(16384)
But I am continually getting EOF at the last line. The code I am sending with,
self.request.send(pickle.dumps(results))
Hi there, im trying to do a comparison in MYSQL but wish for it to be case sensitive
ex:
$userID="test"
$q = db_query("select * from users where user_id = '" . $userID . "'");
In DB:
userid = "TEST"
Ho do i go about making sure the mysql query does not return TRUE for this query as the userid varialbe doesnt match the case of the userid in the database
thanks
Hi,
In Sql Server when you select to modify a SP or UDF it loads the objects alter query in a query window. Are these queries accessible in a system table so I can store the alter statements somewhere? It looks like syscomments has some objects but not all of them.
Thanks
i am trying to query from a temp table,and i keep getting the message
Msg 102, Level 15, State 1, Line 1 Incorrect syntax near ' '.
can somebody tell me wats the problem..is it due to convert..
plz help
The query is
select compid,2, convert(datetime, '01/01/' + CONVERT(char(4),cal_yr) ,101) ,0, Update_dt, th1, th2, th3_pc , Update_id, Update_dt,1
from #tmp_CTF
I have written a simple delete query
delete from mails
While I execute I get no problem and the query runs fine, but when I publish the website I get an error stating:
"Could not delete from specified
tables"
What might be the problem?
I am getting this error when placed in IIS but when i run it in local drive through visual studio i am not getting this error...please help
What is the best way to assemble an SQL query with join conditions dynamically? I don't want to hard code the query for each different condition on a webpage or a set of webpages. Is it even feasible?
I got as far as being able to assemble simple queries but i got stumped when i needed to insert join conditions, i.e. how to figure out dependencies for joins etc.
I'm trying to run a rather large query that is supposed to run nightly to populate a table. I'm getting an error saying Incorrect key file for table '/var/tmp/#sql_201e_0.MYI'; try to repair it but the storage engine I'm using (whatever the default is, I guess?) doesn't support repairing tables.
how do I fix this so I can run the query?
Hi all, I have this functions and need to make it one function. The only difference is type of input variable sourceColumnValue. This variable can be String or Integer but the return value of function must be always Integer.
I know I need to use Generics but can't do it.
public Integer selectReturnInt(String tableName, String sourceColumnName, String sourceColumnValue, String targetColumnName) {
Integer returned = null;
String query = "SELECT "+targetColumnName+" FROM "+tableName+" WHERE "+sourceColumnName+"='"+sourceColumnValue+"' LIMIT 1";
try {
Connection connection = ConnectionManager.getInstance().open();
java.sql.Statement statement = connection.createStatement();
statement.execute(query.toString());
ResultSet rs = statement.getResultSet();
while(rs.next()){
returned = rs.getInt(targetColumnName);
}
rs.close();
statement.close();
ConnectionManager.getInstance().close(connection);
} catch (SQLException e) {
System.out.println("???????? ?? ???? ?? ???? ?????????!");
System.out.println(e);
}
return returned;
}
// SELECT (RETURN INTEGER)
public Integer selectIntReturnInt(String tableName, String sourceColumnName, Integer sourceColumnValue, String targetColumnName) {
Integer returned = null;
String query = "SELECT "+targetColumnName+" FROM "+tableName+" WHERE "+sourceColumnName+"='"+sourceColumnValue+"' LIMIT 1";
try {
Connection connection = ConnectionManager.getInstance().open();
java.sql.Statement statement = connection.createStatement();
statement.execute(query.toString());
ResultSet rs = statement.getResultSet();
while(rs.next()){
returned = rs.getInt(targetColumnName);
}
rs.close();
statement.close();
ConnectionManager.getInstance().close(connection);
} catch (SQLException e) {
System.out.println("???????? ?? ???? ?? ???? ?????????!");
System.out.println(e);
}
return returned;
}
hi,
i have a query regarding to insert data in multiple table..
i have a two tables. one is item table and second is field table.
i want to insert data in both table with one query at a time.
any idea about it.
Is it possible to get the duplicate count when executing MySQL "INSERT IGNORE" statement via JDBC?
For example, when I execute an INSERT IGNORE statement on the mysql command line, and there are duplicates I get something like
Query OK, 0 rows affected (0.02 sec)
Records: 1 Duplicates: 1 Warnings: 0
Note where it says "Duplicates: 1", indicating that there were duplicates that were ignored.
Is it possible to get the same information when executing the query via JDBC?
Thanks.
In my web application, I have a dynamic query that returns huge data to datatable, and this query is often recalled with different parameters. So database is exhausted.
I want to get all record with no parameters to an object, and perform queries (may be with linq) on this object. So database will not be exthausted.
Which objects can be used instead of datatable?
I'm curious if there's a simpler way to remove a particular parameter from a url. What I came up with is the following. This seems a bit verbose. Libraries to use or a more pythonic version appreciated.
parsed = urlparse(url)
if parsed.query != "":
params = dict([s.split("=") for s in parsed.query.split("&")])
if params.get("page"):
del params["page"]
url = urlunparse((parsed.scheme,
None,
parsed.path,
None,
urlencode(params.items()),
parsed.fragment,))
parsed = urlparse(url)
On the Members table are columns "MemberID" and "PointsEarned".
I want to update the PointsEarned column from the result of this query:
SELECT m.MemberID, m.UserName,
( (SELECT COUNT(*) FROM EventsLog as e WHERE e.MemberID=m.MemberID AND e.EventsTypeID=2)*10 ) +
( (SELECT COUNT(*) FROM EventsLog as e WHERE e.MemberID=m.MemberID AND e.EventsTypeID=3)*3 ) +
( (SELECT COUNT(*) FROM ChatMessages as c WHERE c.MemberID=m.MemberID)*.1 )
as PointsEarned
FROM Members as m
Can anybody tell me how I should do it with a single query?
Thanks!
Hello All,
Please suggest me a query, which retrieves only those record which has the single row in table. For Example
table1.
name age
aaa 20
bbb 10
ccc 20
ddd 30
If I run "select distinct age from table1. result will be
age
20
10
30
But I need a query, which give the result like
name age
bbb 10
ddd 30
Thanks....
Is it possible to import the attributes of one table, then I put it into another table using a query in mysql?
For example I have table1 with attributes lname, fname, mname
And I want to put those attributes into table2.
Is there any query that could do that? I'm imagining that the table2 has one attribute that could later be dropped so that it will be the same as table1.