sql

Information related to Node in a Database Structure for Tree Data Structure

Hello, Imagine you have a tree data Structure in a database like this: Level: id nextlevel desc 1 2 company 2 3 department 3 4 group Nodes: id level parentnode 0 1 null -> the company 1 2 0 -> dep 1 2 2 0 -> ...

How to output only one max value from this query in SQL?

Yesterday Thomas helped me a lot by providing exactly the query I wanted. And now I need a variant of it, and hopes someone can help me out. I want it to output only one row, namely a max value - but it has to build on the algorithm in the following query: WITH Calendar AS (SELECT CAST(@StartDate AS datetime) AS Date ...

Migration tool from TSQL to PL/SQL?

We need to migrate our database from MSSQL to Oracle and we have over 100 stored procedures written in PL/SQL TSQL. I know its a long shot, but has anybody ever successfully used an automatic migration tool to do the work? I've seen some tools on the web, but I have no way to judge their ability to handle various code. Any personal exper...

How to keep track of column updates?

I'm using SQL Server to store users uploaded songs. Each song has an id(simple auto increment number) and a name. I want to use URL Rewriting to query some song, like this: http://wwww.mysite.com/song/song_name The problem is that I also want to enable users to change their songs name and still use the old URL. I thought o...

Suspect someone is deleting records from my SQL Server '05 DB - any way to check?

Hey all, I think someone with shared access to my SQL Server '05 DB is deleting records from a table in a DB for their own reasons. Is there any audit table I can check to see manual delete queries which may have been run on the DB in the last X number of days? Thanks for your help. Ed ...

oracle select if there is no entry in second table

I've two tables where I like to select from the second table where it has a foreign key to first table. The conditions are: (1). The qty field of second table must have a value greater than 0 Or (2). First table record doesn't have a corresponding entry in the second table. ...

Limiting Number of Rows Inserted into a SQL Server Database

I have a program in c# in VS that runs a mainform. That mainform exports data to an SQL Database with stored procedures into tables. The data exported is a lot of data (600,000 + rows). I have a problem tho. On my mainform I need to have a "database write out interval". This is a number of how many "rows" will be imported into the da...

Parent/Child tables not referencing in LINQ or am I just wrong?

I have a categories table "Category" [ID, Title] and a Parent/Child table "CategoryParent" [ID,CategoryID,ParentCategoryID] where a many-to-many tree is represented by the parent of a category being indicated using the ParentCategoryID field in the join table. I thought this would be a simple structure to use to retrieve root categories...

How to provide SQL initial data when app label is used?

From the documentation: Django provides a hook for passing the database arbitrary SQL that's executed just after the CREATE TABLE statements when you run syncdb. You can use this hook to populate default records, or you could also create SQL functions, views, triggers, etc. The hook is simple: Django just looks for a file called...

Date Comparing Solutions

Using C# & MySQL Table1 ID Date1 Date2 001 04/05/2010 05/06/2010 002 04/06/2010 07/08/2010 ...., to Date2 Datatype is Varchar, Format: mm/dd/yyyy The Date always compare with system date, when the date is going to expire, it will show the message for i 1 week like this.. 7 days to expire 6 day to expire 5 day to expire ... ... 1...

Inner join with count() on three tables

Simple and fast question, i have those tables: //table people | pe_id | pe_name | | 1 | Foo | | 2 | Bar | //orders table | ord_id | pe_id | ord_title | | 1 | 1 | First order | | 2 | 2 | Order two | | 3 | 2 | Third order | //items table | item_id | ord_id | pe_id | title | | 1 | 1 | 1 | ...

How to fetch categories and sub-categories in a single query in sql? (mysql)

Hi, I would like to know if it's possible to extract the categories and sub-categories in a single DB fetch. My DB table is something similar to that shown below table cat_id parent_id 1 0 2 1 3 2 4 3 5 3 6 1 i.e. when the input is 3, then all the rows with parent_id as 3 AND the row 3 itself AND all t...

Finding similar names in multiple tables

I have multiple tables with different customer names. I am trying to find out how many times the same name is in a table. The challenge here is that someone could have entered the name as "John Smith" or "Smith, John". There are 40,000 rows in each table and over 40 different tables. I am trying to query somehow without knowing the name...

SQL: CASE and selecting multiple COLUMS

Hi Guys, How can I do this: Based on the select Case below I want to show TWO separate columns within one WHEN? The two lines below which are commented is what something I would like to have and I am sure it is something very simple I am missing....however i get syntax error select person.FirstName, person.LastName, CASE ...

How to get 0 value when count(*) returns null on multiply values

I have a table that contains error codes and entry times (among other things). What I need is a way to count the amount of lines with the same error code (that I choose) for the last hour, and to string the result the error code. SELECT COUNT(*) || ',' || error_code as amount_and_code FROM my_table WHERE error_code in (5001, 5002, 5003,...

Saving ArrayList in SQLite database in Android

Hello all, I've been working with SQLite on android and I would like to add an arraylist to a column in a table, and then fetch the data back as an arraylist. The arraylist is a list of Longs. I've noticed that SQL has an option for storing BLOBS, however it looks like I need to convert the arraylist to a byte[] first before being able ...

Is "LIKE ?" More efficient than LIKE '%'||?||'%'

Recently one of my colleagues made a comment that I should not use LIKE '%'||?||'%' rather use LIKE ? in the SQL and then replace the LIKE ? marker with LIKE '%'||?||'%' before I execute the SQL. He made the point that with a single parameter marker DB2 database will cache the statement always and thus cut down on the SQL ...

how to convert csv to table in oracle

How can I make a package that returns results in table format when passed in csv values. select * from table(schema.mypackage.myfunction('one, two, three')) should return one two three I tried something from ask tom but that only works with sql types. I am using oracle 11g. Is there something built-in? ...

SQL insert field, with value of other auto increment field + value

Hi. It might sound complicated, but it's not. I have a table called "orders", with fields: id INT(11) auto_increment, realid INT(14) Now, I want at every insert into this table, do something like: INSERT INTO orders VALUES (null, id+1000); However I'll be doing it on shop which is currently online, and I want to change everything ...

SQL Server 2005 bigint missing?

I am trying to set a column as a 64-bit integer, but my only available options are tinyint, smallint and int. Where did bigint run off to? Notes: I'm using Access 2008 to access my SQL Server. ...