sql

concatenate rows from a select statement

I have a select statement which is something like this select col1 from table1 where cond1=true This returns results like col1 _____ 5 5 6 3 but I want to change it to return me 5-5-6-3 Is this possible? If so how? Please let me know how to do this. Thanks in advance for your replies. ...

Designing SQL alternative?

I'm thinking of designing & implementing my own SQL-equivalent (DDL+DML) that is... a pure relational algebraic language, and has an elegant Lisp-/Scheme-like syntax Assuming an RDBMS such as MySQL, where exactly would I need to start my language design work? On top of the storage engine layer such as InnoDB? I don't know what all R...

Finding most active topics or games

What's a good metric for finding the most active forum thread or game in your database? Imagine you run a forum like 4chan. You want the most active threads to appear on the first page. You tried sorting topics by last_updated, but the result is chaotic: the threads you see on each refresh are effectively random, and jumping to the se...

SQL Server DB - Deleting Records, or setting an IsDeleted flag?

Possible Duplicate: What to do when I want to use database constraints but only mark as deleted instead of deleting? Is it more appropriate to set some kind of "IsDeleted" flag in a heavily used database to simply mark records for deletion (and then delete them later), or should they be deleted directly? I like the IsDeleted f...

When to use composite indexes?

What are the general rules in regards to using composite indexes? When should you use them, and when should you avoid them? ...

SQL Query Help

Hai, Table Structure Id No Date Time 0001, 01-05-2009, 040000 0001, 02-05-2009, 020000 0002, 01-05-2009, 060000 0002, 01-05-2009, 180000 Time and Date is nvarchar I want to get the data between Yesterday 030001 to today 030000 Day before yesterday 0300001 to yesterday 030000 I tried the below mentioned query Sel...

table size not reducing after purged table

I recently perform a purging on my application table. total record of 1.1 millions with the disk space used 11.12GB. I had deleted 860k records and remain 290k records, but why my space used only drop to 11.09GB? I monitor the detail on report - disk usage - disk space used by data files - space used. Is it that i need to perfrom sh...

Comparision of data in SQL through python

i have to parse a very complex dumps(whatever it is), i have done the parsing thruogh python.since the parsed data is very huge in amount, i have to feed it in the database (SQL), I have also done this... now the thing is i have to compare the data now present in the sql. in actual i have to compare the data of 1st dump with the data of...

sort distinct date column

Hi Experts, I need distinct year and month from date column which would be sorted by same column. I have date coulmn with values like (YYYY/MM/DD) 2007/11/7 2007/1/8 2007/11/4 2007/12/3 2008/10/4 2009/11/5 2008/5/16 after having query, it should be 2007/1/1 2007/11/1 2007/12/1 2008/5/1 2008/10/1 2009/11/1 This doesn't seems to ...

How to encode string in Oracle?

Hello, I have problem with encoding data in Oracle database. I want to xor string with another string (mask) and then encode it with base64. In Python this looks like: def encode_str(s, mask): xor_mask = mask while len(xor_mask) < len(s): xor_mask += mask chrs2 = [] for i in range(len(s)): chrs2.append(chr(or...

size limit for XML datatype in SQL 2005

Is there a size limit on the XML data type in SQL 2005? When I try to return anything more than 44kb size of the XML string from my stored proc, it just returns an empty string. I am using FOR XML PATH to return hierarchical data sets in XML format from my stored procs. ...

Month wise totals in columns

Hello, I've a table (Consumption) as follows: DocDate ItemCode Quantity 01.01.09 A 5 02.01.09 A 6 and so on.. for the whole year I need results as follow: ItemCode Jan09Total Feb09Total Mar09Total The problem is that the quantities should be summed up for the months, which should be in columns and acco...

Create hexadecimal number in SQL

I want to generate unique hexadecimal numbers in SQL. How can I do this? If you know how to generate in c# please also include that. ...

Django: Order a model by a many-to-many field

I am writing a Django application that has a model for People, and I have hit a snag. I am assigning Role objects to people using a Many-To-Many relationship - where Roles have a name and a weight. I wish to order my list of people by their heaviest role's weight. If I do People.objects.order_by('-roles__weight'), then I get duplicates w...

Where Used Statements in SQL

I have data used primarily in one table in a database and referenced in several different tables. I need to correct the data. Is it possible to write a "where-used" statement that will search every table in the database and return all tables where the data is referenced? I am using SQL 2005. Thanks. ...

Passing multiple parameters of same column to SQL Server select SP

I have a string value in the web.config for example 2 guids separated by a ",". I need to query the database dynamically (i.e i have no idea how many values could be separated by a comma in the web.config) and run a select statement on the table passing these values and getting all that is relevant for example: select * from tablename...

Database Structure for Tree Data Structure

What would be the best way to implement a customizable (meaning, a tree structure with an unknown number of level) tree data structure in a database? I've done this once before using a table with a foreign key to itself. What other implementations could you see, and does this implementation make sense? ...

How can I combine these queries?

I have 5 queries I'd like to join together. Basically what they do is they go though the database and select how much a tenant has paid, and how much a tenant owes based on how long ago he or she was charged. I have four categories Charge < 30 days old Charge < 60 AND >= 30 days old Charge < 90 AND >= 60 days old Charge > 90 days old ...

Handling identity columns in an "Insert Into TABLE Values()" statement?

In SQL Server 2000 or above is there anyway to handle an auto generated primary key (identity) column when using a statement like the following? Insert Into TableName Values(?, ?, ?) My goal is to NOT use the column names at all. ...

Reporting Services / Supporting robust filtering

I'm looking for sort of a 'best practice' way to tackle this common scenario. I think the question is best asked with an example. Let's assume the following: The goal is to write an 'order summary' report which displays a listing of orders based on various filtering criteria. Example: The user wants to report on all orders created ...