sql

how would you write this sql to delete if either of two fields are in a set of values

Background: i have 2 tables: Components: (id, name) Dependencies: (id, hasaComponentId, isaComponentId) in this case the hasaComponentId and isaComponentId are both foreign keys into the components table joined by components.id Question i have a set of Ids that the user selects. I want a sql query that will delete records from...

Exception 'System.OutOfMemoryException'

When I try to generate script to a table that contain 500000 records I'm getting an error: Exception of type 'System.OutOfMemoryException' was thrown. Can anybody suggest a solution for backup the table data to clear this error. ...

Money vs Decimal datatypes when using LINQ to SQL

There are lots of discussion about using MONEY or DECIMAL datatypes in SQL Server for holding financial data. It seems all it is about possible lost of precision when using MONEY datatype. If I understand it right, this situation may take place when we do calculation with these values in stored procedures using T-SQL. Do I assume righ...

Query Excel worksheet in MS-Access VBA (using ADODB recordset)

I'd like to query an Excel worksheet in VBA and specify conditions. The simple query "SELECT * FROM [PCR$]" works perfectly, but I don't know how to add a WHERE clause. I tried cmd2.CommandText = "SELECT * FROM [PCR$] WHERE ([B1] IS NOT NULL)" but then it complains about missing parameters. This is the complete code: Dim rs2 As New ...

why it checks just the last row of sql?

hi, I use this method in my database class which checks the password and yahooId ,if they were correct it allows the user to go to the next frame .I have added a lot of yahooId and password in my sql but this method just checks the last row and allows the last person to go to the next frame.would you please help me? thanks. public sta...

SQL: Oracle - Parameters in query

im trying to use the vs2008 query builder to create a query with a parameter. i know that in sql server it would work with: select col1,col2 from tbl where col3=@myParam how would it be typed in oracle or is it pl/sql? i get the problem in the @myParam part. ...

Want the data of Upline and Downline for particular ID

here is the table and data like: id name 1 test1 2 test2 3 test3 4 test4 5 test5 6 test6 From above data i want the data like if i pass the id as parameter and return the data from from up and gown by order Example if i pass the id as parameter = 4 then it should be return upline 2 row and downline 2 row for particular id,...

Is it an error of PostgreSQL SQL engine and how to avoid (workaround) it?

I'm parsing text documents and inserting them into PostgreSQL DB. My code is written in Java and I use JDBC for DB connectivity. I have encountered very strange error when adding data to DB - it seems that at unpredictable moment (different number of iteration of main loop) Postgres does not see rows just added to tables and fails to per...

Can SQL Profiler display return result sets alongside the query?

In SQL Profiler 2005, is it possible to capture a result set in a SQL trace, so that I could see corresponding queries with result sets? ...Or is it only a one way trace? Thanks! George ...

Optimizing multiple joins

Hi folks, I'm trying to figure out a way to speed up a particularly cumbersome query which aggregates some data by date across a couple of tables. The full (ugly) query is below along with an EXPLAIN ANALYZE to show just how horrible it is. If anyone could take a peek and see if they can spot any major issues (which is likely, I'm not ...

Automatic Insertion of Data

I have a table name Overtime Hours which have the following columns Ot_ID, Shift_Date, Employee_ID, Hours. What I need to do is insert a set of values in these tables on the 1st date of every month, automatically. for example, I need to add values('1/1/2010',12345,4.6) for january, values('2/1/2010',12345,4.6) for february and so on fo...

Products database design for product lines, categories, manufacturers, related software, product attributes, etc.

I am redeveloping the front end and database for a medium size products database so that it can support categories/subcategories, product lines, manufacturers, supported software and product attributes. Right now there is only a products table. There will be pages for products by line, by category/subcategory, by manufacturer, by suppo...

Mysql Sub Select Query Optimization

I'm running a query daily to compile stats - but it seems really inefficient. This is the Query: SELECT a.id, tstamp, label_id, (SELECT author_id FROM b WHERE b.tid = a.id ORDER BY b.tstamp DESC LIMIT 1) AS author_id FROM a, b WHERE (status = '2' OR status = '3') AND category != 6 AND a.id = b.tid AND (b.type = 'C' OR b.type = 'R') AN...

SQL Date Interval Algorithm

I am currently writing a Delphi application that runs queries over a DB2 database using ADO. One of the requirements is that the user should be able to define queries using dates, for example "show me all data from the last 60 days" or "show me all data between November 20th 2009 and January 18th 2010". This wouldn't be an issue, excep...

SQL Server 2008: Count Number of Keys In Multiple Date Ranges

SQL Server 2008 again. I have a primary key pt_id and a datetime column order_dts for each id. I want to count the number of keys in each year from 1996-2008 and return eight results - a count for each year. For a single year SELECT COUNT pm.pt_id AS '1996' FROM dm.medications pm WHERE (pm.order_dts BETWEEN '1/1/1996' and '12/31/1996') ...

selecting latest rows per disctinct foreign key value

excuse the title, i couldn't come up with something short and to the point... I've got a table 'updates' with the three columns, text, typeid, created - text is a text field, typeid is a foreign key from a 'type' table and created is a timestamp. A user is entering an update and select the 'type' it corresponds too. There's a correspon...

Using scope_identity() with ASP.NET controls

I've built a form for entering some data into a table in my database, now I want to INSERT that data, and get back the ID (which is an autonumber) of the record that has just been added. I've got the INSERT part working just fine, and I've tacked "SELECT SCOPE_IDENTITY();" onto the end of that, but now I need to retrieve the returned num...

how to allow full-text search to include lookup tables for SQL server 2008 ?

Suppose I have following two tables: Employee(Name, description, departiemtID,...) --foreign key: departmentID Department(departmentID, name, description, ...) I want to full-text search on Employee.Name, Employee.description, department.Name, department.description. What's the best solution for this case? Demo query please. ...

displaying records that could not be updated mysql

Hi, I am trying to update my results table with matching values from another table. While, updating , is there any possibility to display records that have not been updated(not matched)? BEGIN WORK UPDATE results, testcases SET results.testset = testcases.TestSet WHERE results.TestCase = testcases.TestCase ...

Which method should I go with; Indexing MySQL db with SOLR

I have a classifieds website, with approx 30 categories of classifieds. I am on the stage where I have to build MySQL tables and index them with SOLR. Each row in a table has around 15 fields... I am looking for performance! I wonder which of these two methods works best: 1- Have one MySQL table for each category, meaning 30 tables, ...