sql

SQL Databases in vb.net

If you are using an sql database with a vb.net application, does the user need to have anything extra other than the .net framework installed for the program to run? Meaning, if I simply compile the application, are there any extra steps I need to take to make this work? Thanks for the help! ...

SQL statement with datetimepicker

This should hopefully be a simple one. When using a date time picker in a windows form, I want an SQL statement to be carried out, like so: string sql = "SELECT * FROM Jobs WHERE JobDate = '" + dtpJobDate.Text + "'"; Unfortunately, this doesn't actually provide any results because the JobDate field is stored as a DateTime value. I'd l...

Set Variable Values

I'm sure this is something simple, but I can't seem to figure it out. Why doesn't this code work? DECLARE @FirstSaturday DATETIME DECLARE @ENDDATE DATETIME SELECT @FirstSaturday = min(RED1.DATE) FROM REDFRIDAYDATES..TBLREDFRIDAYALLDATES RED1 WHERE Period = 9 AND year = 2009 SELECT CASE WHEN getdate() < @FirstSaturday THEN set @ENDD...

Merging data between databases

Suppose I have two distinct databases with identical schemas but different data. I want to merge the data between the two databases by adding the data from one into the other. Foreign key relationships, etc. need to be maintained when the data is migrated. Are there any tools (or databases that have built-in tools) to make this job fair...

How to store user profile edits that must be approved before going live?

Hi, I'm trying to figure out how I should save an edit a user makes to their profile in a way that doesn't go live or affect the existing live data until it's approved by an admin. Have a second table for edited profiles then copy over the data on approval? Keep it all in one table and have a _tmp copy of all the fields that are editabl...

How to sort by count with postgresql?

I have two tables: Companies: (id, name, city) Workers: (id, name) I would like to get all companies and sort them by numbers of employes. The result should give: count | company id | company name | city ------------------------------------------ 90 6 foo corp NY 45 9 bar corp LA 0 ...

C#/SQL get autoincremented field value

I have a table with autoincremented primary key. In my code I am trying to receive the new autoincremented value when I execute each 'insert' query. Is there a way to do it programatically? Thanks. UPD: Assume I have a table: TABLE User ( userID INT NOT NULL AUTO_INCREMENT, name VARCHAR( 25 ) NOT NULL , email VARCHAR( 50 ) NOT NULL , U...

SQL Server: How to change name in a view?

I am using Visual Studio 2008 and SQL Server 2008 Express. How can I change the name of the view? I can change tables' names, but I can't change the view name. Any suggestion? Thank you, Fabio Milheiro ...

Joining to a limited subquery?

I have this releases table in a SQLite3 database, listing each released version of an application: |release_id|release_date|app_id| |==========|============|======| | 1001| 2009-01-01 | 1| | 1003| 2009-01-01 | 1| | 1004| 2009-02-02 | 2| | 1005| 2009-01-15 | 1| So for each app_id, there will be multi...

TSQL inter-table updates

I have two tables, a contacts table and an addresses table. The addresses table contains a contact id, and 4 address lines. I wish to update the contacts table with the information from the addresses table. For simplicity's sake let the tables be as follows: addresses( . contact int not null, . address1 varchar(32) not null, . address2 ...

Migrating MySQL to a table with different structure

Hi all, My company's currently moving our databases around, shifting one set of tables out from the old MySQL instance into the new. We've done some development prior to this migration, and some tables' structure has been altered from the original (eg. columns were dropped). So currently I've dumped the data from the old database and ...

MySQL Alias Question

i am wondering why this fails mysql> SELECT Continent C, Name, SurfaceArea -> FROM Country -> WHERE SurfaceArea = ( -> SELECT MAX(SurfaceArea) -> FROM Country -> WHERE Continent = C); ERROR 1054 (42S22): Unknown column 'C' in 'where clause' its a answer provided by the certification guide for some sample exercises....

sql complex group query

I have a table with the following rows: id. type - link 1. image - http://1 2. image - http://2 3. text - none 4. video - http://.. 5. image - http://.. 6. text - http://.. I want to group the type (image) by date, so they show as single row. In this example, the first two images will merge together and output will be like...

How to sort by custom count with postgresql?

I have two tables: Companies: (id, name) Workers: (id, name, country) I would like to get all companies and sort them by numbers of employees from a given country. For a query looking for companies that have more workers from the USA, the result should give: #workers from USA | company id | company name ----------------------------...

Optimize right joins

The following query is working as expected. But I guess there is enough room for optimization. Any help? SELECT a.cond_providentid, b.flag1 FROM c_master a WHERE a.cond_status = 'OnService' ORDER BY a.cond_providentid, a.rto_number; ...

Preserving data integrity in Drupal:

I've happened to develop a module in Drupal and due to some seeming View limitations had to use custom SQL. This ran me into some problems with node revisions and I came to conclusion that in Drupal it's best to use its native methods for working with any data. Otherwise, data integrity problems may arise. And even with desire to optim...

SQL Convert to GMT DateTime

Hi there, i wan't to convert my records entries from dateTtime+OFFSET to dateTtimeZ directly (2008-05-11T15:30:00+2--->2008-05-11T13:30:00Z) with sql functions. Don't know how to do this :-( I need to implement this using MySql prefering not using stored procs Thx ...

SQL Max(something,0) type solution

Hi I would like to do the following: SELECT sum(max(field-10,000,0)) from TABLE as in, I want to have field-10,000 summed up, but if field-10,000 < 0 then I want it to add 0. any suggestions? Karl ...

SQL Collation conflict when comparing to a constant

I have a SQL query that compares a value in the database to a constant: SELECT * FROM my_table INNER JOIN #TempTable tem ON my_table.id = temp.id AND my_table.key = 'SOME STRING' And I get the error: Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AS" in the equal to operati...

SQL - Identifying source table from UNION query

Hi, I'm building an RSS feed in PHP which uses data from three separate tables. The tables all refer to pages within different areas of the site. The problem I have is trying to create the link fields within the XML. Without knowing which table each record has come from, I cannot create the correct link to it. Is there a way to solve...