sql

What is the best way to build a complex NSCompoundPredicate?

I need to build an NSPredicate with many pieces of data. For example in SQL I would do something like the following: SELECT * FROM TRANSACTIONS WHERE CATEGORY IN (categoryList) AND LOCATION IN (locationList) AND TYPE IN (typeList) AND NOTE contains[cd] "some text" AND DATE >= fromDate AND DATE <+ toDate I'm st...

How should I migrate this data into these Sql Server tables?

Hi folks, I wish to migrate some data from a single table into these new THREE tables. Here's my destination schema: Notice that I need to insert into the first Location table .. grab the SCOPE_IDENTITY() .. then insert the rows into the Boundary and Country tables. The SCOPE_IDENTITY() is killing me :( meaning, I can only see a w...

ORDER BY the quantity of records with a timestamp of < 24 hours (MySQL)

I have a table full of entries with DATETIME time stamps, and an ID field. I want to make a MySQL query (in my PHP script) that selects from another table with the matching ID. I want to make some kind of join that will sort by the number of entries in the first table with a timestamp more recent than 24 hours. So basically, if there are...

column to row in sql server ?

Table: CREATE TABLE Table1 ( col1 INT, col2 nvarchar(10), col3 INT, col4 INT ); INSERT INTO Table1 (col1, col2, col3, col4) VALUES (1, 'welcome', 3, 4); My table have different data type , col2 is nvarchar h can i do this ... result: col value --------------- col1 1 col2 welcome col3 3 col4 4 ...

Using Microsoft Access SQL operators in Python ODBC

Short version: When I try to use Access's DatePart function via ODBC, it cannot be resolved. Longer version: I have a Microsoft Access query which returns rows with a timestamp and a score. I want to sort it by day and then by score - effectively a high-score table for the day. For want of a better function, I used the DatePart funct...

Replace function in a query

@"SELECT [MN].[PK_ID], [MN].[FK_NOTEADDED_BY], [MN].[ADDED_ON], REPLACE(MN.NOTE_CONTENT, '\n', '<br/>') AS [NOTE_CONTENT], ...

Is it possible to pass table-valued parameters to stored procedure using NHibernate?

If possible give short example or link to example, thanks. ...

Synchronize Data Access

Some years ago I built an Excel file for my colleagues that displays lots of data from an external ODBC data source. The data is partitioned into lots of data tables in different sheets. The file also contains a button that allows the user to update the data. Since accessing the data from the external source was very slow, I implemented...

Prepared Statement: Call to member function on non-object.

public function endGame($result) { $sql = "UPDATE games SET result = ? WHERE id = ?"; $stmt = $this->db->prepare($sql); $stmt->bind_param("si", $result, $this->currentGame);//Error here $stmt->execute(); $stmt->close(); } mysql> describe games; +-------------+-------------+------+-----+---------+----------------+ |...

Directed graph SQL

I have the following data set, which represents nodes in a directed graph. CREATE TABLE nodes (NODE_FROM VARCHAR2(10), NODE_TO VARCHAR2(10)); INSERT INTO nodes VALUES('GT','TG'); INSERT INTO nodes VALUES('GG','GC'); INSERT INTO nodes VALUES('AT','TG'); INSERT INTO nodes VALUES('TG','GC'); INSERT INTO nodes VALUES('G...

Problem select specific column name using sql statement

I found problem when trying to retrieve specific name column that using syntax/statement/command using sql. Example I have table 'dcparam' with name some column 'SELECT', 'INSERT', 'UPDATE' in database sqlserver. Then I trying to select using query: SELECT SELECT,INSERT,UPDATE FROM dcparam Well it could be solve using "*" in select, ...

Timeout a query

Hi, I wanted to know if we can timeout a sql query. In the sense, that suppose I have a sql query whose output is useful only if gives the output in 10 minutes ,after which even if it outputs the results its of no use to me. What I want to do is that if the query takes more than 10 minutes to do the processing then it should just kind...

Import unique records from datatable to sql table

Hi, I have a datatable matching the structure of a MS Sql table and I would like to import new records from the datatable into SQL. So, in the example below, I am looking to import the record for Jim. DataTable: Name DOB Country Brian 11-11-78 USA Dave 01-01-80 UK Jim 02-02-81 FR SQL: Name DOB Country...

about full text query in SQL

Hello everyone, I have a nvarchar column which contains English and Japanese text. I want to make full text search on this column. When configure full text search, we need to specify language option for word breaker (e.g. using English work breaker or using Japanese word breaker). I am wondering in this case, what language should I assi...

How do I choose parent node attribute and its child values using XML and Xquery?

I have this: <pss> <ps n="А parent node" m="654564654" t="435,8551" a="2857,2716"> <sc s="a1" a="25,4220"/> <sc s="a2" a="0"/> <sc s="a3" a="2395,9945"/> </ps> ... </pss> I need to select "А parent node m attribute and a1-a2 a values in one query. i tried this but it doesnt work: SELECT ps.value('@m', 'nvarchar(50)...

Returning the average amount of a column

I have a table which represents the scores and id's of users who have played a flash game. I want to return the amount of times the average user has tried the game- every time they complete a "try" the score and id of the user is input into the mysql table. The structure is - id int(11) score int(11) ...

SQL SUM on aggregate function

Perhaps I'm trying to be too clever for my own good, and I could possibly use a scalar variable to solve this. I'm trying to add 1 to my output from the subquery; INSERT INTO bookrevisiontbl (revisionnum, bookdate) SELECT SUM(MAX(revisionnum) + 1), GETDATE() FROM bookrevisiontbl_tbl However the following error occurs Cannot perfo...

Sorting algorithm for large datasets

Hi, I don't know whether the term sort is most appropriate but anyway I have a large datasets which consists of columns userA, userB, date, interactionDuration. In other words the dataset contains rows which describe which users were interacting, how long the interaction lasted and the date of interaction. The goal is to divide these i...

How can I include database changes (DDL patches, one-time data inserts, etc) in my build process?

I run my build script and then I have to remember which of the database SQL and PL/SQL scripts to run each time I deploy my application. How can I include these patches in my build script? Or does everybody just run them manually? Currently I number my patches so I know the order to run them, but sometimes I have to check SVN history ...

Handling error in multiple insert script (sql)

Hi all, I need to insert about 500 images to database at once. I have a script, that builds multiple query script: SELECT 'INSERT INTO [truvle].[dbo].[Ads_Images]([Img_adId],[Img_image]) SELECT CONVERT(INT, ' + CAST([Ad_id] AS VARCHAR) + ')' + ',(SELECT * FROM OPENROWSET(BULK N''' + [Ad_path] + ''', SINGLE_BLOB) as [somethin...