sql

ORA-01001: invalid cursor

I am getting an oracle error ORA-01001: invalid cursor in the production where a number of transactions are processed in bulk. However the same code works fine in development. I need to know when can one have ORA-01001: invalid cursor in an update query. I did some googling and found that there are two possibilities of getting this erro...

Select longest common timerange

Hi, I have a table where I have datetimes associated with an ID: ┌────────────────┬──────────────────────┐ │ location_id | datetime | ├────────────────┼──────────────────────┤ │ 200333 | 2008-01-01 00:00:00 | │ 200333 | 2008-01-01 01:00:00 | │ 200333 | 2008-01-01 02:00:00 | | ... | ....

Selecting max/min value from more than one fields

In the following query the start/finish columns are datetime fields. How should I modify this query to get two more columns, one with the min date and one with the max date (of all the 6 datetime fields and all the rows) repeated in each row. Alternatively how could I create a new query returning only these 2 (min/max) dates, for the...

PostgreSQL Views: Referencing one calculated field in another calculated field

I have the same question as #1895500, but with PostgreSQL not MySQL. How can I define a view that has a calculated field, for example: (mytable.col1 * 2) AS times_two ... and create another calculated field that's based on the first one: (times_two * 2) AS times_four ...? ...

how to add new column in ms access table with this criteria

i have two msaccess tables tableA textA numA bd 1 as 0 aa 2 cc 4 tableB textB ss aa bd as how to write an sql query to add one column called numB in table B so that final table B would be tableB ( basically fetching values from tableA ) textB numB ss 0 ( because ss is not there in table A ) aa 2 bd ...

Help with LINQ query

I'm trying to do this with LINQ: SQL>> SELECT p_Id from items WHERE p_Name = 'R1' LINQ>> var getpID = (from p in myDatabaseDataSet.Items where p.p_Name == ptxtBox.Text select p.p_Id).SingleOrDefault(); int p_Id = getpID; But getpID always return 0. What's wrong?. E...

Timeline from 2 related tables

Let's say I have a screenshots table and a replies table. So: every screenshot can have multiple replies (one-to-many). Now, I want to create a combined timeline of the two, but in reality, they're pretty unrelated (in structure). How can I select data from both tables, ordering by their publish time, descending; when for example, I can...

mySQL recursive Count()

I have an issue regarding an recursive count which works well in SQL server, but I can not make this work in mySQL. In SQL Server I used to use: SELECT @Param= not_unique_id, (Select Count(not unique id) FROM TABLE0 WHERE not_unique_id=@Param) FROM Table0 WHERE ..... this will give me: 1 2 1 2 2 1 3 3 3 3 3 3 this will give me...

sql order by name, numbers at the end

maybe it is a very childish question. can I order the record in that way that the values which begins with a number go to the end of the record? for example these are the values in the database: 1 Bill Andrew to turn in this with a query: Andrew Bill 1 ...

SQL Server 2008 /2000 difference using as column name a reserved keyword

I could be not more sorry guys - the question was a very wrong one. As spotted by you the error is due to the fact that a colum with that name does not exists. The error and the post is due to a misalignement between a staging server and a production server. But the error has been detected by your answers, so many, many thanks The fol...

Using Views in SQL

Hi, I have a view that is created from a base table.This view is basically the exact copy of table without any filter conditons and it has all the columns and records of the table. Is there any advantage in using view (which is a direct copy of table) instead of the table direclty in my application or stored procedures. ...

Conditional expression in SQL

Hello! I am using MYSQL and PHP. I have a table called item. Two of its attributes are price and discounted price.I have SELECT statement as below: $sql = 'SELECT C.cart_id,I.item_id,C.quantity, I.discounted_price,I.price FROM cart C, item I WHERE I.item_id = C.item_id'; I want to modify this sql statement and include a conditional ...

SQL Server Query Performance - Clustered Index Seek

Excuse the long post, but below I have included a full script to generate and populate my test harness. My test harness has the following tables |--------| |-------------| |-----| |--------------| |Column | |ColumnValue | |Row | |RowColumnValue| |--------| |-------------| |-----| |--------------| |ColumnId| |ColumnValueId|...

Fetch unique combinations of two field values

Probably it has been asked before but I cannot find an answer. Table Data has two columns: Source Dest 1 2 1 2 2 1 3 1 I trying to come up with a MS Access 2003 SQL query that will return: 1 2 3 1 But all to no avail. Please help! UPDATE: exactly, I'm trying to exclude 2,1 because 1,...

How to model Users with Roles and how to fetch them from the Database

I guess this is a common Problem: consider an application where Users have a Role You will likely have something like User username : String role : String but in your database you have CREATE TABLE IF NOT EXISTS roles ( role_id TINYINT(1) UNSIGNED AUTO_INCREMENT, role_name VARCHAR(10) NOT NULL, PRIMARY KEY...

Getting value from array in a SELECT statement

Is it possible to define an array of text fields (or any data type) and select a value from it, all within a single statement? For example: SELECT ARRAY['First', 'Second', 'Third'][mytable.state] as interpreted_state WHERE mytable.id = 1; ...

insert data into sql database..

Dear Sir, I wrote code to insert textbox data into sql database, my code working properly but when I open the table no data was added, my code given below, help me... Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click Dim connetionString As String Dim connection As SqlConnecti...

DataSet.TableAdapter-designer: Can not edit value in the SqlParameter Collection Editor-Dialog ?

Hello, I want to change the field title to integer max value 21......... not 200 chars only. When I change the value 200 of Size and confirm OK button a 2nd Dataset1.designer file is created and I get a lot of duplicate variable errors... I already changed the value in the designer and saved everything ok, but when I check again the ...

a simple way to sum a result from UNION in MySql

I have a union of three tables (t1,t2,t3). Each rerun exactly the same number of records, first column is id, second amount: 1 10 2 20 3 20 1 30 2 30 3 10 1 20 2 40 3 50 Is there a simple in sql way to sum it up to only get: 1 60 2 80 3 80 ...

MySql Searching two tables and comparing columns with like and %

I am trying to select data from two tables and insert it into another one. I want to select the data when certain things match in each table. The problem is that one of the comparisons needs to be a like and I am at a loss. The sql statement is below and I believe that it will at least show what I am trying to do. insert into hr_numb...