sql

Normalizing Data on a Table

I need help to transform data on a table, reducing a series of columns to one single column. An example follows below: Frequency_1 integer, Frequency_2 integer, Frequency_3 integer, Frequency_4 integer, These columns currently hold 1 or 0. Only one column will hold 1. The new column should be defined as Frequency integer And this ...

How do I cast a string to integer and have 0 in case of error in the cast with PostgreSQL?

In postgres I have a table with a varchar column. The data is supposed to be integers and I need it in iteger type in a query. Some values are empty strings. The following: SELECT myfield::integer FROM mytable yields ERROR: invalid input syntax for integer: "" How can I query a cast and have 0 in case of error during the cast in pos...

Advantages to Vertical Partitioning of Table

(Note that this situation isn't exactly how it is, but I made this as an example) I have an entity in a table with data that is updated every 5 seconds (Kinematic Data: Speed, Heading, Lat, Long, and PositionTime), and other data that is updated hardly at all, if ever (Color, Make, OriginTime). Now my boss wants me to partition this ...

Mysql query : If value(s) exist(s) in column, select just the value(s), else select all

Having a Mysql database, I have to select all ( TUser.Name, TAccount.Name ) pairs if TUser.name not exists in variable @UserNames. If exists, I have to select only the ( TUser.Name, TAccount.Name ) pairs where TUser.name in @UserNames. Something like the last line of the below query : DECLARE @UserNames = "Alpha, Beta, Gama"; SELECT...

How-To delete 8,500,000 Records from one table on sql server

Hi there, delete activities where unt_uid is null would be the fastest way but nobody can access the database / table until this statement has finished so this is a no-go. I defined a cursor to get this task done during working time but anyway the impact to productivity is to big. So how to delete these record so that the normal use...

Output one field of one record from a SQL database in ASP.NET.

I need to read one record from a database (determined by the url's querystring), and take one field from it ("Cost"). The SQL currently in my datasource for it is just: SELECT [Cost] from [Cars] WHERE ([RegistrationNumber] = @RegistrationNumber) ...then @RegistrationNumber is defined as coming from the QueryString. I'm very much stil...

Update multiple columns in SQL with bound multi-part identifier

I'm trying to update multiple columns in a MS SQL statement using a sub-query. A search led me to something like: UPDATE table1 SET col1 = a.col1, col2 = a.col2, col3 = a.col3 FROM (SELECT col1, col2, col3 from table2 where <expression>) AS a WHERE table1.col1 <expression> http://geekswithblogs.net/phoenix/archive/2009/10/13/update-mu...

Pivot SQL Statement

I have a table like this (of course there are many more values but you get the idea): ID Name --- ---- 1 A 1 B 2 C 3 D 4 A 4 D 4 E 4 F 4 G 4 H I want to write a query that would output this, given that an ID cannot have more than 6 names. ID Name1 Name2 ...

LINQ To SQL: Getting primary key id number from Table WITHOUT making a second trip?

hello, how would i get the primary key id number from a Table WITHOUT making a second trip to the database in LINQ To SQL? right now, i submit the data to a table, and make another trip to figure out what id was assigned to the new field (in an auto increment id field). also, seond part of my question is: i am always careful to know th...

How to create view that combine multiple row from 2 tables?

I want to create view that combine data from two tables, sample data in each table is like below. SELECT Command for TableA SELECT [ID], [Date], [SUM] FROM TableA Result ID | Date | SUM 1 | 1/1/2010 | 2 1 | 1/2/2010 | 4 3 | 1/3/2010 | 6 SELECT Command for TableB SELECT [ID], [Date], [...

Does LINQ To SQL auto update the LOCAL/CLIENT id column after a SubmitChanges call?

just want to know if linq to sql auto updated the id column of a class (table row object) after SubmitChanges is called inserting a new row to that table, that would be fantastic, would anyone be able to confirm this? ...

alternative to Ms Database Publishing Wizard

I really hate this application, it always generates tables & procedures I didn't select. Is there a better software to extract specific SP's and Table schemas? Note: for Microsoft SQL Server 2005 ...

sql update query

Hi I need an update query to set the null values with another value in the same group for example Table filed1 filed2 filed3 1 e 1/1/2009 1 e null 1 e 1/1/2009 2 f 2/2/2009 2 f 2/2/2009 2 f null 3 g 3/3/2009 3 ...

SQL query with limit on rows from one table, not the result set

I'm running a simple query with a join, similar to SELECT t1.a, t2.b FROM t1 LEFT JOIN t2 ON ... LIMIT 5 As t1 has-many rows in t2 ( any number above 2 ) the LIMIT statement does not return the first 5 rows from t1 and corresponding entries from t2, but 5 rows which usually include 2-3 rows from t1. How can I write this query to get ...

how to catch NULL values using case statement

Hi, here in this query I want to replace the values in Person.Contact of Adventureworks database with some new values. The below query case statement is working fine for other values but I am not able to change the values those are in NULL. I am using SQL Server. Any help is appreciated. select contactid,Title,FirstName,MiddleName, cas...

How to store dependency tree in a database?

I am trying to store a dependency tree in a PostgreSQL database. There are about 20,000 software items, each item can depend on several other items. There are several types of dependencies (some are run-time dependencies, some are build-time dependencies and some are test-dependencies). The dependency is recursive and each item only kn...

How can I protect my PL/SQL source code.

How can I protect my PL/SQL source code. ...

Very slow SQL statement

I'm having some major issues with an SQL statement, the following statement causes so much stress to the MySQL engine it pretty much hangs: select c.title, c.initial, c.surname, c.labelno, c.email, br1.bookingdate from explorer.booking_record br1 inner join explorer.client c on c.labelno = br1.labelno and email not like '' where br1.boo...

How to create automatically a table populate script from current data in SQL Server?

Is there a tool that allows me to create a sql populate script for a table using its current data? ...

oracle date sequence?

Hi I have an oracle db and I need a table containing all the dates spanning 2 years; for example from 01/01/2011 to 01/01/2013. First I thought of a sequence but apparently the only supported type is number, so now I am looking for an efficient way to do this cheers hoax ...