sql

SQL replace vs. doing an insert or update statement

Hi, I was wondering what the advantages/disadvantages or doing a MySQL replace vs. doing either an update or insert statement are. Basically, doing dao.replaceEntry(entry); instead of: if(existing){ dao.insertEntry(entry); } else { dao.updateEntry(entry); } Also, would it be misleading to call the dao.replaceEntry ...

Oracle Script problem - create trigger not terminating

I am trying to make some changes to an oracle database and have a script put together to do so. The problem is when it gets to a point in the script where I am creating a trigger it seems like the Create Trigger block does not properly terminate, when I look at the trigger afterwards it contains all of the remaining code in the script. ...

SQL Server 2005 Schema Ownership & Domain Accounts

Greetings all, In SQL Svr 2005 I created a new schema for my database called GSOC whose owner is dbo. I then created a local SQL user account with the default schema set to GSOC - my new schema name. I have one View that I want this schema to control access to, so I added the local SQL account to the View's permissions granting SELECT p...

SQL Server 2008 Update Query with Join and Where clause in joined table

Hi All, not sure why this is not working.. UPDATE ust SET ust.isUnsubscribedFromSystemEmails = 1 FROM UserSetting AS ust INNER JOIN [User] ON ust.userID = [User].userID AND [User].emailAddress IN (SELECT emailAddress FROM BadEmailAddresses) In plain English, I am trying to set the isUnsubscribed fiel...

How to check when autogrowth is done last?

In sql server 2005, the autogrowth is enabled by size. Is there any way to check when autogrowth on data and log file happened last? ...

Return only latest values from timestamped table

I have a table with the following structure: timestamp, tagid, value I want a query where I can receive only the newest timestamped values for a list of tag id's. For example: SELECT * FROM floatTable WHERE tagid IN(1,2,3,4,5,6) Will return the entire set of values. I just want the latest stored value for each one. ...

Can I bind multiple values as a single parameter using MYSQLI and PHP?

Imagine I have the following SQL query: SELECT id,name FROM user WHERE id IN ('id1','id2','id3') Now imagine I need the array of ids to be supplied by PHP. So I have something like this: $idList = array('id1','id2','id3'); $query = "SELECT id,name FROM user WHERE id IN (?)"; $stmt = $db->prepare($query); $stmt->bind_param(/*Somethin...

ORDER BY whether a GROUP_CONCAT contains a certain value?

I have properties and I need to list the ones mapped as "Founding Members" first, and then alphabetically while the rest that aren't need to come afterwards and be listed alphabetically. properties table: ------------------------ id name 1 Gaga Hotel 2 Foo Bar Resort properties_features ------------------------ feature_id pro...

Passing from Form to Query in Access/SQL/VB

Access 2007 / SQL / VB I have a query: SELECT Count(*) AS CountOfCR1 FROM PData WHERE (((PData.DestID)='CR1') And (((PData.AnswerTime)>=Starting)<Ending+1)); I am trying to pass the variables Starting and Ending to the above query from the below form: Starting = StartDate & " " & StartTime Ending = EndDate & " " & EndTime On Error G...

Fastest way to perform time average of multiple calculations in SQL?

I have a question about the fastest way to perform a SQL Server query on a table, TheTable, that has the following fields: TimeStamp, Col1, Col2, Col3, Col4 I don't maintain the database, I just can access it. I need to perform 10 calculations that are similar to: Col2*Col3 + 5 5*POWER(Col3,7) + 4*POWER(Col2,6) + 3*POWER(...

T-SQL How to get SUM() from a subquery

Hi, I need fast answer (I can't check that code right now): is that query works ? I need to get the total sum of a column values from the subquery, something like that: select sum(select time from table) as sometimes group by sometimes ...

Oracle query optimization using dynamic dates

I have a view where if I select like this: select * from view where date = '17-sep-10' it returns in seconds. If I use a dynamic date: select * from view where date = to_date((select current_business_date from v_business_day), 'mm/dd/yyyy') it returns in 20 mins. Why would har...

Python or SQL Logistic Regression

Given time-series data, I want to find the best fitting logarithmic curve. What are good libraries for doing this in either Python or SQL? Edit: Specifically, what I'm looking for is a library that can fit data resembling a sigmoid function, with upper and lower horizontal asymptotes. ...

Is it possible to have multiple composite (aka "many-to-many", ManyToMany) joins that don't make the result set huge.

Situation: Table book is associated with one or more authors via the _author_book table. It is also associated with one or more genres via the _book_genre table. When selecting all the books, and all their genres, and all their authors, the number of rows returned is (assume each book has at least one genre and author): PROBLEM: book...

copy one field from table to another field in the same table

I used this query to copy one full column from the same table: UPDATE 'content_type_chapter' SET 'field_chapternumbersort2_value' = 'field_chapternumbersort_value' But I have received this error. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use nea...

adding a column description

Does anyone know how to add a description to a SQL Server column by running a script? I know you can add a description when you create the column using SQL Server Management Studio. How can I script this so when my SQL scripts create the column, a description for the column is also added? ...

mysql performance: nested insert/duplicate key vs multiple updates

Hello. Does anyone know what would be more efficient and use less resources: Method 1-- Using a single SELECT statement to get data from one table and then iterating through it to execute multiple UPDATEs on another table. E.G. (pseudo-code, execute() runs query): Query1_resultset = execute("SELECT item_id, sum(views) as view_count F...

How to set VS2010 SQL table column to be unique?

In Microsoft SQL Server 10, how do I set constraint, that column in table with data type nchar(50) must be unique? ...

How to get MySql to use "[" as a quote character?

I am forced to use a dumb-as-nails Windows program (called IDCentre, made by Datacard, if you have the deep misfortune to use it) that says it can deal with ODBC databases. So, I hooked it up to my MySQL database. All is well so far. Then I noticed that it barfs when it attempts to do an update. The SQL that MySQL deems bad contains ...

how to write query to check status is present in list or not?

Declare Status varchar(15) set status = 'Returned','Cancelled','Rejected' I pass parameter 'processing' and 'Completed' I want to find out 'processing' and 'Completed' is presented in Status group or not. if it is presented true true else false. plz help me .... ...