sql

query with case column

In a query, I have a column like this: case when X = 1 then case when Y <> 0 then YY else XX end else ZZ end as MyColumn Is there a way, in another column, to check the above column value referencing MyColumn instead of rewriting the case statement? I should value another column based on the MyColumn value. Thanks ...

Oracle-SQL: Generating cyclical, composite sequences

I want to generate composite sequences in the following format: <Alphabet><2 digit numeric code> Each alphabet series will have numeric values ranging from 00 to 99. The initial value will be A00, the subsequent values will be A01, A02 and so on. Upon reaching A99, the next sequence should carry-on to B00. When the "B" series is exha...

aggregate sql data into business objects- sample code inside -

Do you see a better way to read data from sqlite database into business collections? These are 2 methods of my Repository. I want to get all Schoolclass entites with/without referencing Pupil entities (see Left outer join) Is there anything that I can improve ? Haven`t found any good tips about that scenario in google so I tried mysel...

How to search for a substring in SQLite?

Whats the most efficient way to search for a sub string in SQLite? I'm looking at the LIKE operator. Do I have the right idea? Has this worked well for you? http://www.sqlite.org/lang_expr.html Thank You. ...

How can I write an INSTEAD OF INSERT trigger that sets one column for any table?

Howdy, I am working on a legacy app that is being extended to run in a multi-tenant configuration. The basic architecture takes the old application and adds a StoreID column to every table. Each tenant then sees the legacy tables through a set of views that filter on store id, something like: create view AcmeBatWings.data as select ...

join on three tables? Error in phpMyAdmin

I'm trying to use a join on three tables query I found in another post (post #5 here). When I try to use this in the SQL tab of one of my tables in myPHPAdmin, it gives me an error: #1066 - Not unique table/alias: 'm' The exact query I'm trying to use is: select r.*,m.SkuAbbr, v.VoucherNbr from arrc_RedeemActivity r, arrc_Merchant m...

High Plan Count in SQL Server 2008 Activity Monitor

I have a MERGE query to create an upsert operation on my database with data entered through my application. When I go to call it to save my data on large transactions (>5000) it takes a very long time (~20-40 seconds). Here's my MERGE statement MERGE TestTable AS target USING (SELECT @Guid) AS source (target.Guid = source.Guid) WHEN M...

Why am I getting PLS - 00382?

Here is my object def: CREATE OR REPLACE TYPE FALCON.contacts AS OBJECT (phone VARCHAR2(50) ,phoneusage VARCHAR2(25) ,phonetype VARCHAR2(25) ,email VARCHAR2(150) ,phoneext VARCHAR2(25) ,anytext VARCHAR2(250)) Here is the table def: CREATE OR REPLACE TYPE FALCON.co...

How to store Goals (think RPG Quest) in SQL

Hi, Someone asked me today how they should store quest goals in a SQL database. In this context, think of an RPG. Goals could include some of the following: Discover [Location] Kill n [MOB Type] Acquire n of [Object] Achieve a [Skill] in [Skillset] All the other things you get in RPGs The best I could come up with is: Quest 1-* Que...

how to get values inside an xml column, when it's of type nvarchar.

My question is similar to this one: http://stackoverflow.com/questions/3061804/choose-a-xml-node-in-sql-server-based-on-max-value-of-a-child-element except that my column is NOT of type XML, it's of type nvarchar(max). I want to extract the XML node values from a column that looks like this: <Data> <el1>1234</el1> <el2>Something</el2> ...

How can I select adjacent rows to an arbitrary row (in sql or postgresql)?

I want to select some rows based on certain criteria, and then take one entry from that set and the 5 rows before it and after it. Now, I can do this numerically if there is a primary key on the table, (e.g. primary keys that are numerically 5 less than the target row's key and 5 more than the target row's key). So select the row with ...

SQL Server Fulltext Search contains phrase problem

I have a problem with SQL Server 2008 full text search I have the following query SELECT * FROM cigars WHERE CONTAINS(cigars.*, @Search ) @Search is a value that is passed in through a stored procedure. But, thats not the problem. What is is if someone searches for say 'Punch' it works fine and I get all cigars that match. Where the...

I'm not getting the expected result from an SQL query.

I'm developing a search function for a website. I have a table called keywords with two fields id and keyword. I have two separate search queries for AND and OR. The problem is with the AND query. It is not returning the result that I expect. The printed SQL is : SELECT COUNT(DISTINCT tg_id) FROM tg_keywords WHERE tg_keyword='keywor...

Performance of update statement inside DTS package

Hi, I have a DTS package, which after running daily with no problems for a couple of years, has started to play up. Originally it was inserting data into a table which would then fire an insert trigger. The trigger used [inserted] to update three columns in the table. Usually, it was updating about 500,000 rows of inserted data. When t...

What makes Cassandra (and NoSQL in general) a better solution to an RDBMS ?

Well, NoSQL is a buzzword right now so I've been looking into it. I'm yet to get my head around ColumnFamilies and SuperColumns, etc... But I have been looking at how the data is mapped. After reading this article, and others, it seems the data is mapped in a JSON like format. Users = { 1: { username: "dave", passwo...

Counting Subqueries

Say for example I have this table: Items: ------- id title price And I wanted to create a query that created a new row that for each item, it would query another table that matched the id, with the id in the other table, set the row another row in the other table. ...

Creating a new many-to-many table

I have a database Class_Books which links ISBNs (from Books table) to Class_ID's (from Classes table). I'm changing my Books table so the primary key is a Book_ID (autoincrement INT) instead of the ISBN. Is there a way to update Class_Books so it uses Book_ID now? ...

SQL Server 2008 slow down after 30,000 user Insert from a busy Java web application

One of our system finally launch in production and during the peak hour (about 200 concurrent user at any one time), traffic can ramp up to 30,000 user transaction within an hour. What we notice is a strange behavior that right after our SQL server restarted, the performance is very fast. Even with 200 concurrent user at the beginning,...

One-to-many table setup

I have a table where I have to relate groups of primary keys to one another. There is no information about these groups other than that they exist. Specifically, I am storing groups of Editions of Books together, so I can know that a certain set of books are editions of each other. I currently have a setup where I have an Edition_Group_...

Counting Subqueries

My last quest was too vague, so I will revise it. I know the following isn't correct SQL syntax, however you should be able to get the gist of the query I'm trying to perform. select id, title, count(select x from otherTable where otherTable.id = thisTable.id) as new_row from thisTable I...