sql

SQL can I have a "conditionally unique" constraint on a table?

I've had this come up a couple times in my career, and none of my local peers seems to be able to answer it. Say I have a table that has a "Description" field which is a candidate key, except that sometimes a user will stop halfway through the process. So for maybe 25% of the records this value is null, but for all that are not NULL, it ...

selecting records in mysql db from 1, 7, and 30 days ago with datetime and php

Im using the following query to target results that are exactly X days older than current time. SELECT *, DATE_FORMAT(datetime, '%m/%d/%Y') FROM table WHERE datetime BETWEEN SYSDATE() - INTERVAL 30 DAY AND SYSDATE() ORDER BY ID DESC Problem is its returning data from current day if a record from ...

how to disable mysql's match query's 50% exclusion

So apparently if a Mysql table's fulltext index contains a keyword that appears in 50% of the data rows, that keyword will be ignored by the match query So if I have a table with the fulltext index 'content' which contains 50 entries and 27 of the entries contains the word 'computer' in the content field, and I run the query: SELECT *...

How to debug differences in postgresql TRUNCATE times?

postgres 8.3 / Ubuntu Karmic / 32-bit (in virtualbox): duration: 76.534 ms statement: truncate audit.users cascade duration: 0.952 ms statement: delete from audit.users postgres 8.4 / Ubuntu lucid / 64-bit (native, on the machine hosting the karmic virtualbox): duration: 1469.271 ms statement: truncate audit.users cascade ...

SSIS Dynamic Excel Destination File Name

How can I configure a dataflow task that takes data from a MS SQL Server 2008 datasource and puts it in an Excel file where the filename looks like 'date filename'.xls? ...

Combine results from sql query

Hi, I have three tables in sql, CUSTOMER, ISSUE, ISSUE_NOTES. SELECT CUSTOMER.name, ISSUE.description, ISSUE_NOTES.notes FROM CUSTOMER, ISSUE, ISSUE_NOTES WHERE CUSTOMER.customer_id = ISSUE.customer_id AND ISSUE_NOTES.incident_id = ISSUE_NOTES.incident_id This will produce a row for each issue_notes field that's populated. (field is...

concat tables with different content

Hi, I am currently building a small web application for publishing stories using PHP and MySQL. Each story may either be a article (with lots of fields and data), just a hyperlink/url, just an image, or a downloadable file with certain attributes (once again with lots of fields). My problem is related to finding the optimal database la...

Update mySQL table based on row=column name

A little background so you understand what I'm trying to do. I am making a page that takes two user input products and checks to see if they are compatible with one another. This is an n+1*n mySQL table because there are n products. The table looks like name a b c d e a b c d e I already know that every product is comp...

ssrs multiple datasets - master detail

Hi, I'm working on migrating all of our reporting solutions to SQL Server Reporting Services 2008 R2. I have a problem with one of the reports which builds a CP12 - for readers outside the UK, this is a Gas Safety certificate. The report has two data sets, one containing the tenant and landlord details, the other containing a list of ...

Add new row to gridview

I'm using a gridview to display and access a sql database and using databinding. I'm also using autogenerate columns as one gridview has multiple sources and toggles between them. What would be the best way to allow the user to insert a new row? Would a listview be better? ...

how to view PostgreSQL database on windows 7?

Hi, I installed an application that uses a PostgreSQL database. When I installed the application it automatically installed PostgreSQL for me. How can I view the raw PostgreSQL database rows? Thanks ...

SQL - Getting the max effective date less than a date in another table

Hey all, I'm currently working on a conversion script to transfer a bunch of old data out of an SQL Server 2000 database and onto a SQL Server 2008. One of thing things I'm trying to accomplish during this conversion is to eliminate all of the composite keys and replace them with a "proper" primary key. Obviously, when I transfer the ...

SQL Server Generate Script To Fill Tables With Data From Other Database?

Let's say I have two databases with identical tables, but one database's tables contains data while the other doesn't. Is there a way in SQL Server to generate a script to fill the empty tables with data from the full tables? ...

Basic optimisation with an index for mysql

Hi, i have a question about basic mysql database optimisation. I have 3 tables, Articles, Tags and Taggings (which is a join table). Articles Taggings Tags id id id name article_id name tag_id I am retrieving the articles that exactly match the ...

Selecting a column with period in the column name SQL Server

I am linked to a Proficy Historian that allows periods in the column names. Because the data is stored in a non DBMS format I can not use openquery to get the data because there is no set schema to the tables. So I must use four part name syntax to get the data. This example works: SELECT * FROM iHist...[SELECT * FROM ihTrend] but ...

RESOLVED :: Sql question, how to write

Please help me to write the following sql. I have a table like this, with an amount column and date column amount date ----------------------- 100 - 2010-02-05 200 - 2010-02-05 50 - 2010-02-06 10 - 2010-02-06 10 2010-02-07 what I want is to write a sql to get total for each day. Ultimately my query...

Combine two columns together from separate tables

Let's say for instance: I have two tables: old_data and new_data. Both old_data and new_data have one column called this_is_col. Both old_data and new_data have various (hundreds) of rows of dates (2010-02-06, 2010-01-09, 2007-06-02, etc.). Both tables don't necessarily have the same dates, but they both have the same format. The fiel...

Insert Data From One Server To Another?

If I want to run this sort of query in SQL Server, how can I do the same query from one server I am connected to to another? I tried adding "[ServerName1]." before "[DatabaseName1].[dbo]..." and "[ServerName2]." before "[DatabaseName2].[dbo]..." but that didn't seem to work. INSERT INTO [DatabaseName1].[dbo].[TableName] ([Fi...

Entity framework issue with WCF and IIS

Hello all, I have a WCF service, a MS SQL database, and the Visual Studio 2008 development environment all in one machine. The operating system is Windows Server 2008 with IIS 7 on it. The IIS 7 hosts my WCF service and the service is connecting to a database using Microsoft Entity Framework. Currently, I'm testing the WCF service using...

SQL Updated since last visit column

I'm working with SQL Server and I'm pretty new to SQL in general, so if this is a very trivial question, please bear with me. I have a table in a database with a datetime field representing some timestamp. When extracting the table via a SELECT statement, I would like to have a column of True/False representing whether or not the row ha...