sql

Importing and shredding XML into SQL Table

Hi i hope someone can help me, i am trying to import XML elements into an SQL Table, in XML format. To start with i have an XML file called Chassis.xml that looks like this. <Chassis> <Chassis Id="1" Chassis="blah blah" Suitability="1" Structured="1" /> <Chassis Id="2" Chassis="blah blah" Suitability="1" Structured="1" /> <Chassi...

Oracle function to return the size of a clob in megabytes

Hi all, I have a table, let's call it attachments. I have an attachment id and the attachment filedata. However, unfortunately, when the files are uploaded, the size of the file is never put into a filesize field.....so I have a bit of a predicament. Is there a way I could do a query to calculate the size of a. a files size in megabyt...

retrive value using OleDbDataReader

hi, Let us think my sql query is select customerDetials.custid,TestTable.col1 from CustomerDetails INNER JOIN TestTable on CustomerDetails.custid=TestTables.custid where CustomerDetails.custid>0 I wanna use OleDbDataReader to retive rows of this . I used this way while (dataReader.Read()) { string str= dataReader["custome...

implementing paging logic in DB2 SQL

Hi, Is there a way to implement paging logic in DB2 SQL, where records can be fetched page wise. The following query works only for queries with no joins. When queries with join are used the ROW_NUM is returned as 0 and paging cannot be done. SELECT * FROM (SELECT ROWNUMBER() OVER() AS ROW_NUM, Results.* FROM (S...

Calculate rolling month value in SQL Server

I have a table in SQL Server 2005 database that has following columns: Id,ProductName,Year,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec What I need to do is to calculate an average ROLLING value for a product. For instance, if product named "Car" has 2 rows in a table(Year 2009 and 2010) I want to calculate average values from Aug...

sql: select not in...

how can I rewrite the following query using JOIN SELECT * FROM table1 WHERE id NOT IN ( SELECT t1Id FROM table2 ); ...

Searching ASP.NET SQL DataSet for Postcode

Hi I am doing a project in ASP.NET that at one point searches a SQL database for a postcode using Datasets: string postcode = "%" + searchTerm.Trim().Replace(' ', '%') + "%"; SearchDataSet.SearchCustomerTableDataTable custTable = custAdapter.GetDataCustPostcode(postcode); The GetDataCustPostcode runs: SELECT * FROM CustomerTable WHE...

SQL - Move multiple rows worth of data to one row

What I am trying to do is take multiple rows of data from a column and insert it into a single cell. Here's what I have below: +++HouseNumber+++++++CustomerType+++ + 1 + Residential + + 2 + Commercial + + 2 + Residential + + 3 + Residential + +++++++++++++++++++++++++...

Indexing Null Values in PostgreSQL

I have a query of the form: select m.id from mytable m left outer join othertable o on o.m_id = m.id and o.col1 is not null and o.col2 is not null and o.col3 is not null where o.id is null The query returns a few hundred records, although the tables have millions of rows, and it takes forever to run (around an hour). When I check...

SQL Server Update with Inner Join

I have 3 tables (simplified): tblOrder(OrderId INT) tblVariety(VarietyId INT,Stock INT) tblOrderItem(OrderId,VarietyId,Quantity INT) If I place an order, I drop the stock level using this: UPDATE tblVariety SET tblVariety.Stock = tblVariety.Stock - tblOrderItem.Quantity FROM tblVariety INNER JOIN tblOrderItem ON tblVar...

Caching options in Python or speeding up urlopen

Hey all, I have a site that looks up info for the end user, is written in Python, and requires several urlopen commands. As a result it takes a bit for a page to load. I was wondering if there was a way to make it faster? Is there an easy Python way to cache or a way to make the urlopen scripts fun last? The urlopens access the Amazon ...

grouping problem in sql

Cant get my head round the sql for a leaderboard part of a facebook app I'm developing. The idea is, a list of peoples friends is passed in the WHERE clause (i.e 2,1,3,4 would be ID's of someones friends) therefore the leaderboard is a list of someones friends including themselves. I want the top score for every fb_id and want it in de...

Outer join performance

Hi! Why the outer joins are in general slower than inner joins? I mean, independently from the database vendor. I suppose it's a matter of implementation or the access plan used, but I wasn't able to convince a colleague of mine who thinks performance should be the same. Thanks in advance Lluis ...

Dynamic select list (JavaScript)

Hi, Does anyone know how I could get the select options in the following to be populated from a SQL DB?: var cell2 = row.insertCell(1); var sel = document.createElement('select'); sel.name = 'selRow' + rowCount; sel.options[0] = new Option('text zero', 'value0'); sel.options[1] = new Option('text...

How do I 'DROP' and unamed relationship/constraint in MS Access with SQL?

I have a Microsoft Access database and I have two tables. Table1 has a primary key and Table2 has a foreign key that references Table1's primary key. This relationship is set up and viewable in the Relationship viewer in MS Access, the 'Enforce Referential Integrity' check box is checked, and the Join type is an inner join. The relations...

mysql query - contains?

how can i search for a particular string in mysql? I tried using contains- gives me error: SELECT r.name , r.network , r.namestring , i.name , r.rid , i.id , d.dtime , d.ifInOctets , d.description FROM router AS r INNER JOIN interface AS i ON r.rid = i.rid INNER JOIN 1278993600_1_60 AS d ON i.id =...

MySQL INSERT - SELECT syntax problem!

INSERT IGNORE INTO table3 (id1, id2) VALUES SELECT id1, id2 FROM table1, table2; What's wrong with the above SQL query? It shows me syntax error. ...

SQL AND on column from join table

I'm having trouble getting the correct results in my query. I'm using Mysql and here is what I have so far: SELECT cpn, status, title, value_category, rating_category, parts.id FROM `vendors` INNER JOIN `vendor_parts` ON (`vendors`.`id` = `vendor_parts`.`vendor_id`) INNER JOIN `parts` ON (`parts`.`id` = `vendor_parts`.`part_id`) WHE...

Replace table with command in Crystal Reports XI

Hi, I'm trying the replace a table with a command. Replacing one table with another is usually no problem. Trying to do the same thing with a "command". It seems to work at first, an edit command window opens. I type in the command (I used "select * from myTable" as a test case), click ok and absolutely nothing happens. Background i...

MySQL's alternative to T-SQL's WITH TIES

I have a table from which I want to get the top N records. The records are ordered by values and some records have the same values. What I'd like to do here is to get a list of top N records, including the tied ones. This is what's in the table: +-------+--------+ | Name | Value | +-------+--------+ | A | 10 | | B | 30 ...