sql

mysql Query: Select Lastest Where Another Row With N doesn't exist

Hi, sorry about the title, I'm not sure how to even describe this, which makes it even harder to search for a solution. I have a table which has many answers: CREATE TABLE `answers` ( `a_id` int(11) NOT NULL auto_increment, `p_id` int(11) NOT NULL default '0', `q_id` int(11) NOT NULL default '0', `user_id` int(11) NOT NULL defa...

F# Generate SQL from CSV

I have recently been learning F# and functional programming. One application I have found very useful is generating SQL inserts for a data load from a CSV (or excel table) with some associated ID's. The following code is my result, which I believe I will find very handy in the future. I thought others could also benefit from this and ...

why it returns SQL exception?

I have a "Manager" class and also one frame which is"Report" .In the frame I have three radio buttons which their texts are "Years before 1970","between 1970 and 2000","years after 2000" and if one of them is selected , in the text field below these radio buttons I will show the number of rows that have this situation which are in my SQ...

How to fill a varbinary(MAX) column with a default image for all the records in SQL Server 2005 Express

I want to fill the varbinary(MAX) column of a SQL Server database table when ever a new record is created with a default picture. How do I do this using a trigger or in that case by any other means? Any help is highly appreciated. Thank You This is the T-SQL code I have tried: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER TR...

generic stored procedure in oracle

I want to write a PLSQL stored procedure that accepts a table name as argument. This table is source table. Now inside my procedure i want to manipulate the fields of that table. EX: I want to insert the records of this source table into another target table whose name is XYZ_<source table name>. The column names for source and targ...

Compare unique values from two mysql tables

I have two mysql tables: TableA has 10,000 records TableB has 2,000 records. I want to copy the 8,000 unique records from TableA into TableB ignoring the 2,000 in TableB which have already been copied. ...

SQL Server 2008 query to find rows containing non-alphanumeric chararacters in a column.

I was actually asked this myself a few weeks ago, whereas I know exactly how to do this with a SP or UDF but I was wondering if there was a quick and easy way of doing this without these methods, I'm assuming that there is and I just can't find it. A point I need to make is that although we know what characters are allowed (a-z, A-Z, 0...

SQL Server / Link Server SOTAMAS90 ?

Can anyone tell me how to create a link server in SQL Server 2005 with SOTAMAS90? ...

sql and database

Hi, I have this method in my database class.and I want to get a part of data from a column which is "dateOfBirth" in MySQL table ,but I don't know why the list.size() is "0" but when i use System.out.println() in my code it will show just the first line of sql table ,although I have two rows!!! my method: public static int getBirthP...

How to create a column of a specific type ?

How would I add a column to a Select and have that column be of a specific type. For example Select Company, City, Dues, 0 As NewColumn1, 123.12 As NewColumn2 But I want NewColumn1 to be of type bit, and NewColumn2 to be of type Real Oh, I'm using SQL Server 2005. ...

Minimum price selection

Situation looks like this: We have product 'A123' and we have to remember lowest price for it. Prices for one product comes from random number of shops and there is no way to tell when shop x will send us their price for 'A123'. So I had SQL table with columns: product_number price shop (from which shop this price comes) An SQL fun...

merge student name under the same company names and only show the selected student name under that particular company

I have got something like this as a prototype and i wanted it sorted according to this. but now my code have all the student name under different companies. how i can fetch them according when this student and this company is link and only fetch them out like that? no codes done yet though. ...

sql query complex

I have table where in a table called test which have 4 fields.one field named as listing, I have 1,2,3,4,5,6 multiple values separated by comma, I need to check whether in that table and in that particular field an id say 4 is there or not.. by a sql query. ...

Finding any rows where the latest event time is over a specified period

The relates to OpenNMS where I'm trying to write an automation in SQL. I have a system which sends events to a table every time the backup succeeds. I want to detect if the backup is overdue for any given node. So for example the (simplified) table looks like: nodeid, eventid, eventuei, eventtime 1 , 1 , backupOk, 09:20 15/12/0...

What is the difference between Scope_Identity(), Identity(), @@Identity, and Ident_Current?

I know Scope_Identity(), Identity(), @@Identity, and Ident_Current all get the value of the identity column, but i would love to know the difference. Part of the controversy i'm having is what do they mean by scope as applied to these functions above? I would also love a simple example of different scenarios of using them? ...

MySql - autocomplete

Hi Everyone, I am creating an Ajax autocomplete application and would like know if there is an SQL query I can use for this purpose - e.g if someone types "p" I would like to retrieve all words beginning with "p", if they add "e" retrieve all words starting with "pe" - and continue like that. Someone suggested the query below but I don...

what is more appropriate way loop through object collection or database hit

hello everyone, i am using collection object. In some cases no of objects become large. in that case what i have to do either loop through the object collection or do a new hit? which gives more optimal to performance ? ...

Round to n Significant Figures in SQL

I would like to be able to round a number to n significant figures in SQL. So: 123.456 rounded to 2sf would give 120 0.00123 rounded to 2sf would give 0.0012 I am aware of the ROUND() function, which rounds to n decimal places rather than significant figures. ...

Complex SQL query with group by and having

Hello All, I am having a table orders orders ( id int unsigned not null, fcr_date TIMESTAMP, completion_date TIMESTAMP, factory_no varchar(255), vendor_no varchar(255)) Please ignore the data type typos if any. I want to write a sql query that helps me filter the data per vendor factory. The data to fetch includes the number of ...

Thread safe sql transaction, how to lock a specific row during a transaction ?

I have a procedure like this: create procedure Checkout @Foo nvarchar(20), @cost float as begin transaction declare @Bar nvarchar(20); select @Bar = Bar from oFoo where Foo = @Foo; update Foo set gold = gold - @cost where name = @Foo; update Bar set gold = gold + @cost where name = @Bar; delete from oFoo where @Foo = Foo; commit tra...