sql

How to preserve an ampersand (&) while using FOR XML PATH on SQL 2005

Are there any tricks for preventing SQL Server from entitizing chars like &, <, and >? I'm trying to output a URL in my XML file but SQL wants to replace any '&' with '&amp;' Take the following query: SELECT 'http://foosite.com/' + RTRIM(li.imageStore) + '/ImageStore.dll?id=' + RTRIM(li.imageID) + '&raw=1&rev=' + RTRIM...

Ruby on Rails plugin for showing line numbers in log for SQL queries.

Does anybody know any plugin, that can show line numbers for SQL queries in Rails logs? Something like this: User Load (0.003154) SELECT * FROM `users` WHERE (`users`.`id` = 1) - (user.rb, line 24) Thanks! ...

Lightweight SQL database which doesn't require installation

Could you recommend me, please, lightweight SQL database which doesn't require installation on a client computer to work and could be accessed easily from .NET application? Only basic SQL capabilities are needed. Now I am using Access database in simple projects and distribute .MDB and .EXE files together. Looking for any alternatives. ...

Getting Dates between a range of dates

Hi All, I need to get all the dates present in the date range using SQL Server 2005 ...

search question

I'm working on a search module that searches in text columns that contains html code. The queries are constructed like: WHERE htmlcolumn LIKE '% searchterm %'; Default the modules searches with spaces at both end of the searchterms, with wildcards at the beginning and/or the end of the searchterms these spaces are removed (*searchterm -...

How to select maximum 3 items per users in MySQL?

Hi, I run a website where users can post items (e.g. pictures). The items are stored in a MySQL database. I want to query for the last ten posted items BUT with the constraint of a maximum of 3 items can come from any single user. What is the best way of doing it? My preferred solution is a constraint that is put on the SQL query re...

Copying BLOB values between databases with pure SQL in SQL Server

I need to pull some BLOB data from a SQL Server 2005 database and generate a SQL script to insert this same data in another database, in another server. I am only allowed to do this using SQL scripts, I can't use any other utility or write a program in Java or .NET to do it. The other big restriction I have is that I don't have access ...

How do I delete all the records in a table that have corresponding records in another table

I have two tables A and B. I would like to delete all the records from table A that are returned in the following query: SELECT A.* FROM A , B WHERE A.id = B.a_id AND b.date < '2008-10-10' I have tried: DELETE A WHERE id in ( SELECT a_id FROM B WHERE date < '2008-10-10') but that only works if the inner select ac...

SQL: Complex Deletion help

I basically created some tables to play around with: I have Two main tables, and a Many-Many join table. Here is the DDL: (I am using HSQLDB) CREATE TABLE PERSON ( PERSON_ID INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, NAME VARCHAR(50), MAIN_PERSON_ID INTEGER ) CREATE TABLE JOB ( JOB_ID INTEGER GENERATED BY DEF...

SQL Statement indentation good practice

Hi, What is the accepted practice for indenting SQL statements? For example, consider the following SQL statement: SELECT column1, column2 FROM table1 WHERE column3 IN ( SELECT TOP(1) column4 FROM table2 INNER JOIN table3 ON table2.column1 = table3.column1 ) How should this be indented? Many thanks. ...

SQL Server Print Blank Line Without Space

In SQL Server 2005, I want to print out a blank line with the PRINT statement, however, when I run PRINT '' it actually prints a line with a single space. Does anyone know if it's possible to just print a blank line without the space? If I print a new line character, it doesn't print a space, but I end up with two new lines. ...

Speed up sql JOIN

First of all, some background. We have an order processing system, where staff enter billing data about orders in an app that stores it in a sql server 2000 database. This database isn't the real billing system: it's just a holding location so that the records can be run into a mainframe system via a nightly batch process. This batch...

Stored Procedure failing on a specific user

I have a Stored Procedure that is constantly failing with the error message "Timeout expired," on a specific user. All other users are able to invoke the sp just fine, and even I am able to invoke the sp normally using the Query Analyzer--it finishes in just 10 seconds. However with the user in question, the logs show that the ASP alwa...

What is a good Visio Enterprise Architect replacement?

I've been using Visio 2002/2003 Enterprise Architect to do my database schema design visually and then forward-generate the DDL to create the database. I wanted to switch to Visio 2007, but while it does have database diagramming support, it doesn't have the ability to generate DDL. Bummer. I am really disappointed because it seems li...

MS SQL: Convert Datetime column to nvarchar

I need to select a datetime column in a table. However, I want the select statement to return the datetime as a nvarchar with the format DD/MM/YYYY. ...

What is a good framework for Database Migrations the is compatibile with SQL Server?

I've been spoiled by ActiveRecords. So I'm on the lookout for migration system that can be applied to SQL Server, and either is executed as Java application, or a Win32 Executable. (Of course further compatibility with other DB's and host OS's is welcome.) The real desire is having a clear schema change application with roll back, ide...

Access second result set of stored procedure with SQL or other work-around? Python\pyodbc

I'm using python\pyodbc and would like to access the second result set of a stored procedure. As near as I can tell, pyodbc does not support multiple result sets. Additionally, I can't modify the stored procedure. Are there any options to access the second result set using SQL or some other work-around? Perhaps create a second stored pro...

How to use GROUP BY to concatenate strings in SQL Server?

How do I get: id Name Value 1 A 4 1 B 8 2 C 9 to id Column 1 A:4, B:8 2 C:9 ...

Learning SQL. Where to get started?

I want to start learning sql? Where should I get started from? I am looking specific answers for: Platform - Windows/ Linux RDBMS - MSSQL/ Oracle/ MySQL Books - that goes along with some real world case studies (not the boring author/books relationship) Online resources - tutorials/ real world projects ...

MySQL: How to determine foreign key relationships programmatically?

Similar to this question but for MySQL.... How can I programmatically determine foreign key references in MySQL (assuming InnoDB)? I can almost get them with: SHOW TABLE STATUS WHERE Name = 'MyTableName'; ...but alas, the comment column which seems to contain some of this info gets truncated so I can't rely on it. There must be som...