sql

Repeater control to aggregate data?

I have a table with doctor offices and doctors in those offices that I'm populating to a repeater control. The data coming back is not aggregated. So, if there are 2 doctors in 1 office, there are 2 rows, same office, different doctor. Is there a way to aggregate the data so the repeater shows 1 office with all of the doctors from that...

mysql procedure? Function?

I need to have a routine/function/stored proc/whatever to archive particular accounts from our 'active' table, to an inactive table. I can write this out as a group of queries, all executed in order by PHP one at a time, but I'm looking to offload most of the work to mysql because it's not necessary for PHP to be involved here. Basical...

SQL database problems with addressbook table design

Hello! I am writing a addressbook module for my software right now. I have the database set up so far that it supports a very flexible address-book configuration. I can create n-entries for every type I want. Type means here data like 'email', 'address', 'telephone' etc. I have a table named 'contact_profiles'. This only has two colu...

How to document a database

(Note: I realize this is close to http://stackoverflow.com/questions/186392/how-do-you-document-your-database-structure , but I don't think it's identical.) I've started work at a place with a database with literally hundreds of tables and views, all with cryptic names with very few vowels, and no documentation. They also don't allow g...

SQL Rounding Question

I have the following values being returned in a column.. 0.250000 and 13.000000. I'd like to round the 0.250000 up to 1 and leave the 13 as is. Any easy way to do this since they both fall within the same column? ...

Accessing 'Global' Variables In An ExecuteSQL Task

I have an SSIS package that does the following: Selects the connection strings from a table of servers. The connection string is either the name of the server along with the domain (i.e. Dalin.myhouse.com) or is the direct IP to a server. The package iterates through each connection string and populates a defined 'global' variable. Th...

Excel Add-On to display data from (My)SQL Database

Hello, is there an easy way of importing data from a mysql/odbc datasource into an excel spreadsheet? The user should be able to select some values from drop downs (e..g date range, branch name etc.) and the values from the dropdown should be used to populate (prepared) SQL statements. The results should be displayed in the Excel file...

DB Design: Does having 2 Tables (One is optimized for Read, one for Write) improve performance?

I am thinking about a DB Design Problem. For example, I am designing this stackoverflow website where I have a list of Questions. Each Question contains certain meta data that will probably not change. Each Question also contains certain data that will be consistently changing (Recently Viewed Date, Total Views...etc) Would it be bett...

SQL statement to collect data in a day-by-day, hour-for-hour fashion...

I have a database which gets updated with 200-1000 new rows per day. Now, I'd like to have an SQL-statement which returns the data day-by-day, hour-by-hour so I can give a rough estimate for the current trend, i.e. how many rows will be added to the database today, just by taking a quick look at those historical graphs. So, say that I w...

Items from multiple categories best practices

Hi, I'm making list of items in categories, problem is that item can be in multiple categories. What is your best practice to store items in categories and how list all items within category and its child categories? I am using Zend Framework and MySQL to slove this issue. Thanks for your replies. Sorry for my English :) ...

Log changes made to all fields in a table to another table (SQL Server 2005)

I would like to log changes made to all fields in a table to another table. This will be used to keep a history of all the changes made to that table (Your basic change log table). What is the best way to do it in SQL Server 2005? I am going to assume the logic will be placed in some Triggers. What is a good way to loop through all th...

What's the difference between "using" and "on" in table joins?

Is this ... T1 join T2 using(ID) where T2.VALUE=42 ... the same as ... T1 join T2 on(T1.ID=T2.ID) where T2.VALUE=42 ... for all types of joins? That's my understanding of using(ID), its just a short hand for "on(T1.ID=T2.ID)". Is this true? Now for another question Is the above the same as ... T1 join T2 on(T1.ID=T2.ID and T2...

in SQL, or Django ORM, what's the conventional way to have an ordered one-to-many?

Say I wanted to have a project, and one-to-many with to-do items, and wanted to re-order the to-do items arbitrarily? In the past, I've added a numbered order field, and when someone wants to change the order, had to update all the items with their new order numbers. This is probably the worst approach, since it's not atomic & require...

Sql Query Linking Two Tables

Hi there, One doubt in MSSQL. There are two tables in a databases. Table 1 named Property contain fields PRPT_Id(int),PRPT_Name(varchar), PRPT_Status(bit) Table 2 named PropertyImages contain fields PIMG_Id(int),PIMG_ImageName(varchar),PRPT_Id(int),PIMG_Status(bit) These two tables follow a one-to-many relationship. That means the e...

Cleanest way to build an SQL string in Java

I want to build an SQL string to do database manipulation (updates, deletes, inserts, selects, that sort of thing) - instead of the awful string concat method using millions of "+"'s and quotes which is unreadable at best - there must be a better way. I did think of using MessageFormat - but its supposed to be used for user messages, ...

Java: creating a date object from a string and inserting into MySQL

Anytime I have to handle dates/times in java it makes me sad I'm trying to parse a string and turn it into a date object to insert in a preparepared statement. I've been trying to get this working but am having no luck. I also get the helpful error message when I go to compile the class. "Exception in thread "main" java.lang.Error: Un...

Best data access method in .NET 2.0

When developing with .NET 3.5 I naturally use LINQ for data access. But for .NET 2.0 projects, what data access model is the best one to use? I tend to use TableAdapters mainly, but sometimes also write my own SQL depending on the situation. ...

How can I modify this to get a random record on the many end of a join?

Here is my query: Select Top 10 CS.CaseStudyID, CS.Title, CSI.ImageFileName From CaseStudy CS Left Join CaseStudyImage CSI On CS.CaseStudyID = CSI.CaseStudyID And CSI.CSImageID in( Select Min(CSImageID) -- >not really satisfactory From CaseStudyImage Group By CaseStudyID ) Order By CS.CaseStudyID ASC Instea...

In PHP, how many DB calls per page is okay?

I've got shared hosting on a LAMP set up. Obviously the fewer calls to the Db per page the better. But how many is too many? Two? Ten? A hundred? Curious what people think. ...

Cross join (pivot) with n-n table containing values

I have 3 tables : TABLE MyColumn ( ColumnId INT NOT NULL, Label VARCHAR(80) NOT NULL, PRIMARY KEY (ColumnId) ) TABLE MyPeriod ( PeriodId CHAR(6) NOT NULL, -- format yyyyMM Label VARCHAR(80) NOT NULL, PRIMARY KEY (PeriodId) ) TABLE MyValue ( ColumnId INT NOT NULL, PeriodId CHAR(6) NOT NULL, Amount DECIMAL(8, 4) NOT NU...