sql

Using XQUERY/Modify to replace a piece of my XML with value from varchar field

I have a table: MyTable config as XML title as varchar(255) In MyTable.config I have XML in the following structure: <configuration pagetitle="myConfig"> <column> <row> <component id="1" type="MyPiece" title="My Title" text="junk" /> </row> </column> </configuration> I need a script to inject the value of MyTa...

auto_increment causing errors with CREATE TABLE

I have been using netbeans as a tool for my java, and i have a problem. I read this tutorial and then i tried to create a table using this SQL: CREATE TABLE CUSTOMERS ( ID INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, FIRST_NAME VARCHAR(20), LAST_NAME VARCHAR(30), ADDRESS VARCHAR(30), CITY VARCHAR(30), STATE_ VARC...

Best Way to DataBind a List with sub-related content (For example, SO's questions with tags)

Using ASP.net 2.0, how do I present the information to the user similar to the Questions list on SO where each question has some child items (like the tags). I would probably be making two separate queries, one to first find the list of questions, then another query to find all tags which belonged to the list of questions. Approach 1: ...

Change each record in a table with no primary key?

I have a table in a database that represents dates textually (i.e. "2008-11-09") and I would like to replace them with the UNIX timestamp. However, I don't think that MySQL is capable of doing the conversion on its own, so I'd like to write a little script to do the conversion. The way I can think to do it involves getting all the record...

Easiest way to convert CArchive to use SQL database for serialization?

I have an existing application that uses CArchive to serialize a object structure to a file. I am wondering if can replace the usage of CArchive with some custom class to write to a database the same way that things are serialized. Before I go about figuring if this is doable I was wondering if other people have done the same- what is ...

Can I concatenate multiple MySQL rows into one field?

Using MySQL, I can do something like select hobbies from peoples_hobbies where person_id = 5; and get: shopping fishing coding but instead I just want 1 row, 1 col: shopping, fishing, coding The reason is that I'm selecting multiple values from multiple tables, and after all the joins I've got a lot more rows than I'd like. I'v...

How do function indexes work in SQL?

Does anyone know how function indexes work in databases? ...

Avoid entering double quotes from start & ending of a string

Hi, In a database, I have a string that contains "default" written in it. I just want to replace that default with 0. I have something like: select * from tblname where test = 'default' I do not want quotes in the replacement for "default". I want select * from tblname where test = 0 is there any way to do this? ...

T SQL - Eloquent replacement of Correlated Subquery

I have a query that is currently using a correlated subquery to return the results, but I am thinking the problem could be solved more eloquently perhaps using ROW_NUMBER(). The problem is around the profile of a value v, through a number of years for an Item. Each item has a number of versions, each with its own profile whick starts w...

How can I run sql server stored procedures in parallel?

I want to do something like: exec sproc1 and sproc2 at the same time when they are both finished exec sproc3 I can do this in dts. Is there a way to do it in transact sql? Or is there a way to do it with a batch script (eg vbs or powershell)? ...

Oracle String Concatenation Operator

What is the string concatenation operator in Oracle SQL? Are there any "interesting" features I should be careful of? (This seems obvious, but I couldn't find a previous question asking it). ...

Which tools or methods would you suggest for creating large amounts of SQL test data?

I'd like to stress test some of my SQL queries and find out about bad query plans and bottlenecks. I plan to fill some tables with random test data. Are there tools or a set of scripts available for this purpose, preferably for SQL Server? Thanks! UPDATE: Sorry, didn't know these two question already existed: Data generators for SQL...

Incorrect syntax near store procedure error

I'm updating a long list of records. In my code, everything run as predicted until it execute the query. It gave me a incorrect syntax near 'TempUpdatePhysicalCityStateZip'. (My store proc name). I've test it on the sql studio and it run fine. So, I'm not quite sure where i got it wrong. Below is my store proc. and code. ALTER PROCEDURE...

Should I use the CASCADE DELETE rule?

I've always been too scared to use DELETE CASCADE, but as I get more confident (lazy :D), I'm thinking how bad can it be, is it best practise to use it or should I avoid it and clean up my foreign keys etc the old fashioned way (with stored procedures)? ...

How to create dynamic and safe queries

A "static" query is one that remains the same at all times. For example, the "Tags" button on Stackoverflow, or the "7 days" button on Digg. In short, they always map to a specific database query, so you can create them at design time. But I am trying to figure out how to do "dynamic" queries where the user basically dictates how the d...

question on how to use sql server integrated service

I have a table called book with, the attrbutes are booked_id, yearmon, and day_01....day_31. Now i need to unpivot the table and transform day_01...day_31 into rows, I have successed in doing that, but the problem is that my yearmon is a format of 200805 and i need to append a day to it based on day_01 or day_02 etc, so that i can create...

SQL Cheatsheet?

Just wondering if anyone has any favourite SQL references they to use when creating new queries. Possibly something that shows syntax, or available functions? ...

Using SQL to determine cidr value of a subnet mask

I'd like to find a way to do a SQL query that will calculate the cidr (bit representation) of a subnet mask stored in the database. So for example, I've got either 255.255.255.0 or its decimal value (4294967040) stored in the database. I'd like to do a select and get back /24 representation via the query. I've done things like the fol...

Why does this SQL script work as it does?

I'm pulling email address records from a table in SQL Server 2005, and want to build a single string to use as the @recipients list with sp_send_dbmail. The table has a field called EmailAddress and there are 10 records in the table. I'm doing this: DECLARE @email VARCHAR(MAX) SELECT @email = ISNULL(@email + '; ', '') + EmailAddres...

Email Notification Service

What are some ideas (using .NET and SQL 2005) for implementing a service that sends emails? The emails are to be data-driven. The date and time an email is to be sent is a field in a table. ...