sql

Get data from two tables depending on data from one in a single query

I'm making a simple forum, and in the listing of the threads i want the classical "last post by (user) at (date)" to show. I'm using only one table to contain all the posts in the forum, where posts with the parentPost-field not equal to null are replies to a thread. These are the tables and necessary fields i need data from: forumPost...

How to describe Full text search for a client?

I implemented a full text search "searching in tags", using SQL server 2005, I want to describe for the client what i did, what what full text search means by simple examples? My Client is not a programmer but a good internet user. ...

Lazy loading/caching of SQL query results with a model

I'm developing a system (with Rails 2.3.2, Ruby 1.8.7-p72) that has a sizable reporting component. In order to improve performance, I've created a Report model to archive old reports. The idea is that if a matching report already exists for an arbitrary set of conditions then use it, otherwise generate the report and save the results. ...

How to Convert SQL server to Oracle ?

I have a SQL server database (Tables, Views, SP...). I need to convert this database to Oracle 10g. How can I do it? ...

How to check which locks are held on a table

How can we check which database locks are applied on which rows against a query batch? Any tool that highlights table row level locking in real time? DB: SQL Server 2005 ...

Cannot simply use PostgreSQL table name ("relation does not exist")

I'm trying to run the following PHP script to do a simple database query: $db_host = "localhost"; $db_name = "showfinder"; $username = "user"; $password = "password"; $dbconn = pg_connect("host=$db_host dbname=$db_name user=$username password=$password") or die('Could not connect: ' . pg_last_error()); $query = 'SELECT * FROM sf_ba...

Should I use Natural Identity Columns without GUID?

Is it ok to define tables primary key with 2 foreign key column that in combination must be unique? And thus not add a new id column (Guid or int)? Is there a negative to this? ...

Porting from MySql to T-Sql. Any INET_ATON() equivalent?

Need to move some code from MySql to TSql. I have a couple of calls to INET_ATON which converts a string which resembles an IPAddress into a number. Is there a T-SQL equivalent? ...

Creating table names that are reserved words/keywords in MS SQL Server

Is it ok to name my database tables that are already keywords? For my case, I am trying to name the table that will hold my users. I've named it User but it is showing up as pink in SQL Server Management Studio so I am assuming its an existing System Table or Keyword. Thanks for your advice. ...

Simple Java library - output Oracle query to CSV?

Is there a simple Java library or approach that will take a SQL query and output the result to a CSV file? Update: I found there were a couple other related SO posts existing (1, 2) ...

Creating XML using the from XML clause using SQL 2000

I am creating an XML document from a SQL query and i was wondering if there is a way to output the version and encoding tag via the SQL Query? ...

What's the best way to audit log DELETEs?

The user id on your connection string is not a variable and is different from the user id (can be GUID for example) of your program. How do you audit log deletes if your connection string's user id is static? [EDIT] The best place to log insert/update/delete is through triggers. But with static connection string, it's hard to log wh...

How do I use select with date condition?

Hello, In sqlserver, how do I compare dates? For example: Select * from Users where RegistrationDate >= '1/20/2009' (RegistrationDate is datetime type) Thanks ...

How to manage SQL Statements in Data Layer

Hi, in a PHP project we already have separated business logic from database access. All database tasks are encapsulated in different database classes grouped by database and topic. Theses classes look very horrible, half the source are SQL strings, that get filled with params and so on. We thought of putting the SQL in "other" locations...

How to insert dynamically through a variable in PL/SQL??

Lets create a table first create table test ( id number, name varchar2(20) ); Now during insert, i wanna hold the data into variable first & then dynamically pass the variable into the VALUES clause. declare v_data varchar2(50); begin v_data:='1,sunny'; execute immediate 'insert into test values(v_data)'; commit; end; But ...

MySQL - Combining question answers from multiple transactions

I have the follow tables in a database that I am using to store the results of surveys: http://img19.imageshack.us/img19/5016/strtranans.jpg Each time I speak to someone at a store (read Shop) I create a new transaction, with a date time (tblTransaction.Created). Each transaction can many question answers associated with it. My probl...

Comma separated Values

How can i fetch this query using mysql? Table1: id : nos 1 12,13,14 2 14 3 14,12 Table2: id : values 12 PHP 13 JAVA 14 C++ Now , I want output like this: 1 PHP, JAVA, C++ 2 C++ 3 C++, PHP ...

CSV Carriage Return Character

Hi I have a CSV output on one of my applications. This produces a file from of web form data. In some cases I am getting a carriage return character in my notes field. This causes an error when importing the file. I would like to remove this character. The issue appears to be happening when users paste information into the form from w...

sql server 2005 command line install error ADD_LOCAL property already installed

Hi, I have a silent installation of SQL Server 2005 that works great when installing SQL Server on a machine that does not have it already installed. I use the following parameters when I perform the installation: #define SQL_SILENT "/passive /qb" #define SQL_USERNAME "username=MyUserName" #define S...

Change the WHERE for a select on only one row depending on the field content

Ok, this may sound a little weird, but what I need to do is simple. I have a list of companies and each one has a description. The site is in 4 languages. My problem comes when I have listed a company in English but the person who is in charge of translating it in French still didn't make the translation, so I have a simple: SELECT TOP(...