sql

Literal does not match format string in Oracle

Hello I am trying to run this oracle query in toad and I am getting the above mentioned error. How can I fix it? INSERT INTO IMAGE ( IMAGE_SEQ_NO,BLDG_ID,BU_ID,DT_TAKEN, NEGATIVE_NO,FILENAME,FILE_TYPE,DESCRIPTION, STORAGE_SRCE,DOC_ID,PICT_SRCE_TYPE,TAKE_BY, INFO_SRCE,DOC_REF_NO,DOC_TYPE,SUB_DOC_TYPE, DDW_IMAGE_DOC_...

Using dynamic finders to specify NOT NULL

I very often want to use dynamic finders to specify NOT NULL. So… this works: Widget.find_all_by_color('blue') this works: Widget.find_all_by_color(nil) But how can I do SELECT * FROM `widgets` WHERE `color` IS NOT NULL; ? ...

Cross-platform SQL date difference function or query

I have a table that has a datetime column and I need to retrieve records with a date within the previous hour, day, week, month etc. One constraint is that I need to support Oracle, MySQL, DB2 and SQL SERVER. Can I achieve this with one SQL query only? ...

SQL SELECT criteria in another table

I have 2 related tables: messages -------- mid subject --- ----------------- 1 Hello world 2 Bye world 3 The third message 4 Last one properties ---------- pid mid name value --- --- ---------------- ----------- 1 1 read false 2 1 importance high 3 2 read false 4 2 i...

Join queries and when it's too much...

I find that I am using a lot of join queries, especially to get statistics about user operations from my database. Queries like this are not uncommon: from io in db._Owners where io.tenantId == tenantId join i in db._Instances on io.instanceId equals i.instanceId join m in db._Machines on i.machineId equals m.machineId selec...

Selecting All Children From All Parents in mySQL

I have a simple table like this: +------------+---------+-----------+--------------+ | comment_id | post_id | parent_id | comment_text | +------------+---------+-----------+--------------+ | 1 | 200 | 0 | a | | 2 | 200 | 0 | b | | 3 | 200 | 1 | ...

sql constraints

Why do i have to drop all constraints (keys in general) before i can drop a table in sql server. I dont understand why this would be necessary if I have permissions to drop the table and the know how to do it why not drop all constraints for me? Is there some sort of technical or database design reason for this? ...

Tracing an ajax error to a sql query

I am working within the confines of CMS software, that automatically generates a query for use in a google suggest like input field. The provided fields works fine, with the query they use which uses an inner join over two tables. I am trying to make a query which will grab information from just one table, and will returns results on e...

SQL query and stored procedure not producing desired results

I have this table and Stored proc function: Table: CREATE TABLE _DMigNumbers( Number numeric(20,0) NOT NULL PRIMARY KEY ); INSERT INTO _DMigNumbers VALUES(0) Stored proc function: CREATE FUNCTION read_and_increment() RETURNS NUMERIC(20,0) BEGIN DECLARE @number_just_read NUMERIC(20,0); SELECT number INTO @number_just_r...

converting SQL to ACCESS

here's a regular SQL statement: SELECT SUM(CASE WHEN [Column2] = 'Cylinder' THEN 1 ELSE 0 END) as 'Cylinder count', SUM(CASE WHEN [Column2] = 'Snap' THEN 1 ELSE 0 END) as 'Snap count', SUM(CASE WHEN [Column2] = 'Tip' THEN 1 ELSE 0 END) as 'Tip count', SUM(CASE WHEN [Column2] = 'Other' THEN 1 ELSE 0 END) as 'Other count' FROM [TableName]...

SQL query help.

Hi, Sorry for posting this question again. I rephrased my question a little bit. I am trying to write a query to return rows from Table-A where multiple rows found in Table-B with STATUS = 1 for each CID column from Table-A. So in this example CID 100 has two records found in Table-B and STATUS = 1. So I want to write a query to retur...

getting rid of zeros in the output of an access query

i have a query in access that is this: SELECT iif([Cup Type] like '*Cylinder*',count([Cup Type]),0) AS Cylinder, iif([Cup Type] like '*Snap*',count([Cup Type]),0) AS Snap, iif([Cup Type] like '*Tip*',count([Cup Type]),0) AS Tip, iif([Cup Type] like '*Other*',count([Cup Type]),0) AS Other FROM [Lab Occurrence Form] WHERE [1 0 Preanaly...

Help with SQL query

I've got the next SQL query: SELECT FIRST_NAME, LAST_NAME FROM MYTABLE WHERE STATUS = 1 AND VARIABLE IN ( 'PR', 'AR' ) AND SPECIAL = 1; SPECIAL is an aditional condition which is added if I previously selected 'PR' (checkbox) in my form. The thing is, with this query, I'm no longer getting rows where VARIABLE is 'AR'. Now, the idea i...

sql scalar function returns invalid quarter

I am sure that I am overlooking some simple thing, I admit that I am still learning various aspects of SQL and the Datepart function is one.. I am inputting a date and returning an invalid quarter, here is the code: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER FUNCTION Dbo.FN_Get_Quarter ( -- the parameters for the functi...

(Common Table Expressions) CTE as part of WHERE clause... possible?

Is it possible to use CTE in a WHERE clause e.g. SELECT * FROM Table1 WHERE Table1.PK IN ( WITH Cte AS ( -- root selection (dynamic, generated in code) SELECT Bla FROM Table2 -- recursive part UNION ALL SELECT …..) SELECT Bla FROM Cte) The reason I’m asking is that I need to use a recursive query and the ...

Can this query be any more DRY?

I've just checked out the ON DUPLICATE KEY UPDATE for MySQL. Here is an example query. $query = 'INSERT INTO `activities` (`id`, `hole_id`, `name_id`, `start_depth`, `end_depth`, `start_time`, `end_time` ...

IndexDB, WebSQL in 4 Months

Hi All, I've got a bit of a problem, I'm about to start a 4-6 month project which will need offline support. AppCache is awesome and accepted as the standard but the big browsers are still undecided about the database implementation with Opera, Safari and Chrome opting for WebSQL (SQLite) and Mozilla and supposedly IE backing IndexDB. ...

SQL Server - Update a column if row is the first record in group

How do i identify the first row that has value for each Brand and Category, then update Column "FirstValue" as 1, else 0? e.g of expected table Date | Brands | Category | Value | FirstValue Jan 08 | A | 1 | 0 |0 Jan 08 | A | 2 | 0 |0 Jan 08 | A | 3 | 0 |0 Jan 08 | ...

One simple MySQL query modified, works but errors on certain input

I am having trouble with a query used by a google suggest type of feature in a CMS The first link is the query that is provided by and used within the CMS itself, and works flawlessly. The second is my modification, which works fine but when certain input is entered, such as 'b', generates a syntax error, and I can not understand why. ...

International Replication Timestamps

Hi all, My scenario is as follows. I have a client and server. The client pulls data from the server by using a value that is stored locally called LastReplication. This value is passed to the server whenever a request for replication data is made and the server compares it to a field in my database called LastUpdated and returns and r...