sql

Paging with Oracle

I am not as familiar with Oracle as I would like to be. I have some 250k records, and I want to display them 100 per page. Currently I have one stored procedure which retrieves all quarter of a million records to a dataset using a data adapter, and dataset, and the dataadapter.Fill(dataset) method on the results from the stored proc. ...

Is it possible to execute a text file from SQL query?

I have a number of generated .sql files that I want to run in succession. I'd like to run them from a SQL statement in a query (i.e. Query Analyzer/Server Management Studio). Is it possible to do something like this and if so what is the syntax for doing this? I'm hoping for something like: exec 'c:\temp\file01.sql' exec 'c:\temp\fil...

MySQL -- mark all but 1 matching row

This is similar to this question, but it seems like some of the answers there aren't quite compatible with MySQL (or I'm not doing it right), and I'm having a heck of a time figuring out the changes I need. Apparently my SQL is rustier than I thought it was. I'm also looking to change a column value rather than delete, but I think at lea...

Inserting checkbox values into database

Hi to all I need help for this problem that i'm trying to solve for a while (i'm new in PHP). I have a form with several checkboxes which values are pulled from a database. I managed to display them in the form, assign an appropriate value to each, but cannot insert their values into other database. Here's the code: <form id="form1" n...

What is the use of Cursor Auto Fetch in SQL Server?

What is the use of Cursor Auto Fetch in SQL Server? thanks ...

Which SQL statement is faster?

Which SQL statement is faster? SELECT TOP 2 c1.Price, c2.Price, ..... c49.Price, c50.Price FROM Table1 AS c1, Table2 AS c2, ..... Table49 AS c49, Table50 AS c50 WHERE c1.Date = c2.Date AND c2.Date = c3.Date ..... c49.Date = c50.Date ORDER BY c1.ID DESC OR SELECT TOP 2 c1.Price, c2.Price, ..... c49.Price, c50.Price FROM (Table1 AS c1...

Why would someone use WHERE 1=1 AND <conditions> in a SQL clause?

Why would someone use WHERE 1=1 AND <conditions> in a SQL clause (Either SQL obtained through concatenated strings, either view definition) I've seen somewhere that this would be used to protect against SQL Injection, but it seems very weird. If there is injection WHERE 1 = 1 AND injected OR 1=1 would have the same result as injected O...

Finding difference in row count of two tables in MySQL

I have two tables, one stores the products and quantity we have bought, the other stores the sells. The current stock is therefore the sum of all the quantity columns in the bought table minus the number of rows in the sells table. How can this be expressed in MySQL. Remember that there are many different products. EDIT: To make it hard...

Mirroring Table Modifications

I have a set of tables that are used to track bills. These tables are loaded from an SSIS process that runs weekly. I am in the process of creating a second set of tables to track adjustments to the bills that are made via the web. Some of our clients hand key their bills and all of those entries need to be backed up on a more regular s...

How much more inefficient are text (blobs) than varchar/nvarchar's?

We're doing a lot of large, but straightforward forms for a fairly big project (about 600 users using it throughout the day - that's big for me at least ;-) ). The forms have a lot of question/answer type sections, so it's natural for some people to type a sentence, while others type a novel. How beneficial would it be to put a charact...

compare data in a vb.net dataset with values in an array list

I'm looking for an efficient way of searching through a dataset to see if an item exists. I have an arraylist of ~6000 items and I need to determine which of those doesn't exist in the dataset by comparing each item within the arraylist with data in a particular column of the dataset. I attempted to loop through each item in the datase...

Oracle PL/SQL Query Order By issue with Distinct

Does anyone know what is wrong with this query? SELECT DISTINCT c.CN as ClaimNumber, a.ItemDate as BillReceivedDate, c.DTN as DocTrackNumber FROM ItemData a, ItemDataPage b, KeyGroupData c WHERE a.ItemTypeNum in (112, 113, 116, 172, 189) AND a.ItemNum = b.ItemNum AND b.It...

Remove duplicate from a table

The database type is PostGres 8.3. If I wrote: SELECT field1, field2, field3, count(*) FROM table1 GROUP BY field1, field2, field3 having count(*) > 1; I have some rows that have a count over 1. How can I take out the duplicate (I do still want 1 row for each of them instead of +1 row... I do not want to delete them all.) Example:...

How can I see the SQL ActiveRecord generates?

I'd like to check a few queries generated by ActiveRecord, but I don't need to actually run them. Is there a way to get at the query before it returns its result? ...

Need a row count after SELECT statement: what's the optimal SQL approach?

I'm trying to select a column from a single table (no joins) and I need the count of the number of rows, ideally before I begin retrieving the rows. I have come to two approaches that provide the information I need. Approach 1: SELECT COUNT( my_table.my_col ) AS row_count FROM my_table WHERE my_table.foo = 'bar' Then SELECT my_t...

Building a temp table /map

I'm working on a stored procedure in SQL Server 2000 with a temp table defined like this: CREATE TABLE #MapTable (Category varchar(40), Code char(5)) After creating the table I want to insert some standard records (which will then be supplemented dynamically in the procedure). Each category (about 10) will have several codes (typicall...

MySQL COUNT(DISTINCT()) unexpected results

I'm using MySQL 5.0.45 on CentOS 5.1. SELECT DISTINCT(email) FROM newsletter Returns 217259 rows SELECT COUNT(DISTINCT(email)) FROM newsletter Returns 180698 for the count. SELECT COUNT(*) FROM (SELECT DISTINCT(email) FROM newsletter) AS foo Returns 180698 for the count. Shouldn't all 3 queries return the same value? Here is the ...

Is it possible to have an indexed view in MySQL?

I found a posting on the MySQL forums from 2005, but nothing more recent than that. Based on that, it's not possible. But a lot can change in 3-4 years. What I'm looking for is a way to have an index over a view but have the table that is viewed remain unindexed. Indexing hurts the writing process and this table is written to quite freq...

using C# regex. question is how to use "="

I`m parsing SQL query with C# Regex. I need also to make my pattern to understand "=", for example: string pattern = @"...something...(where)\s\w*\s*(order by)*...something else..."; the following query should match my pattern: select fieldslist from mytable where fieldvalue=someint order by specialfield how can I change the interva...

What is the proper syntax for a cross-table SQL query?

Right now, I have SELECT gp_id FROM gp.keywords WHERE keyword_id = 15 AND (SELECT practice_link FROM gp.practices WHERE practice_link IS NOT NULL AND id = gp_id) This does not provide a syntax error, however for values where it should return row(s), it just returns 0 rows. What I'm trying to do is get the gp_id from gp...