sql

Unique vs distinct multi-column in Oracle 9i

Hi, I am a bit confused about the uses of these words. I have a table with he following columns: SITE, LAT, LONG, NAME, ...... I want results with unique (or is it distinct) LAT, LONG. How do I achieve this? ...

SQL Server: Is it possible to insert into two tables at the same time?

My database contains three tables called Object_Table, Data_Table and Link_Table. The link table just contains two columns, the identity of an object record and an identity of a data record. I want to copy the data from DATA_TABLE where it is linked to one given object identity and insert corresponding records into Data_Table and Link_T...

Webserver to combine xml files?

I have a program I've written in VB.NET 2005, it saves statistics in an xml file. I use this program on multiple computers. I'd like to set up a webserver where I can upload my xml file, or just the data, and add it to the server ignoring duplicate entries already on the server. What do I need for to learn for this? SQL? Any ideas w...

How do you version your database schema?

How do you prepare your SQL deltas? do you manually save each schema-changing SQL to a delta folder, or do you have some kind of an automated diffing process? I am interested in conventions for versioning database schema along with the source code. Perhaps a pre-commit hook that diffs the schema? Also, what options for diffing deltas e...

How can I create a MySQL JOIN query for only selecting the rows in one table where a certain number of references to that row exist in another table?

I have two tables in my database, called ratings and movies. Ratings: | id | movie_id | rating | Movies: | id | title | A typical movie record might be like this: | 4 | Cloverfield (2008) | and there may be several rating records for Cloverfield, like this: | 21 | 4 | 3 | (rating number 21, on movie number 4, givin...

Import Text File into generic Database using SQL

Hi, I am currently trying to import a semi-colon delimited text file into a database in c# using OleDb where I don't know the type (SQL Server, Access, Oracle, MySQL, postgreSQL, etc.) Currently I'm reading in the file as a database using the Jet text reader then creating a prepared insert statement, populating the fields, then commiti...

Dynamic SELECT TOP @var In SQL Server

How can I have a dynamic variable setting the amount of rows to return in SQL Server? Below is not valid syntax in SQL Server 2005+: DECLARE @count int SET @count = 20 SELECT TOP @count * FROM SomeTable ...

What's the best way to pass a "row of data" from one C# console app to another C# console app?

I have a C# console app "App1" that reads a row of data from a table in a SQL Server 2005 DB. I want App1 to pass all the data in this row to App2, another C# console app. What is the best way to do this? My first (naive) attempt was to do this: object[] o = myrow.ItemArray; // make a string that separates each item by a space... for...

Setting Format for Query Defined Field

I have the following query in iSeries SQL which I output to a file. SELECT SSLOTMAK, SSLOTMDL, SSLOTYER, sum(SSCOUNT) FROM prqhdrss GROUP BY SSLOTMAK, SSLOTMDL, SSLotyer HAVING sum(SSCOUNT) > 4 ORDER BY SSLOTMAK, SSLOTMDL, SSLOTYER When I run it, the field created be the sum(SSCOUNT) is a 31 Packed f...

How to get records after a certain time using SQL datetime field

If I have a datetime field, how do I get just records created later than a certain time, ignoring the date altogether? It's a logging table, it tells when people are connecting and doing something in our application. I want to find out how often people are on later than 5pm. (Sorry - it is SQL Server. But this could be useful for o...

select top 10 records for each category.

I want to return top 10 records from each section in the one query. Can anyone help how to do it. Section is one of the column in the table. Database is sql server 2005. Top 10 by date entered. Sections are business, local and feature For one particular date I want only top(10) business rows (most recent entry), top (10 ) local rows and...

Is there a practical limit to the size of bit masks?

There's a common way to store multiple values in one variable, by using a bitmask. For example, if a user has read, write and execute privileges on an item, that can be converted to a single number by saying read = 4 (2^2), write = 2 (2^1), execute = 1 (2^0) and then add them together to get 7. I use this technique in several web applic...

How to use a function-based index on a column that contains NULLs in Oracle 10+?

Lets just say you have a table in Oracle: CREATE TABLE person ( id NUMBER PRIMARY KEY, given_names VARCHAR2(50), surname VARCHAR2(50) ); with these function-based indices: CREATE INDEX idx_person_upper_given_names ON person (UPPER(given_names)); CREATE INDEX idx_person_upper_last_name ON person (UPPER(last_name)); Now, given_...

SQL Absolute value across columns

I have a table that looks something like this: word big expensive smart fast dog 9 -10 -20 4 professor 2 4 40 -7 ferrari 7 50 0 48 alaska 10 0 1 0 gnat -3 0 0 0 The + and - values are associated with the...

how to read the last row with SQL Server

What is the most efficient way to read the last row with SQL? The table is indexed on a unique key--the "bottom" key values represent the last row. Edit: This is for SQL Server. Thank you rp ...

How to show SQL server 2000 server roles through an SQL query

what sql query will i need to show the activated server roles in a specific user? ...

Why recordsets initially were forward only

I have seen recent updates in term of record sets being updated so that we can scroll back and forth through the data it points to. My question is why they were initially designed for a forward only traversal. Is there any impact using the new version? ...

Should web applications use explicit SQL transactions?

Consider a regular web application doing mostly form-based CRUD operations over SQL database. Should there be explicit transaction management in such web application? Or should it simply use autocommit mode? And if doing transactions, is "transaction per request" sufficient? ...

What is the best way to convert an int or null to boolean value in an SQL query?

What is the best way to convert an int or null to boolean value in an SQL query, such that: Any non-null value is TRUE in the results Any null value is FALSE in the results ...

Is there a way to get DateTime value from timestamp type column. MS SQL 2005

I need a select from table which does not have column that tells when row was inserted, only timestamp column (values like: 0x0000000000530278). Some data was imported to the table yesterday and now I need to find out what exactly was imported :( Is there a way to do it using only timestamp info? Here I found that: Timestamp is a 8 by...