sql

Graphing time intervals in Access

I have a table that looks like the following: StudyId StudyStartDateTime ============================ 1 01/01/2009 08:45 AM 2 01/01/2009 08:53 AM ... I'd like to return a query that contains the StudyId, as well as the ten-minute interval during which it was started: StudyId Interval ================== 1 8:40...

SQL select. Help please

Hi! I have a 3 tables 1. tBooks id Title authorID 2. tAuthors id Name 3. TBookAuthors bookID authorID a book can have a few authors, an author can write a few books So i need to search a book by name and select all the authors in the one record. i tried like this, but result is a few records (how much authors). Only diference b...

Select Distinct in SQL Server vs Access

I have a large query that pulls data from 3 tables. It is a SELECT DISTINCT query. I am in the process of migrating this query from Access to SQL Server. The query in Access, which uses linked tables to SQL Server, returns 920K records. The query in SQL Server (querying the same 3 tables) returns 1.1 million records. They are the sam...

Retrieving data from MySQL in one SQL statement

Hi all, If I'm getting my data from Mysql like so: $result = $dbConnector->Query("SELECT * FROM branches, businesses WHERE branches.BusinessId = businesses.Id ORDER BY businesses.Name"); $resultNum = $dbConnector->GetNumRows($result); if($resultNum > 0) { for($i=0; $i < $resultNum; $i++) { $r...

Sql server management server

Can I replace Sql Server Management Studio Express with the enterprise version without deleting the express version? If so can you tell me how? ...

Internal SQL Server Error when referencing a named instance of SQL

I am trying to script some inserts from a source database to a target database, using linked servers. For the first time we are using a second named instance of SQL, and it is giving me an "Internal SQL Server Error" when I run the following code. If I remove the brackets around the named instance, I no longer get the Internal SQL Serv...

Is this stored procedure safe from sql injection?

This stored proc executes sql with parameters using sp_executesql. Is it safe from sql injection? create procedure ExecutePeopleFilter (@lastNameFilter varchar(20), @companyNameFilter varchar(20), @ageFilter int, @dateFilter datetime) as begin declare @sql varchar(4000) declare @params varchar(1000) decla...

How can a materialized view be created in sqlite?

I've done countless searches on materialized views and SQLite. Of what I can find there seems to be mentions in 2004 and 2006 that SQLite DOES NOT have materialized views. Followed immediately by SQLite's changelog from March 2008 where it specifically mentions optimizing materialized views. Now, I figure logically either the 2004 and...

How to find complementary tags?

I have a MySQL database with 3 tables: The main table of records called "tracks" (as in music) A tags table called "tags" A join table for the two called "taggings" The tags table is basically a list of genres, which is pre-defined. A track can then have 1 or more tags (via the join table). The idea is, that the user checks off the ...

SQLServer CASE expressions - short circuit evaluation?

I am trying to optimize a query that does something like this: SELECT ... CASE WHEN (condition) THEN (expensive function call #1) ELSE (expensive function call #2) END ... The query plan shows that for even in cases where 100% of rows satisfy the WHEN clause, a substantial portion of the time is spent in calls to the resu...

How Do I Query for "Per Day" results for a given date range in MS SQL?

Sorry if this has been asked before. I tried looking through the related questions and didn't find anything that I thought was relevant. Anywho, I would like to build a query that will pull the number of rows that were created on a given date range and time frame. In other words. the date range would be for a given month, but I only wan...

select a list of rows from this table format based on distinct fk2 and > date?

Is it possible to select a list of rows from this table format based on distinct fk2 and > date? Table pk fk1 fk2 value date 1 1 1 100 1/1/2009 2 1 2 110 1/1/2009 3 1 2 120 5/1/2009 4 1 3 130 1/1/2009 I would like it to return rows 1,3,4 I only pass in fk1 Select * from table where fk1=1 'and the row with the latest dat...

Why is PostgreSQL Harder to Manage/Maintain then other Databases

I am very interested in postgesql because they have a uuid data type. I have done searches around SO and many people say that Postgres is harder to maintain and manage. Why is this? Is it because postgres needs more configuration, is it because postgres does not have a GUI? ...

How can I create a unique index in Oracle but ignore nulls?

I am trying to create a unique constraint on two fields in a table. However, there is a high likelihood that one will be null. I only require that they be unique if both are not null (name will never be null). create unique index "name_and_email" on user(name, email); Ignore the semantics of the table and field names and whether tha...

SQL Query Where Clause for Null OR Match (only return 1)?

I have a table that has records with a structure similar to this.. ID RoleID 1 NULL 2 15 3 16 I wrote a where clause to get records like the following SELECT * from TableX WHERE (RoleID = 2 OR RoleID IS NULL) This gets me the record of "1,NULL" But if i query SELECT * from TableX WHERE (RoleID = 15 OR RoleID I...

AddWithValue difficulty

I want to run parameterized SQL with .NET. But when I use AddWithValue() the generated command does not work. SqlCommand cmd = new SqlCommand("SELECT * FROM table WHERE table.name = @A") cmd.Parameters.AddWithValue("@A", "A string"); Generates this sql command: exec sp_executesql N'SELECT * FROM table WHERE table.name = @A',N'@A nva...

What does Codd's 'non-subversion rule' mean?

Recently I was reading about Codd's 12 Rules, and I understood all except number 12, the 'non-subversion' rule. If anyone can explain me the rule (using an example, preferably), that would be very helpful. Thanks. ...

Nvarchar or varchar what is better use multiply of 2 or rounded full numbers??

Hello, My question is what is better to use in generating columns in SQL. Should the size of nvarchar (varchar) be multiply of 2 (32, 64, 128) or it's doesn't matter and we can use fully numbers example '100', '50' ? Thank You very much for answers with reasons Greeting's to all ...

SQL "specified data type is not valid" error

Why does SQL server express 2008 give me this error? CREATE TABLE model ( name varchar(3), desc varchar(25) ) 0x80040E14, Minor Error 26302 > CREATE TABLE model ( name varchar(3), desc varchar(25) ) The specified data type is not valid. [ Data type (if known) = varchar ] ...

How do I perform update query with subquery in Access?

I want to port this SQL query, which works just fine on SQL Server, MySQL, and Oracle, to an Access database. How do I do that? Right now it prompts me for a Company_ID for some reason. Edit: I was getting the prompt because I forgot to first create the Company_ID column in VendorRegKeys. Now I am getting error "Operation must use an...