sql

Fuzzy match two hash tables?

Hi, I'm looking for ideas on how to best match two hash tables containing string key/value pairs. Here's the actual problem I'm facing: I have structured data coming in which is imported into the database. I need to UPDATE records which are already in the DB, however, it's possible that ANY value in the source can change, therefore I d...

Sql Querying, group relationships

Hi, Suppose I have two tables: Group ( id integer primary key, someData1 text, someData2 text ) GroupMember ( id integer primary key, group_id foreign key to Group.id, someData text ) I'm aware that my SQL syntax is not correct :) Hopefully is clear enough. My problem is this: I want to load a group record...

Query returning an ascending group number

I have a query like below that has groups (COL1) and that group's values (COL2). select col1, col2 from (select 'A' col1, 1 col2 from dual union all select 'A' col1, 2 col2 from dual union all select 'B' col1, 1 col2 from dual union all select 'B' col1, 2 col2 from dual union all select 'C' col1,...

Insert Data from to a table

I have a table that lists number of comments from a particular site like the following: Date Site Comments Total --------------------------------------------------------------- 2010-04-01 00:00:00.000 1 5 5 2010-04-01 00:00:00.000 2 8 ...

Database Designer for Visual Studio?

I am working on a database project and the entire team is working within Visual Studio. I created a database project, and I suppose I was hoping that I could utilize UML diagramming (or something along the lines of MySQL Workbench) so that I could "design" my database, and then auto-generate scripts. Unfortunately, at least from my cur...

SSIS 2005 - How to Import a Fixed Width Flat File?

I have a flat file that looks something like this: junk I don't care about \n \n columns names\n val1 val2 val3\n val1 val2 val3\n columns names \n val1 val2 val3\n I only care the lines with values. These value lines are all fixed width format and have the same line length. The other junk lines and column names c...

Trying to use VB to automate some queries. Running into what looks like a string problem

Hi there I'm using MS Access 2003 and I'm trying to execute a few queries at once using VB. When I write out the query in SQL it works fine, but when I try to do it in VB it asks me to "Enter Parameter Value" for DEPA, then DND (which are the first few letters of a two strings I have). Here's the code: Option Compare Database Public S...

What is the Microsoft Query Syntax for Subqueries?

I am trying to do a simple subquery join in Microsoft Query, but I cannot figure out the syntax. I also cannot find any documentation for the syntax. How would I write the following query in Microsoft Query? SELECT * FROM ( SELECT Col1, Col2 FROM `C:\Book1.xlsx`.`Sheet1$` ) AS a JOIN ( SELECT Col1, Col3 FROM `C:\Book1.x...

Left Join on Associative Table

I have three tables Prospect -- holds prospect information id name projectID Sample data for Prospect id | name | projectID 1 | p1 | 1 2 | p2 | 1 3 | p3 | 1 4 | p4 | 2 5 | p5 | 2 6 | p6 | 2 Conjoint -- holds conjoint information id title projectID Sample data id | title | projectID 1 | color | 1 2...

Converting output of sql query

Hi, Let say I have table Payments Id int autoincement Status int and my query is : select id, status from payments but I wanna convert status to enum. 0 is unpaid 1 is paid. so result should look like: 1 paid 2 unpaid 3 paid ... I need this conversion because I use XmlReader reader = cmd.ExecuteXmlReader(); oc.LoadXml("<r...

SQL Server / T-SQL : How to update equal percentages of a resultset?

I need a way to take a resultset of KeyIDs and divide it up as equally as possible and update records differently for each division based on the KeyIDs. In other words, there is SELECT KeyID FROM TableA WHERE (some criteria exists) I want to update TableA 3 different ways by 3 equal portions of KeyIDs. UPDATE TableA SET FieldA...

MySQL: Question about SELECT WHERE AND/OR

I'm trying to write a query that returns the same result from three different events, but I think I am doing it wrong. I can run my query against one event ID and it works. How can I select all three? Here's what I have so far: SELECT * FROM `Registrations` WHERE `Role` = "Attendee" AND `RegistrationStatus_ID` = "1" AND `DigSignature` ...

data type mismatch when comparing dates in MS-Access

I have dates stored in an MS-Access table in the 'General Date' format. I'm trying to create a query that returns records between a specific date range (all records from March 2010) however I encounter a 'data type mismatch in critera expression' message. Here is my statement; SELECT Loan.loan_datetimeLeant, product_name, [prod...

LINQ Normalizing data

I am using an OMS that stores up to three line items per record in the database. Below is an example of an order containing five line items. Order Header Order Detail Prod 1 Prod 2 Prod 3 Order Detail Prod 4 Prod 5 One order header record and two detail records. My goal is have a one to one relation for details records(...

Hibernate custom join clause on association

I would like to associate 2 entities using hibernate annotations with a custom join clause. The clause is on the usual FK/PK equality, but also where the FK is null. In SQL this would be something like: join b on a.id = b.a_id or b.a_id is null From what I have read I should use the @WhereJoinTable annotation on the owner entity, but ...

How to select 'previous' and 'next' records in SQL?

I am building a blog-post detail page on my site that will display display a 'previous' and 'next' link similar to how a typepad blog post works. See example below. I am wondering if there is a way to query the database which accomplishes something like the image below where it selects the 'current' record (in yellow) for display, but ...

Are there any good .Net libraries for building arbitrary sql commands? Not relational data.

I am looking for some library that takes the TextWriter approach to writing SQL commands (much like there is the HtmlTextWriter in .Net for writing html). I am NOT writing CRUD-type commands for relational data, I am writing arbitrary SQL (bulk inserts, table creation, creating backups, etc). Any suggestions are appreciated. ...

How to write this query in Linq2Sql

I have a table company which holds the company_id, company_name and other details. I have a table subcontracts which has a company_id column that maps to company.company_id. How can I write a select statement to get all active companies which have not been assigned to an active subcontract? IE The company_id cannot be found in subcont...

Can I improve performance by refactoring SQL commands into C# classes?

Currently, my entire website does updating from SQL parameterized queries. It works, we've had no problems with it, but it can occasionally be very slow. I was wondering if it makes sense to refactor some of these SQL commands into classes so that we would not have to hit the database so often. I understand hitting the database is gen...

Hibernate duplicate primary key on restart using GenerationType.TABLE

We're running into an issue where we have Event subclasses that use GenerationType.TABLE to generate the primary key, and when we restart the servers we are getting duplicate primary key errors. We're using SQL Server and Hibernate version 3.5.1-Final. Here's what our Hibernate annotations look like: @Entity @Inheritance(strategy = In...