sql

Checking for time range overlap, the watchman problem [SQL]

I am running into a road block on a larger problem. As part of a large query I need to solve a "night watchman" problem. I have a table with schedule shifts as such: ID | Start | End 1 | 2009-1-1 06:00 | 2009-1-1 14:00 2 | 2009-1-1 10:00 | 2009-1-1 18:00 3 | 2009-2-1 20:00 | 2009-2-2 04:00 4 | 2009-2-2 06:00 | 2009-2-2 14:...

SQL putting two single quotes around datetime fields and fails to insert record

I am trying to INSERT into an SQL database table, but it doesn't work. So I used the SQL server profiler to see how it was building the query; what it shows is the following: declare @p1 int set @p1=0 declare @p2 int set @p2=0 declare @p3 int set @p3=1 exec InsertProcedureName @ConsumerMovingDetailID=@p1 output, @UniqueID=@p2 output, ...

how to find out who and when permissions/grants in stored procedure was changed

There is a stored procedure in SQL Server 2005 in which users claim execute permission was removed as they can no longer execute the stored procedure. I tried to find it in trace files, but i can't find an entry for this stored procedure My question is is there other way to find out who and when permission/grants of this stored procedu...

Lazy evaluation of Oracle PL/SQL statements in SELECT clauses of SQL queries

I have a performance problem with an Oracle select statement that I use in a cursor. In the statement one of the terms in the SELECT clause is expensive to evaluate (it's a PL/SQL procedure call, which accesses the database quite heavily). The WHERE clause and ORDER BY clauses are straightforward, however. I expected that Oracle woul...

PLS-00306: wrong number or types of arguments in call to...

Can anyone help me with this error. It works when I try the first procedure but not the second when I enter two numbers. Any ideas? create or replace package LE2_P1 is procedure GENERATE_MULTIPLICATION_TABLE(p_axis_both in number); procedure GENERATE_MUTLIPLICATION_TABLE(p_axis_x in number, p_axis_y in number); end LE2_P1; / create or ...

what's wrong with this sql query?

Okay I have two variables in PHP $username; $password; which are initialized to the data retrieved from $_POST variable :) I have this SQL query $sql = "SELECT * FROM users WHERE username = '" . $username . "' AND password = '" . $password . "')"; But this doesn't works and returns me nothing :( Can you instruct me into the right...

Comma delimited output from SQL query

How can i put the result of a sql server query into a "comma delimited" format? ...

PHP & Mysql updating many to many relationship with checkbox form

I have a many to many table structure and updating checkbox forms. The goal is to relate the users table to the projects table with the users_project table. This way there can be many users per project and many projects per user. The form would on each user edit page would look something like this <form action="#" method="post"> <...

How does a dataset update query work?

I have a dataset that points to a View in my SQL database, and a gridview that uses this dataset to populate itself. I of course want the rows editable, so I added Edit and Delete functionality to the gridview - standard method (not custom buttons) working with the Update Query now... For some reason it didn't auto-generate the update s...

handling DATETIME values 0000-00-00 00:00:00 in JDBC

I get an exception (see below) if I try to do resultset.getString("add_date"); for a JDBC connection to a MySQL database containing a DATETIME value of 0000-00-00 00:00:00 (the quasi-null value for DATETIME), even though I'm just trying to get the value as string, not as an object. I got around this by doing SELECT CAST(add_date A...

access db, select group by having max problem

in Access DB... I need to extract the itemcode / desc combination for each itemcode in the following table where the desc has been used most frequently. most frequently could possibly mean that there was only one version (see added record for pear) in the case of itemcode 777, I'll have to decide later which description version to use....

oracle - sum on a subquery ?

Hi, Wonder if anyone can help me understand how to sum up the column of single column, ie a list of costs into one total cost. I have been looking into this, and I think I'm on the right lines in undertsanding i need to sum the query, treat it as a subquery. However I'm not having much luck - do I need to give the subquery an alias, or...

Calculating the difference between two dates

I have a report that calculates multiple date differences (in business days, not DATEDIFF) for a variety of business reasons that are far too dull to get into. Basically the query (right now) looks something like SELECT -- some kind of information DATEDIFF(dd, DateOne, DateTwo) AS d1_d2_diff, DATEDIFF(dd, DateOne, DateThr...

Trouble Writing SQL Query....

I'm having trouble writing a query. I have a support tabled called 'MYTABLE' and it has a column called 'TABLENAME' that can have one or many table names in it. Multiple Tables are separated with commas. Example: TBLUSER TBLUSER, TBLACCOUNT I'm trying to write an query that will identify any entries in the MYTABLE table that are no...

Executing an SQL statement in C#?

Hey guys i want to execute my SQL statement but im having synatx trouble, can someone help me understand what i doin wrong please? Thanks, Ash. public void AddToDatabase(string[] WordArray, int Good, int Bad, int Remove) { for (int WordCount = 0; WordCount < WordArray.Length; WordCount++) { string sSQL = "INSERT INTO W...

Generate parent record from child records

I have the following situation. Im getting data from an external system in the form UserId Group Value 1 Abc ..... 1 Abc ..... 1 Bcd ..... 2 Abc ..... I need to massage this data into my schema, i.e. Parent Table ID UserID Group Name 1 1 Abc User 1 - Abc data 2 1 ...

How do I delete from multiple tables using INNER JOIN in SQL server

In MySQL you can use the syntax DELETE t1,t2 FROM table1 AS t1 INNER JOIN table2 t2 ... INNER JOIN table3 t3 ... How do I do the same thing in SQL Server? ...

Can i reuse bind variable in an 'insert ... on duplicate update ...' statement?

I am attempting to run a query that uses bind variables against a mysql database engine. I am wondering how I can tell the engine to "reset" the bind variable assignments. I'm sure an example will explain much better than my poor brain. Here is the query: INSERT INTO site_support_docs ( ASSET_ID, TIME_STAMP, ...

username and password prompt when trying to do SQL queries when connecting Microsoft Access to Delphi 7

As part of my university coursework, I was asked to design and create an HCI for a shop. Part of it is to connect Delphi 7 to MS Access and run SQL queries. I have the database connected to Delphi, but when I run the program and enter the query it prompts me to enter a username and password to access the database. Does anyone have any id...

How to set an initial id value on a create_table?

I want to get the auto incrementing id column for a create_table rails command to start at 500. I've found examples of how to set the initial auto_increment id value in sql: CREATE TABLE student ( id int(2) NOT NULL auto_increment, name varchar(50) NOT NULL default '', class varchar(10) NOT NULL default '', mark int(3) NOT NULL default...