sql

NoSQL or RDBMS for Data Analysis

Hi, i ask myself if i should try to use a NoSQL database or a SQL Database. I have read a lot, but would like to hear some people who hav experience with NoSQL. My situation is as follows: We have a not so complex relational database schema. We do reasearch on recommender systems and therefore monitor the user interactions with a specifi...

CRYPT_GEN_RANDOM strange effects

I want to randomly choose a value from a small range of integers (less than 200). As an alternative to SELECT RAND() I'm trying to use CAST(CAST(CRYPT_GEN_RANDOM(2) AS INTEGER) AS FLOAT) / 65535 but I'm getting some strange effects. For example: WITH Numbers (num) AS ( SELECT num FROM ( VAL...

Extending a long SQL with inner joins (server 2000)

Hi, Recently a very friendly user on stackoverflow helped me with this SQL: SELECT (SELECT TOP 1 a.id FROM vAnalysesHistory AS a WHERE a.companyid = n.stockid ORDER BY a.chosendatetime DESC) AS id, n.name, (SELECT TOP 1 a.chosendatetime FROM v...

Building a select distinct on mysql ( zend_db)

I HAVE THE FOLLOWING TABLE, I WOULD LIKE TO GET to do a select distinct on the the column [code], i don't need to get the "A" three times. [ ID ] [ CODE ] [ LIBELLE ] 1 A LIBELLE1 2 B LIBELLE2 3 C LIBELLE3 4 A LIBELLE4 5 A LIBELLE5 6 D LI...

Export to excel from SQL Server 2000 using Query Analyzer code

What's the easiest way to export data to excel from SQL Server 2000. I want to do this from commands I can type into query analyzer. I want the column names to appear in row 1. ...

delete duplicate record from same table in mysql

I have one table named tblm_customer. It contain field named firstname and lastname. Now I want to delete all records from the table that contain the same firstname and lastname that are already in the table. I used mysql database and customerid is the primary key in the table. ...

How to detect a record is locked?

With SQL Server 2008, how can I detect if a record is locked? EDIT: I need to know this, so I can notify the user that the record is not accessible because the record is blocked. ...

Sql Query - Unique item with latest date of entry

**Update: Title should have read: Sql Query - Unique item with latest entry Hi there, I have a two tables. users and rsvp. Users has user detail in it (id, name, email) rsvp has rsvp status in it (answerid, userid, eventid, answer) Note: answer 1 = coming answer 2 = not coming answer 3 = maybe answer 4 (pseudo answer) = no reply Plea...

sql server 2008: sp_RENAME table disappeared

Hi, I renamed the table by sp_RENAME (SQL SERVER 2008) sp_RENAME 'dbname.scname.oldtblname' 'dbname.scname.newtblnam' The resulting message (it was in black color - so I get it as just a warning or successful message) was something like "Caution: Changing any part of an object name could break scripts and stored procedures." So afte...

Float or decimal for prices?

Hi all, Which type (Float or decimal) is best used to store prices in a database? Thx ...

Spring DataSourceInitializer splits trigger ins sql by ; delimiter

We use org.springframework.batch.test.DataSourceInitializer class in order to init DB on basis of .sql scripts. Init was failed,after trigger had been added to .sql. After debugging,the cause of error while was found here: try { scripts = StringUtils.delimitedListToStringArray(stripComments(IOUtils.readLines(scriptResource.getInputStr...

Transform SQL table to XML with column as parent node

Hi, I'm trying to transform a table to an XML struture and I want one of the columns in my table to represent a parent node and the other column to represent a child node. I have got part of the way but I don't have the complete solution. I need the TABLE_NAME column to transform to a xml parent node and the COLUMN_NAME column to trans...

Django getting executable raw sql for a QuerySet

I know that you can get the SQL of a given QuerySet using print query.query but as we know from a previous question ( http://stackoverflow.com/questions/2926483/potential-django-bug-in-queryset-query ) the returned SQL is not properly quoted. See http://code.djangoproject.com/browser/django/trunk/django/db/models/sql/query.py Is ther...

Data deduplificaton

The code below explains best what I'm trying to accomplish. I know that I can use a cursor or other looping routine to loop through the records to find the duplicates and create my notes records based on what is found. I'm trying to avoid that, unless there's no better option. DROP TABLE #orig DROP TABLE #parts DROP TABLE #part_notes ...

Construct Query with Linq rather than SQL strings

I've got a 2.0 server control that uses a dynamic query roughly in the form: string sql = "Select " + columnvariable + " FROM " + tablenamevariable So, obviously, you could give it any valid column name from any valid table in the DB and it would return the values in the column into a DataReader (in this case). I'm trying to cut down...

Add a null value to a Varchar Value..

Hi, I have 2 columns with "name" and "surname" I want to return a result with the two concatenated. but I have a problem, the surname column accept null values and when it's the case the concatenation is null.. I would like in this case just to have the NAME here is code: SELECT c.ID_CONT, c.ID_TYPE_CONTACT, c.ID_PARAM_CE...

What does a caret (^) do in a SQL query?

What is the caret (^) doing in the following SQL Server query? SELECT 1^2, 1^3; which gives the results: 3 2 I came across this before I found the SQUARE() function. ...

Help me work out how to build my SQL for this JOIN scenario

I'm still trying to learn SQL as of this writing, so I'm a bit shakey at the moment. My situation is like this: I have a table called 'Tasks' with an auto-incrementing primary key ID and a text field (and a few others that aren't relevant to this problem, too). I have another table called 'Locations' with a foreign key referring to a ...

Getting the maximum value of records

Hello All, I am having a table called Withdrawals which has : Name, year, period, amount. EX: Name Year Period Amount -------------------------------- Jim 2010 1 100 Jim 2009 4 99 Jim 2009 3 17 Kim 2007 2 234 Ryu 2008 5 555 I was stuck that I can't get the...

How to create a new column in a select query

In MS Access, I want to insert a new column into the returned result of a select query. The new column has the same value for every row. For example, my select returns columns A, B and I want C to be the new column created by the select query: A B C ---------- a1 b1 c a2 b2 c a3 b3 c ...