sql

How do I compare two glob values in Oracle

I have two tables I would like to complare. One of the columns is type glob. I would like to do something like this: select key, glob_value source_table minus select key, glob_value target_table Unfortunately, Oracle can't perform minus operations on globs. How can I do this? ...

Query a Table's Foreign Key relationships

For a given table 'foo', I need a query to generate a set of tables that have foreign keys that point to foo. I'm using Oracle 10G. ...

How do I enforce data integrity rules in my database?

I'm designing this collection of classes and abstract (MustInherit) classes… This is the database table where I'm going to store all this… As far as the Microsoft SQL Server database knows, those are all nullable ("Allow Nulls") columns. But really, that depends on the class stored there: LinkNode, HtmlPageNode, or CodePageNode. ...

Converting SQL Result Sets to XML.

I am looking for a tool that can serialize and/or transform SQL Result Sets into XML. Getting dumbed down XML generation from SQL result sets is simple and trivial, but that's not what I need. The solution has to be database neutral, and accepts only regular SQL query results (no db xml support used). A particular challenge of this tool...

How do you transfer or export SQL Server 2005 data to Excel.

I have a simple SQL 'Select' query, and I'd like to dump the results into an Excel file. I'm only able to save as .csv and converting to .xls creates some super ugly output. In any case, as far as I can tell (using Google) this doesn't seem to be so straight forward. Any help would be greatly appreciated. ...

When do transactions become more of a burden than a benefit?

Transactional programming is, in this day and age, a staple in modern development. Concurrency and fault-tolerance are critical to an applications longevity and, rightly so, transactional logic has become easy to implement. As applications grow though, it seems that transactional code tends to become more and more burdensome on the scala...

SQL: IF clause within WHERE clause

Is it possible to use an IF clause within a WHERE clause in MS SQL? Example: WHERE IF IsNumeric(@OrderNumber) = 1 OrderNumber = @OrderNumber ELSE OrderNumber LIKE '%' + @OrderNumber + '%' ...

Building a Table Dependency Graph With A Recurssive Query

I am trying to build a dependency graph of tables based on the foreign keys between them. This graph needs to start with an arbitrary table name as its root. I could, given a table name look up the tables that reference it using the all_constraints view, then look up the tables that reference them, and so on, but this would be horrible...

Sql Server 2005 error handling - inner exception

In C# you can get the original error and trace the execution path (stack trace) using the inner exception that is passed up. I would like to know how this can be achieved using the error handling try/catch in sql server 2005 when an error occurs in a stored procedure nested 2 or 3 levels deep. I am hoping that functions like ERROR_ME...

Stored Procs - Best way to pass messages back to user application

I'd like know what people think about using RAISERROR in stored procedures to pass back user messages (i.e. business related messages, not error messages) to the application. Some of the senior developers in my firm have been using this method and catching the SqlException in our C# code to pick up the messages and display them to the...

Disable (Politely) a website when the sql server is offline

I work at a college and have been developing an ASP.NET site with many, many reports about students, attendance stats... The basis for the data is a ms sql server db which is the back end to our student management system. This has a regular maintenance period on thursday mornings for an unknow length of time (dependent on what has to be ...

Does LINQ-to-SQL Support Composable Queries?

Speaking as a non-C# savvy programmer, I'm curious as to the evaluation semantics of LINQ queries like the following: var people = from p in Person where p.age < 18 select p var otherPeople = from p in people where p.firstName equals "Daniel" select p Assuming that Person ...

naming columns in excel with Complex sql

I’m trying to run this sql using get external .. it work but when I try to rename the subqurrys or anything for that matter it remove it. I tried as, as and the name in '', as then the name in "", and the same with space. what is the right way to do that? sql for completeness sake select list_name, app_name, (select f...

Hierachy recordset in ms access

How can I get hierachy recordset in ms access through select statement? ...

How to reference a custom field in SQL

I am using mssql and am having trouble using a subquery. The real query is quite complicated, but it has the same structure as this: select customerName, customerId, ( select count(*) from Purchases where Purchases.customerId=customerData.customerId ) as numberTransactions from customerData And what I want to d...

How do I access a database in C#

Basically, I would like a brief explanation of how I can access a SQL database in C# code. I gather that a connection and a command is required, but what's going on? I guess what I'm asking is for someone to de-mystify the process a bit. Thanks. For clarity, in my case I'm doing web apps, e-commerce stuff. It's all ASP.NET, C#, and SQL ...

SQL query to calculate coordinate proximity

I'm using this formula to calculate the distance between entries in my (My)SQL database which have latitude and longitude fields in decimal format: 6371 * ACOS(SIN(RADIANS( %lat1% )) * SIN(RADIANS( %lat2% )) + COS(RADIANS( %lat1% )) * COS(RADIANS( %lat2% )) * COS(RADIANS( %lon2% ) - RADIANS( %lon1% ))) Substituting %lat1% and %lat2% a...

How to calculate the sum of values in a tree using SQL

I need to sum points on each level earned by a tree of users. Level 1 is the sum of users' points of the users 1 level below the user. Level 2 is the Level 1 points of the users 2 levels below the user, etc... The calculation happens once a month on a non production server, no worries about performance. What would the SQL look like to ...

What is the best way to add users to multiple groups in a database?

In an application where users can belong to multiple groups, I'm currently storing their groups in a column called groups as a binary. Every four bytes is a 32 bit integer which is the GroupID. However, this means that to enumerate all the users in a group I have to programatically select all users, and manually find out if they contain ...

How can I delete duplicate rows in a table

I have a table with say 3 columns. There's no primary key so there can be duplicate rows. I need to just keep one and delete the others. Any idea how to do this is Sql Server? ...