sql

How to do select from where x is equal to multiple values?

So I', debugging some code and there is the following SQL query (simplified from what it really is). SELECT ads.*, location.county FROM ads LEFT JOIN location ON location.county = ads.county_id WHERE ads.published = 1 AND ads.type = 13 AND ads.county_id = 2 OR ads.county_id = 5 OR ads.county_id = 7 OR ads.county_id = 9 I'm getting v...

SSIS: DTS Package Editor fails with: Attempted to read or write protected memory

Hello All I'm trying to migrate some DTS packages from SQL Server 2000 to 2008 to see how much pain is involved. I've got the Standard version of SQL Server 2008 installed on my local machine. I downloaded the Microsoft SQL Server 2000 DTS Designer Components and Microsoft SQL Server 2005 Backward Compatibility Components from msdn ...

Upper limit for autoincrement primary key in SQL Server

What is the upper limit for an autoincrement primary key in SQL Server? What happens when an SQL Server autoincrement primary key reaches its upper limit? ...

How do I compress this Oracle resultset into values according to row priority, ignoring nulls?

I'll simplify the problem as much as possible: I have an oracle table: row_priority, col1, col2, col3 0, .1, 100, {null} 12, {null}, {null}, 3 24, .2, {null}, {null} Desired result: col1, col2, col3 .2, 100, 3 So according to the priority of the row, it overrides previous row values, if given. I'm attempting to work out a solutio...

What are "SQL-Hints"?

I am an advocate of ORM-solutions and from time to time I am giving a workshop about Hibernate. When talking about framework-generated SQL, people usually start talking about how they need to be able to use "hints", and this is supposedly not possible with ORM frameworks. Usually something like: "We tried Hibernate. It looked promising...

Obtain max length for a "string" column using LINQ To SQL

Is it possible to obtain the maximum column length for a VARCHAR, CHAR etc? ...

What happen in SQL 2005 when it run out of number for an autonumber column?

What happen when SQL Server 2005 happen to reach the maximum for an IDENTITY column? Does it start from the beginning and start refilling the gap? What is the behavior of SQL Server 2005 when it happen? ...

Are there disadvantages to using a generic varchar(255) for all text-based fields?

I have a contacts table which contains fields such as postcode, first name, last name, town, country, phone number etc, all of which are defined as VARCHAR(255) even though none of these fields will ever come close to having 255 characters. (If you're wondering, it's this way because Ruby on Rails migrations map String fields to VARCHAR...

oracle procedure returns integer

In oracle, I want to create a delete sproc that returns an integer based on the outcome of the deletion. this is what i have so far. create or replace PROCEDURE Testing ( iKey IN VARCHAR2 ) AS BEGIN delete from MyTable WHERE TheKey = iKey; END Testing; i've tried putting a RETURNS INTEGER in but the sproc won't compile. ...

Why is using '*' to build a view bad ?

Hello, Why is using '*' to build a view bad ? Suppose that you have a complex join and all fields may be used somewhere. Then you just have to chose fields needed. SELECT field1, field2 FROM aview WHERE ... The view "aview" could be SELECT table1.*, table2.* ... FROM table1 INNER JOIN table2 ... We have a problem if 2 fields have ...

Insert into temp values (select.... order by id)

I'm using an Informix (Version 7.32) DB. On one operation I create a temp table with the ID of a regular table and a serial column (so I would have all the IDs from the regular table numbered continuously). But I want to insert the info from the regular table ordered by ID something like: CREATE TEMP TABLE tempTable (id serial, folio ...

How to Structure Table to Model Mutually Exclusive 1:n Relationships?

In the following table structure: Fruits ( fruit_id, fruitName ) Vegetables ( vegetable_id, vegetableName ) favoriteFoods ( food_id, foodName, type_id (References either a fruit or a vegetable) ) I realize that I could forgo using a foreign key constraint on the favoriteFoods table and then simply a...

SQL Compare GUI works, but command line gives problems

I recently purchased SQL compare 7.1 pro for the command line capabilities. We have been using the GUI version with no problems for some time now. I am trying to exclude items from the sync, however its not working. I am using the .scp file created from the GUI. My syntax is: SQLCompare.exe /pr:"file.scp" /v sync >> Log.txt. I have trie...

Sql Server Dynamic Queries

Hi, I have a very simple question. I have 15 stored procedures that return data from a common table, then join that table with a specific table to retrieve inventory. Ex. Common: tblCommonSpecific: tblSpecific Is there i was i can pass the name "tblSpecific" into a single stored procedure as a variable, like this: SELECT .... FROM ...

COALESCE SUM GROUP?

Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name` FROM `orders`, `menu_items`, `order_items` WHERE `orders`.`id` = `order_items`.`order_id` AND `menu_items`.`id` = `order_items`.`menu_item_id` AND `orders`.`date` >= '2008-11-01' AND ...

Generating SQL Schema from XML

We are using an Oracle 11 database and a java development environment (using Eclipse) and would like to migrate several xml schemas to SQL schemas. Have looked ax xsd but really need something that we can run from ant/ Eclipse without SQL Server installed. Regards, Andy ...

In SQL, how to delete a row from one table if it doesn't have a corresponding row in another table?

Hey, How can I make: DELETE FROM foo WHERE id=1 AND bar not contains id==1 To elaborate, how can I remove a row with id = 1, from table foo, only if there is not a row in table bar with id = 1. ...

Querying ManyToMany relationship with Hibernate Criteria

I'm not sure how to describe this problem, so I think an example is the best way to ask my question: I have two tables with a manyToMany relationship: DriversLicence <-> LicenceClass LicenceClass is things like "Car", "Motorbike", and "Medium Rigid". Using Hibernate Criteria, how can I find all licences that have both "Car" and "Moto...

How to use Single Quotes in Eval Format String

I've got a Repeater and its SqlDatasource nested inside a Gridview TemplatedField. The Repeater's datasource SelectCommand is set using the FormatString of an Eval from the Gridview. The SelectCommand has a WHERE clause which is to compare a string. Because I have already used the single and double quotes, I am having trouble delimiting ...

SQL Express 2005, Secure Database File

Hi, I have built an application that uses SQL Express 2005 and I want to deploy it, but the problem is that anyone who has SQL Management Studio(or something like that) installed on his computer, can connect to my database and change it. Is there anyway to prevent end-users from seeing or editing the content of my database, even those w...