sql

SQL searching for rows that contain multiple criteria

I have 3 tables Customer Groups CustomerGroupJoins Fields to be used Customer:Key Groups:Key CustomerGroupJoins:KeyCustomer, KeyGroup I need to search for all users that are in all groups with keys, 1,2,3 I was thinking something like (but have no idea whether this is the right/best way to go): SELECT * FROM Customer WHE...

Displaying zero-valued data in an SQL Query?

I have the following two tables (simplified for this question): CREATE TABLE team ( teamID CHAR(6) NOT NULL PRIMARY KEY); CREATE TABLE member ( memberID CHAR(7) NOT NULL PRIMARY KEY, teamID CHAR(6) NOT NULL REFERENCES team(teamID) ); I also have the following query, which is to list the number of members in each team: SELECT tea...

Asp.net to SQL Server 2005, UPDATE smalldatetime procedure doesn't work?

As the topic suggests. I'm making a small program where you can browse and handle a bunch of data. The problem is that while inserting new rows into the SQL table works fine, using the same methods to update causes a problem with the smalldatetime variables. I noticed using profiler that the exec command puts double quotes on the dates,...

Structure within staging area of data warehouse

Hi. We are working on a datawarehouse for a bank and have pretty much followed the standard Kimball model of staging tables, a star schema and an ETL to pull the data through the process. Kimball talks about using the staging area for import, cleaning, processing and everything until you are ready to put the data into the star schema. ...

Using aspnet_regsql.exe to set up Windows Authentication on an already matured database

I have a database (using Microsoft SQL Server Management Studio Express) that is currently being used quite heavily in a functioning application. I am porting this application over to Windows Authentication rather than the current basic authentication system (or lack thereof) that exists. The easiest way that I know to set this up invo...

How much calculation should be done by MySQL?

I am writing an application and using MySQL to return the difference between 2 dates in MySQL should MySQL do this or should I actually let PHP handle it? I also just need the sum of all the results I am getting back should I return them and add them up on the php side or is there a way to add all the results together on the MySQL Serve...

% sign in Java's PreparedStatement

PreparedStatement ps = con.createStatement("select * from table1 where last_name like ?"); ps.setString(1, "'%"+lastName+"'"); Will this work the same as... Statement s = con.createStatement("select * from table1 where last_name like %"+ lastName); Or does PreparedStatement strip out the % sign? ...

Id or [TableName]Id as primary key / entity identifier

Is it preferred to use "Id" as the column name for a primary key or "[TableName]Id" as a naming convention? Table: Account Primary Key: Id -- versus -- Table: Account Primary Key: AccountId It seems to be split about 50% / 50% in the implementations that I've seen. What are the advantages and disadvantages in each approac...

Is there an easy way to add a custom migration script to SQL Compare scripts?

Hi all, At my work we are currently having some serious pains pushing our database changes across environments. The issue starts to show up when we create a new non-nullable column on an existing table. The script that SQL Compare generates creates the column as non-nullable, so it will always fail. I was hoping that there was some al...

ACCESS SQL > SELECT CASE HELP

I have a set of tables including Reps, Teams, Errors, Error Log. Error Log lists all errors made by a rep. Each rep is in a team. Each rep has an Edge ID (user number) Each different type of error has a points value (stored in the errors table). I have this query in Access to total the points value for each rep in a team between two dat...

Why do double and float exist?

Duplicate http://stackoverflow.com/questions/803225/when-should-i-use-double-instead-of-decimal .. and many more... We use the C# and SQL Server decimal datatypes throughout our apps because of their accuracy. Never had any of those irritating problems where the total doesn't add up to the detail, etc. I was wonderi...

How can I write a SELECT statement in which the condition is the result of a function

Hello, I want to write a SELECT statement as follows: SELECT field_a FROM my_table WHERE field_b IN (my_function(field_c)). Is that possible? my_function would have to return an array? I'm using PostgreSQL 8.2 ...

MYSQL MAX/COUNT/IN/DATE

Hi All Hope you can advise. Im pulling my hair out on a query and hope you can advise. I have a table where I want to select MAX from an inner count between dates with an IN. View Table Here is what I have tried but with no luck at all. SELECT MAX(no_hits) from (SELECT count(hits) AS 'no_hits' ) FROM stats WHERE 'date' >= DATE_SUB(C...

how would you go about automating finding all the procs that a proc calls, along with their text?

Say I have a stored procedure, ProcA. It calls ProcB some of the time, ProcC all of the time and ProcD if it hits an error. ProcB calls ProcE every time. ProcC calls ProcF if it hits an error. How could I automate getting the text of ProcA along with the text of all the procs that it calls and regress all the way down the tree (A down ...

SQL if( exists()) query duplication

I need to write a a query that gets a set of information from a table, but if there is no information for that specific client, then use the default set. I was wondering if there is a way to avoid query duplication in an if(exists()) statement. For example: IF( EXISTS( SELECT * FROM UserTable WHERE Name = @UserName)) BEGIN SELECT ...

Using a smalldatetime or int for storing a month in database

I'm currently developing a monthly checklist system for our organization. A user may login, select a month, then submit a list of yes/no questions relevant to that month for our organization's purposes. Some of the questions are used in more than 1 month's checklist, so I'm creating an intersection table to facilitate this one-to-many re...

How do you select latest entry per column1 and per column2?

I'm fairly new to mysql and need a query I just can't figure out. Given a table like so: emp cat date amt cum 44 e1 2009-01-01 1 1 44 e2 2009-01-02 2 2 44 e1 2009-01-03 3 4 44 e1 2009-01-07 5 9 44 e7 2009-01-04 5 5 44 e2 2009-01-04 3 5 44 e7 2009-01-05 1 6 55 e...

How is data stored in SQL server?

How is data stored in SQL server? ...

Will a SQL Server Job skip a scheduled run if it is already running?

The title pretty much says it all - if you schedule a SQL Server job to run every X number of minutes, and it does not finish the previous call before the # of minutes is up, will it skip the run since it is already running, or will it run two instances of the job doing the same steps? ...

Is it poor coding practice to have a SQL table that contains a column with the same name?

Example: CREATE TABLE ErrorNumber ( ErrorNumber int, ErrorText varchar(255), ) This can result in queries that look like: SELECT ErrorNumber FROM ErrorNumber WHERE ErrorNumber=10 ...