sql

Remapping/Concatenating in SQL

I'm trying to reorder/group a set of results using SQL. I have a few fields (which for the example have been renamed to something a bit less specific), and each logical group of records has a field which remains constant - the address field. There are also fields which are present for each address, these are the same for every address. ...

Operator does not exist: interval > integer

A query working on Postgresql 7.4 but not on Postgresql 8.3 with same database. Query: SELECT * FROM login_session WHERE (now()-modified) > timeout; Get error ERROR: operator does not exist: interval > integer LINE 1: ...ELECT * FROM login_session WHERE (now()-modified) > timeout ... ...

Is Oracle really all THAT different from other SQL databases?

So many companies today want someone with Oracle experience. I have none, but it seems to me that it shouldn't be hard to figure out quickly. However, when potential employers ask me if I've worked with Oracle, the line "No, but I'm an expert with Microsoft SQL Server, Borland Interbase, PostgreSQL, and MySQL, and I have no doubt that I ...

Updating sort keys after delete

I have a table which has a field sort_id. In this field there are numbers from 1 to n, that define the order of the data sets. Now I want to delete some elements and afterwards I want to reorder the table. Therefore I need a query that "finds" the gaps and changes the sort_id field according to the modifications. Sure, I could do someth...

Differences between SQL and PL-SQL

Can somebody highlight the main differences between PL-SQL and SQL? And which one do you recommend for a newbie who wants to dive into DBA? ...

SQL Server 2000 "NO JOIN PREDICATE" warning - Why?

I've got a strange problem with SQL Server 2000, and I just can't think of a reason for this to happen. There are two tables, both having a combined primary key with a clustered index on it, both keys have the same structure: (VARCHAR(11), INT, DATETIME) /* can't change this, so don't suggest I should */ So, joining them like this ...

In SQL, can I use a variable scoped outside a nested select within the nested select itself?

I'm trying to get the following SQL statement to work: UPDATE myschema.tableA update_tableA SET field_id = ( SELECT src.field_id FROM myschema.srcTable src INNER JOIN myschema.tableB tableB ON update_tableA.id = tableB.id AND SDO_ANYINTERACT( tableB.shape, src.shape ) = 'TRUE' ); Whe...

Sql Server Query Selecting Top and grouping by

SpousesTable SpouseID SpousePreviousAddressesTable PreviousAddressID, SpouseID, FromDate, AddressTypeID What I have now is updating the most recent for the whole table and assigning the most recent regardless of SpouseID the AddressTypeID = 1 I want to assign the most recent SpousePreviousAddress.AddressTypeID = 1 for each unique Spou...

Query to list SQL Server stored procedures along with lines of code for each procedure

I want a query that returns a list of all the (user) stored procedures in a database by name, with the number of lines of code for each one. i.e. sp_name lines_of_code -------- ------------- DoStuff1 120 DoStuff2 50 DoStuff3 30 Any ideas how to do this? ...

MySQL inserting data only if table doesn't exist

Using strictly SQL (no PHP or anything else), is it possible to create a table and insert default data into that table only if that table doesn't exist? ...

Is there a good reason to use upper case for T-SQL keywords?

The default seems to be upper case but is there really any reason to use upper case for keywords? I started using upper case because I was just trying to match what SQL Server gives me whenever I tried to create something, like a new stored procedure. But then, I feel terrible for my baby (5th) finger that always needs to hold down the S...

Resources for Database Sharding and Partitioning

I'm working with a database schema that is running into scalability issues. One of the tables in the schema has grown to around 10 million rows, and I am exploring sharding and partitioning options to allow this schema to scale to much larger datasets (say, 1 billion to 100 billion rows). Our application must also be deployable onto se...

LINQ to SQL Designer Bug

Every time that I change a value in the designer after saving it, the .designer.cs file will be deleted. Can anyone tell me how can I fix this problem? ...

SQL - How to make a conditional INSERT

Using only MySQL, I'm seeing if it's possible run an insert statement ONLY if the table is new. I successfully created a user variable to see if the table exists. The problem is that you can't use "WHERE" along with an insert statement. Any ideas on how to get this working? // See if the "country" table exists -- saving the result to a ...

Signs of a great SQL developer

Based on their work, how do you distinguish a great SQL developer? Examples might include: Seldom uses CURSORs, and tries to refactor them away. Seldom uses temporary tables, and tries to refactor them away. Handles NULL values in OUTER JOINs with confidence. Avoids SQL extensions that are not widely implemented. Knows how to indent ...

Sproc Parameter Returning First Character Only

I've got a sproc and some C# calling it. My problem is that both the (N)VARCHAR values only have the first character returned. Everything else is fine. Why would only the 1st character be returned? So Content = (string)cmd.Parameters["@SmsContent"].Value, ToNumber = (string) cmd.Parameters["@ToNumber"].Value, both only get the 1st ch...

AX / Axapta: Retrive Custom fields via SQL

I'm creating a rather "dirty" business connector of my own here, and I'm having trouble finding those "custom fields" that have been created. They show up in AX - but in the SQL-database, they are not mentioned at all... I have a hunch that all custom fields are stored somewhere else in the database, so that the original state of the t...

Creating safe SQL statements as strings

I'm using C# and .NET 3.5. I need to generate and store some T-SQL insert statements which will be executed later on a remote server. For example, I have an array of Employees: new Employee[] { new Employee { ID = 5, Name = "Frank Grimes" }, new Employee { ID = 6, Name = "Tim O'Reilly" } } and I need to end up with an array of ...

How do I find trustworthy database help out on the interweb?

I am trying to help a small business that has an application that could benefit from occasional (or temporary) database expertise. The problem is, this company has all their IP in this database, so they are rightfully hesitant to give someone access it. They would typically meet and gain trust in person, but the talent pool within ph...

If I'm posting a question about Oracle SQL query performance, what should I include in my question?

If I am posting a question about a query against an Oracle database, what should I include in my question so that people have a chance to answer me? How should I get this information? Simply providing the poorly performing query may not be enough. ...