sql

SQL Query 'invalid column name'

The following sql query works fine if I leave the four commented SET statements commented out. However, if I uncomment them, or just say I uncomment the first one SET @StoreID = tt_StoreID then I get the following message Invalid column name 'tt_StoreID' Why doesn't it recognize it, and how do I fix it ? *---------------------...

How to generate unique ID's on a cluster of web servers

In the following scenario: 1 Database 4 Web servers How do the Web servers generate unique ID's for the database so that they are unique? Yes it's possible to use Auto-increment, but this is too easily crawled/guessed/etc. So auto-increment is currently not an option. ...

Getting rid of hard coded values when dealing with lookup tables and related business logic

Example case: We're building a renting service, using SQL Server. Information about items that can be rented is stored in a table. Each item has a state that can be either "Available", "Rented" or "Broken". The different states reside in a lookup table. ItemState table: id name 1 'Available' 2 'Rented' 3 'Broken' Add...

TSQL Conditionally Select Specific Value

This is a follow-up to #1644748 where I successfully answered my own question, but Quassnoi helped me to realize that it was the wrong question. He gave me a solution that worked for my sample data, but I couldn't plug it back into the parent stored procedure because I fail at SQL 2005 syntax. So here is an attempt to paint the broader...

casting in MySQL

I have a varchar field that looks like (sadly I have no control over the data): Fri, 30 Oct 2009 06:30:00 EDT Is there a way to cast this into a timestamp format so that I can then sort based on it? ...

Storing a 30KB BLOB in SQL Server 2005

My data is 30KB on disk (Serialized object) was size should the binary field in t-sql be? Is the brackets bit bytes ? ... so is binary(30000) .... 30KB? Thanks ...

MySQL Syntax for setting Default Date

How can we set element to some default date in mysql ? In oracle we would do something like start_date DATE DEFAULT to__date('01011900','DDMMYYYY') mutation_date_time DATE DEFAULT SYSDATE CONSTRAINT entity_specification UNIQUE(external_name, start_date_time, end_date_time)) Also do we have any site or resource where we can get ...

Any References to Example Projects

Currently I am a moderate (in terms of difficulty) when it comes to PHP. I would like to test my knowledge by developing certain utilities using PHP (and maybe SQL). But the problem is that I am not able to find any example projects. Does anyone have any links or some small sample projects? ...

Recommened SQL Priviledges for MySQL users for CMS'es

I have been experimenting with a lot of web development apps like Drupal, Moodle, Efront and Elgg lately. For better security, I run test servers on a XAMPP setup on a virtual XP machine inside Mac OS X 10.4, using Parallels. I think this should be pretty secure, right? When installing software like Elgg, it asks me to create a user in ...

SQL Extract substring

I'm having an issue extracting a substring in SQL query results. Here's the situation: I have a column that contains strings in the following format "ax123456uhba", "ax54232hrg", "ax274895rt", "ax938477ed1", "ax73662633wnn2" I need to extract the numerical string that is preceded and followed by letters. However, occasionally there is...

MySQL "CREATE TABLE IF NOT EXISTS" -> Error 1050

Using the command: CREATE TABLE IF NOT EXISTS `test`.`t1` ( `col` VARCHAR(16) NOT NULL ) ENGINE=MEMORY; Running this twice in the MySQL Query Browser results in: Table 't1' already exists Error 1050 I would have thought that creating the table "IF NOT EXISTS" would not throw errors. Am I missing something or is this a bug? I am ...

Is there a mysql function that will format a unix timestamp?

I have a unix timestamp that I would like to convert using mysql if possible. I'd like to have: Mon. May 21st 2009 I can of course do this with PHP but why if I can have the database do it. Does a function exist for this? Thanks. ...

Extracting words from text field in SQL

Hi, I'm currently building a little CMS for a smaller site. Now I want to extract all words from the text_content field and store them in my word table for later analysis. page( id int, title varchar(45), # ... a bunch of meta fields ... html_content text, text_content text); word( page_id int, # Forei...

Fuzzy grouping in Postgres

I have a table with contents that look similar to this: id | title ------------ 1 | 5. foo 2 | 5.foo 3 | 5. foo* 4 | bar 5 | bar* 6 | baz 6 | BAZ …and so on. I would like to group by the titles and ignore the extra bits. I know Postgres can do this: SELECT * FROM ( SELECT regexp_replace(title, '[*.]+$', '') AS title FROM t...

Swap columns from two sql server tables

I would like to know if there is anyway I can compare two columns in SQL Server. The two columns are located in two different tables. When the column 1's value is smaller than the column 2's value: I want to replace the value of the column 1 with the value of the column 2. ...

Windows impersonate [SQL, ASP.NET, C#]

Hi guys, I try use windows impersonate in asmx web service to read sql database. I make new account in windows. Set permission to full control on database file ORLDatabase.mdf. Now I call method GetDataSet, but it finish on client side with this error: System.Web.Services.Protocols.SoapException: Server was unable to process request...

Tools for Migrating from Oracle to MySQL

I want to migrate schema from Oracle to MySQl, so are the any free tools that would be useful for this task ? I have only Create tables in Oracle SQL Script but it contains unique constraints, foreign key and MySQL has MyISAM storage engine and so foreign key is not supported, how to go about this issue ? Sample Oracle create statments...

GUID Primary Key not being created

When I add a user to my database, I am using a Guid for the primary key. But it is coming in as just a solid string of 0's. Where am I supposed to set it? I set it to "RowGuid()" in the MS-SQL server... ...

How can i add mdf database to Ms sql server database

I have given asp.net membership provider security into my web application for login and created database into the ms sql server all working fine on local server but, when I transfer my database local machine to server login credential is not working. I am guessing its happen because, I have used asp.net membership security and it has cre...

SQLite expression to count rows grouped by week

I have a table with the only relevant column being completionDate, a number of seconds after the epoch that an item was marked complete. I would like to do a select statement to count the number of items complete, grouped by the week in which they were marked complete. So far, I've got something like this: SELECT (completionDate-min)/...