sql

Running a SQL query in rails

Hello I have a rails application where I have to subtract 2 time stamps and display the result on the webpage I have used the following sql statement and I am getting the results. select (julianday(resolutions.created_at)-julianday(tickets.created_at))*24 from tickets,resolutions the value of tickets.created_at is 2010-04-05 18:59:...

Postgres update rule returning number of rows affected

I have a view table which is a union of two separate tables (say Table _A and Table _B). I need to be able to update a row in the view table, and it seems the way to do this was through a 'view rule'. All entries in the view table have separate id's, so an id that exists in table _A won't exist in table _B. I created the following rul...

Better way to write this SQL

I have the following table: create table ARDebitDetail(ID_ARDebitDetail int identity, ID_Hearing int, ID_AdvancedRatePlan int) I am trying to get the latest ID_AdvancedRatePlan based on a ID_Hearing. By latest I mean with the largest ID_ARDebitDetail. I have this query and it works fine. select ID_AdvancedRate...

sqlsrv_query() for a linux system?

This question is related to a previous post. Is there something comparable to sqlsrv_query() on a linux server? Or something extremely simple to parameterize queries for a LAMP(php)/SQL server? ...

How to analyse Wikipedia article's data base with R?

Hi all, This is a "big" question, that I don't know how to start, so I hope some of you can give me a direction. And if this is not a "good" question, I will close the thread with an apology. I wish to go through the database of Wikipedia (let's say the English one), and do statistics. For example, I am interested in how many active ...

Conditional SQLite check constraint?

I have a table defined by the following SQL: CREATE TABLE test ( id integer PRIMARY KEY NOT NULL UNIQUE, status text NOT NULL, enddate date, /* Checks */ CHECK (status IN ("Current", "Complete")) ); I'd like to add a constraint that requires enddate to be non-null if the status is "Complete". Is this possible? I am...

delete where id in list

if i have a list of Ids (1, 4,6,7) and a db table that i want to delete all records where id is in this list, what is the fastest way of doing this? ...

Generating the SQL query plan takes 5 minutes, the query itself runs in milliseconds. What's up?

I have a fairly complex (or ugly depending on how you look at it) stored procedure running on SQL Server 2008. It bases a lot of the logic on a view that has a pk table and a fk table. The fk table is left joined to the pk table slightly more than 30 times (the fk table has a poor design - it uses name value pairs that I need to flatte...

UTF-8 Database Problem

I've a MySQL table that has a UTF-8 charset and upon attempting to insert to it via a PHP form, the database gives the following error: PDOStatement::execute(): SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xE8' for column ... The character in question is 'è', yet I don't see why this should be a problem cons...

SQL order by oldest from Unix Timestamps

Hello. How do I use SQL to order results by oldest first? I am using unix timestamps. Thanks. ...

How to return a record from function, executed by INSERT/UPDATE rule (trigger)?

Do the following scheme for my database: create sequence data_sequence; create table data_table { id integer primary key; field varchar(100); }; create view data_view as select id, field from data_table; create function data_insert(_new data_view) returns data_view as $$declare _id integer; _result data_view%rowtype; ...

Formatting when copying SQL data and pasting in Excel

I want to copy a sql result set and paste it in Excel. But the data I paste in to the spreadsheet doesn't want to recognize Excel formatting. So if I change a column to currency, it doesn't do anything. But...if I double click on a cell, THEN it applies the currency format. But only to that cell. How can I make it automatically reco...

Splitting decimal in sql

Hi guys, I am getting result as decimal in stored procedure. If I am getting result as 123.45, I want to split it into 123 and 45. Can anybody help? ...

Problem with passing parameters to SQL procedure using VBA

Hi, I am trying to pass @intDocumentNo and @intCustomerNo to a stored procedure using VBA but only @intCustomerNo is updated in dbo.tblOrderHead. I don't think the problem is with the procedure because if I enter the values manually it runs properly. What am I doing wrong? VBA Code: Private Sub intCustomerNo_Click() Dim cmdCommand A...

Are there any modeling tools that can visually generate jpa or sql queries?

Does anyone know of a tool like PowerArchitect or SquirrelSQL or maybe eclipse plugin that lets you also generate jpa/sql queries? Imagine you choosing your database, or your entity beans, and the modeling would reverse engineer your database/entity model, so that you could visually just choose the columns you wanted to select, and it w...

How can I update many rows with SQL in a single table?

Hi folks. I have a table and one of the columns holds web addresses like: 'http://...' or 'https://...'. The problem is that there are some invalid entries, like 'shttp://...' or '#http//...' (the first character is invalid) and I want to correct all of them. I use the following SQL statement: 'SELECT [...] FROM MyTable WHERE WebAdd...

get data from to tables !

i have user list , and i have select box to filter userlist one of the select box options is show by most viewed so i have also need user information too . i want to sort my users based on most viewed profile in my user list . i have these two tables but i don't know how to right correct query to make this happen . i used grouping like t...

Type mismatch in expression in Delphi 7 on SQL append

I have a code, that checks the current date when a form is loaded, performs a simple calculation, and appends a SQL in Delphi. It works on Windows 7 with Delphi 7, and on another computer with Xp, but doesn't on 3 other computers with Xp. When the form is loaded it shows a "Type mismatch in expression", and points to the line after the a...

Question About SQL Query

I am using the below statement to generate age of a person in Oracle SQL and my question is below. SELECT TO_NUMBER(TO_CHAR(CURRENT_DATE,'YYYY'))-TO_NUMBER(TO_CHAR(BIRTH_DATE,'YYYY')) FROM NAME WHERE NAME_ID =NAME_ID This statement is only correct upto so far that I need a statement which could count months and even days in order to ...

Help with SQL query (Calculate a ratio between two entitiess)

Hi, I’m going to calculate a ratio between two entities but are having some trouble with the query. The principal is the same to, say a forum, where you say: A user gets points for every new thread. Then, calculate the ratio of points for the number of threads. Example: User A has 300 points. User A has started 6 thread. The point rat...