sql

Update table with values from another table

I have these tables: customer: customer_id vat_number =========== ========== 1 ES-0000001 2 ES-0000002 3 ES-0000003 invoice: invoice_id customer_id vat_number ========== =========== ========== 100 1 NULL 101 3 NULL 102 ...

sql server rollback...

Possible Duplicate: SQL Identity (autonumber) is Incremented Even with a Transaction Rollback does a rollback also rollback identity values??? ...

mysql datetime comparison

For example the following query works fine: SELECT * FROM quotes WHERE expires_at <= '2010-10-15 10:00:00'; But this is obviously performing a 'string' comparison - I was wondering if there was a function built in to MySQL that specifically does 'datetime' comparisons. ...

Convert Xml to Table SQL Server

I wonder how can i read a xml data and transform it to a table in TSQL? For example: <row> <IdInvernadero>8</IdInvernadero> <IdProducto>3</IdProducto> <IdCaracteristica1>8</IdCaracteristica1> <IdCaracteristica2>8</IdCaracteristica2> <Cantidad>25</Cantidad> <Folio>4568457</Folio> </row> <row> <IdInvernadero>3...

SQL Server - Poor performance of PK delete

I have a table in SQL Server 2008 R2 consisting of about 400 rows (pretty much nothing) - it has a clustered index on the primary key (which is an identity). The table is referenced via referential integrity (no cascade delete or update) by about 13 other tables. Inserts/Updates/Gets are almost instant - we're talking a split second (a...

sql resultset records numbering ?

I want to number the rows in my result set. I want some way I can have a result set of 3 records use some SQL keyword to generate a column that would read 1,2,3 for watch of the records... I know I can make a temp table with an auto increment column but i wanted to know if there was a way I can get this back from a SQL query? SELECT r...

Database table PK question

I have a table where I store comments for user users. I will have 100 Million+ comments. 2 ways I can create it: Option 1: user name and comment id as PK. That way all comments are stored physically by user name and comment id. CREATE TABLE [dbo].[Comments]( [user] [varchar](20) NOT NULL, [com_id] [int] IDENTITY(1,1) NOT NULL,...

How can I speed up MySQL query with multiple joins

Hello all, Here is my issue, I am selecting and doing multiple joins to get the correct items...it pulls in a fair amount of rows, above 100,000. This query takes more than 5mins when the date range is set to 1 year. I don't know if it's possible but I am afraid that the user might extend the date range to like ten years and crash it....

What's "wrong" with my DQL query?

I have the following SQL query: select bank.* from bank join branch on branch.bank_id = bank.id join account a on a.branch_id = branch.id join import i on a.import_id = i.id It returns exactly what I expect. Now consider the following two DQL queries: $q = Doctrine_Query::create() ->select('Bank.*') ->from('Ban...

Replacing PK's in Existing SQL DB Tables

Right now I have a DB where the PK's are int IDENTITY. I recently, in the last year, was tasked with adding these to a Replication Topology. This has worked out quite well with the exception of the IDENTITY fields. I want to explore my options for changing or replacing them with a uniqeidentifier(GUID). Is it feasible to insert a NEW ...

Multiple COUNT in 1 SQLITE Query

Using SQLite. SELECT c.*, COUNT(m.course_id) AS "meeting_count", COUNT(r.meeting_id) AS "race_count" FROM course c LEFT JOIN meeting m ON m.course_id = c.id LEFT JOIN race r ON r.meeting_id = m.id GROUP BY c.id Course has meetings has races. Trying to select the correct count for course meetings and cours...

How make for order by name in MYSQL as with order name in Window

table Picture with rows have name 1.jpg,2.jpg,3.jpg,4.jpg,5.jpg,6.jpg,7.jpg,8.jpg,9.jpg,10.jpg,11.jpg select * from Picture order by name mysql order : 1.jpg,10.jpg,11.jpg,2.jpg,3.jpg,...... Issue: I want it sort all type name like as with Window 1.jpg,2.jpg,3.jpg,4.jpg,5.jpg,6.jpg,7.jpg,8.jpg,9.jpg,10.jpg,11.jpg and it must worki...

Trouble with SQL UNION operation

I have the following table: I am trying to create an SQL query that returns a table that returns three fields: Year (ActionDate), Count of Built (actiontype = 12), Count of Lost (actiontype = a few different ones) Bascially, ActionType is a lookup code. So, I'd get back something like: YEAR CountofBuilt CountofLost ...

Why is special character coming out strange from MySql db after I changed to sessions?

I have a classified website, and I recently changed the insertion of classifieds to use php Session variables instead of alot of POST and FORMS... So first BEFORE changing to Sessions, it worked nice and all special characters showed up correctly. Now that I changed to SESSIONS, I get funny characters instead of the special characters....

access sql statement is returning nothing!

i am having a problem with access sql SELECT statement. the problem is that when the backend is ACCESS-2007 it works; however when the backend is sql-server-2008, it is not returning anything. here is the statement: SELECT IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11*Other*','1.11 Other',[Lab Occurrence For...

Database: Does the appendix 'HX' have significant value?

I'm working with a legacy application with surprise surprise, next to no useful documentation on naming convensions or over all data structure. There are similarly named tables in the database with one of them ending in HX. Does this hold any significance in anyones database experience? The data seems to be replicated so I would assume...

Sorting by some column and also by rand() in MySQL

Is it possible to sort a result set by some column and also by RAND()? For example: SELECT `a`, `b`, `c` FROM `table` ORDER BY `a` DESC, RAND() LIMIT 0, 10 Thank you. ...

sql server: will this datetime work?

SELECT "2 0 Analytical (Testing Phase)" FROM "dbo"."Lab Occurrence Form" WHERE (("Occurrence Date" BETWEEN @P1 AND @P2 ) AND ("2 0 Analytical (Testing Phase)" LIKE ''%2.%'' ) ) ', N'@P1 datetime,@P2 datetime','2010-04-30 00:00:00','2010-04-01 00:00:00' is this the correct format to return records between a certain datetime?...

Is it possible to update a variable field in a stored procedure?

I have a simple query that updates a variable column. This query is later string.Formatted and passed to SqlCommand (c#) (TableId is a column in SomeTable): "UPDATE SomeTable set {0}=@Value where TableId=@TableId" I need to convert this query to a stored procedure. Is it possible at all? ...

Searching in SQL Management Studio 2005

Is there a way to search for text within stored procedures? For example I want to find out if a particular table is being referenced by any stored procedure. ...