sql

Update a count (field) safely in SQL

I want to implement SO like tags on userpost. I have a table called tag_data with columns tagId, title, count. I have a separate table that links the relationship between a post and the many tags it may use. Heres the problem, how do i get the current count, increase or decrease it by one and store it SAFELY. So no other connection/thre...

How do I automatically reset a sequence's value to 0 every year in Oracle 10g?

As in the question, how do I automatically reset an Oracle sequence's value back to 0 every year in Oracle 10g? I'm using the sequence to generate an identifier in the format YYYY<sequence value> and the sequence value has to be reset to 0 every year. YYYY is obtained from java and concatenated with the sequence value from Oracle. Th...

MySQL: "The SELECT would examine more than MAX_JOIN_SIZE rows"

I am using PHP and MySQL. In my program there is a select query involving joins. When I run it on localhost it's working fine but when I upload it on my server and try to execute it then it generates the following error: The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_...

Exporting data from spreadsheet to Pgsql database

Hi! I have one huge spreadsheet file (1000+ lines) and one postgreSQL table. I need to compare spreadsheet data with postgresql table data and add fill the blank fields in table with data from spreadsheet and add entries not present in db table. Yes, I can convert (via csv) whole spreadsheet into database table. But, there are unique v...

Exception handling around the rollback of a SqlTransaction

I have two stored procedures that I want execute wrapped in a transaction. For various reasons, I need to handle the transaction in my application code instead of within the database. At the moment, my code looks like this: try { using (SqlConnection conn = Connection()) { conn.Open(); using (SqlTransaction sq...

Help with Multiple group by SQL Server Query

I'm having some troubles to retrieve data from 2 tables with using multi "group by". Below is 2 tables for example and the result I would like to have from my query. PrdID Name KG ------------------ 1 Hals 10 2 Hals 3 3 Kugel 4 4 Kugel 10 5 Hals 12 6 Kugel 11 7 Hals 12 8 ...

Mysql COUNT(*) on multiple tables

What's wrong with this query: SELECT co.*, mod.COUNT(*) as moduleCount, vid.COUNT(*) as vidCount FROM courses as co, modules as mod, videos as vid WHERE mod.course_id=co.id AND vid.course_id=co.id ORDER BY co.id DESC In other words, how can I do it so with every record returned from 'courses', there's an additional column called ...

TSQL query to concatenate and remove common prefix

I have some data id ref == ========== 1 3536757616 1 3536757617 1 3536757618 and want to get the result 1 3536757616/7/8 so essentially the data is aggregated on id, with the refs concatenated together, separated by a slash '/', but with any common prefix removed so if the data was like id ref == ========== 2...

condensing query using SQL

I have a table with 4 things I want... the Name, Price, QTY, and a specific Date There are lots of Entries per date: Name Price Date Twin Private $25 06/02/09 Double $35 06/02/09 Single $20 06/02/09 Twin Private $25 06/03/09 Double $35 06/03/09 Single $20 06/03/09 Twin Private ...

Guaranteed cache hits when retrieving data

Problem setting Entities arrive for processing and are taken through a series of steps which operate on those entities and possibly on other, related, entities and generate some results; Some of the entities are required to be processed in real-time, without any database access; Currently the implementation simply looks up entities in ...

Is any body using sql service broker to update winforms(WPF) GUI?

Hi All, I have a scenario to update Winforms application GUI when ever there is a data change in database table.Is any body using SQL Service broker to do same? For example: I have a customer and order tables in SQl Server 2005 database and I have winform(WPF) application which resides on Call Center executives(say CCE-A,CCE-B,CCE-C,...

How to populate combo box with values in MS Access 2007

I have a database with 3 tables. Manufact: ID, Name, Decription Model: ID, Manufact_ID, Name Order: ID, Manufact_ID, Model_ID, Quantity, Date, In Access I would like to have the normal table/datasheet view for Order which gives the following output ID Manufact.Name Model_ID(combo box) Quantity Date 1 LG W3000H-BN ...

Order by integer with blank fields at the bottom.

Hi, We're rewriting our CMS at the moment and we want our clients to be able to re-order items in a table using a "position" field. So, if they mark an items as position 1 it goes at the top, then position 2 underneath it etc. The problem is that we don't want to them to have to fill in a position every time, only if they want to re-or...

merged SQL table names

I have a merged table from several unions and i want to know from which of those tables the results were taken, is that possible? example... select name from users where name like '%alex%' union select name from admins where name like '%alex%'; Would return lets say two rows, Alexander and Alexandra. Alexander is an admin and Alexan...

Problems with MONTHNAME() on MySQL 5

I'm trying to run a report on our database. We want to know the new registrations per industry per month. I've written this query: SELECT COUNT(j.jobseeker_id) as new_registrations, i.description as industry_name, MONTHNAME(j.created_at) FROM tb_jobseeker as j, tb_industry as i WHERE YEAR(j.created_at) = 2009 AND i.indu...

Caching Strategy for queried data

I'm currently in the process of building a repository for a project that will be DB intensive (Performance tests have been carried out and caching is needed hence why I'm asking ) The way I've got it set up now is that each object is individually cached, if I want to do a query for them objects I pass the query to the database and retur...

Is statement.close() explicitly required in connection pooled environment?

I am using connection pooling in my application. My question is: Is it explicitly required to close statement before closing connection in case of connection pooled environment? In connection pooled environment connection is not getting closed, (but returns back to free connection pool). I had checked jdbc 4.0 functional specs. In poin...

Complicated Access SQL Query exclusion

For an access database that looks like this: (All text fields) Co1 Co2 Co3 Co4 A k t N1 B k t N2 A m t N3 B k z N4 A k z N5 C m t N6 C k z N7 C k t N8 A k t N9 C m t N10 I need to create some kind of reports that would do the following: The results needs to select rows: Ordered by Co1 first then ordered by Co2 ...

Mysql Index Being Ignored

EXPLAIN SELECT * FROM content_link link STRAIGHT_JOIN content ON link.content_id = content.id WHERE link.content_id = 1 LIMIT 10; +----+-------------+---------+-------+---------------+------------+---------+-------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+...

ssrs multi column table data gets spanned accross columns and/or pages incorrectly

In SSRS I built a report where a providers name, address, phone are listed in 3 columns on a page Grouped by State. Example Data: What I'm trying to do is prevent the data from spilling over into the next column or page. I want to just move the provider to the next column/page. Any suggestions? ...