sql

What is wrong on connection string

I am trying to connect database.sdf on same director. Using following code but gives me connection error. What I am doing wrong. Please help me. Dim connstring As String Dim con As SqlCeConnection Dim command As SqlCeCommand connstring = "Persist Security Info = False; Data Source = '.\database.sdf', Password = 'pswrd', ...

Oracle EXISTS query is not working as expected - DB Link bug?

I'm completely baffled by the results of this query: select count(*) from my_tab mt where mt.stat = '2473' and mt.name= 'Tom' and exists (select * from [email protected] cu, [email protected] pr where cu.user_id = pr.user_id and mt.name = pr.name and m...

SQL Server 2005 - Using Null in a comparison

This is more of a question to satisfy my own curiosity. Given the following statement: DECLARE @result BIT SET @result = CASE WHEN NULL <> 4 THEN 0 ELSE 1 END PRINT @result Why do i get back "1" instead of "0" Changing it to: DECLARE @result BIT SET @result = CASE WHEN NULL IS NULL ...

what this sql does

I have this as a sql statement. What does it do IF(`table`.`field1` IS NULL, '', GROUP_CONCAT(DISTINCT `table`.`field1` ASC SEPARATOR ',') ) AS `MyNewFields`, ...

Log SQL queries in production?

I'm having a dilemma on whether or not to log SQL queries in production as well. I don't know how slow writing files is in PHP. Probably some benchmarks could give some answers, but I wanted to see what you guys think before. What does or does not make the process slow? Or what things could it depend on? ...

Creating table with Identity related too other column in table

I'm trying to create a table that has a primary key (Department_ID) that auto assigns(not hard). However the assignment would be based on the exsisting value in another column(Department_Name). So for example if its the department_name payroll the department_ID would be 1 for example. If I tried to insert into and had to add another payr...

SQL - How to batch update given the results of a select

I've got a select statement that joins a couple of tables and grabs some information. I'd like to updated all of the records on one of those tables (found in the select) with information contained in the select. The select looks like this: SELECT account.id document.id FROM customer INNER JOIN account ON (custome...

Can't create a MySQL query that generates 4 rows for each row in the table it references.

I need to create a MySQL query that generates 4 rows for each row in the table it references. I need some of the information in those rows to repeat and some to be different. In the table each row stands for one day. I need to break the day up in 6 hour increments, hence the four rows for each entry. I need to create one column which for...

What is the best way to increment a Java.sql.date / time?

Hello I have an issue where I have a MySQL database storing dates and times in separate columns. However, in Java code I need to increment the resulting timestamp for a date and time from the database by minutes, hours or days and then update the respective columns in the database. I'm currently using Java.sql.date and java.sql.time ty...

In MySQL: How to pass a table name as stored procedure and/or function argument?

For instance, this does not work: DELIMITER // CREATE PROCEDURE countRows(tbl_name VARCHAR(40)) BEGIN SELECT COUNT(*) as ct FROM tbl_name; END // DELIMITER ; CALL countRows('my_table_name'); Produces: ERROR 1146 (42S02): Table 'test.tbl_name' doesn't exist However, this works as expected: SELECT COUNT(*) as ct FROM my_tab...

How to Determine Equality of Two Very Large Tables

Hey guys, I'm using DB2 and I have two tables that have a million+ rows in them. Is there a query I can create that will check the two tables to see if all the values in the two are the same? Or, what is the best way to do this? Thanks, Tyler ...

How to check if table is empty in VB.net

Possible Duplicate: Checking for an SQL result in VB.NET I have login form which is redirect user for their levels but before to that if there is no any user on the data table I would like to redirect to create admin form. I have all the forms but I didn't manage to redirect them because I don't know how to create statement. C...

How to create a sql query for sql reporting services 2008 to return the number of occurences of sick days.

How to create a sql query to return the number of occurrences of sick days. Where one occurrence is defined as consecutive days out sick. It would also be considered one occurrence if the a weekend fell within that time period or a holiday fell in that time period. Examples of what is consider one occurrence: A person is out sick Mon...

SQL Policy based management - Problem with ExecuteSql() based conditions

I have created a SQL condition using ExecuteSql() and enabled a policy based on this condition for Stored Procedure facets. When I evaluate this policy “On demand”, it runs perfectly fine and gives the desired pass/fail results. However, if I run this “On schedule”, the policy runs incorrectly and from the SQL Profiler, I am able to figu...

MySQL Backup Table if it Exists

I am trying to write a script that will copy all the data in table a to table b if table a exists. Table b is the exact same structure as table a would be if it exists, though it may not. I am able to copy using the following statement: INSERT INTO 'B' SELECT * FROM 'A', but I don't know where to use IF EXISTS, or if I even can to determ...

What is wrong with count

I would like to redirect admin if there is no record in table to the another form but I am doing something wrong in my code but i cant find. Could you please help me? Private Sub frmlogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim cmd As SqlCeCommand Dim namecount As String Dim c...

How do I update selective fields in SQL (leaving some unchanged)?

I would like to update a record with two dates, leaving existing data intact if I do not have a new value to update with. Here is a sample table record: id last_foo last_bar -- ---------- ---------- 1 2010-05-30 2010-05-30 And the query I am using: UPDATE sampledates SET last_foo = @LastFoo, last_bar = @LastBar ...

SQL Statement to Track the Number of Defects Opened Each Day By Application

I use Quality Center to track defects, I believe it uses MSSQL language. I have a table that has the following fields: defectID, summary, application, severity, status, createDate, closedDate. Will just cover the relevant fields. defectID application severity createDate closedDate -------- ----------- -------- ---------- --------- 1 ...

MySQL Index Structure: multiple or single index?

Hi, I have question about database optimizing, indexing. I have table that called "projects" and i will execute queries like this: Ordering Queries SELECT * FROM projects WHERE active = 1 ORDER BY created SELECT * FROM projects WHERE active = 1 ORDER BY project_deadtime SELECT * FROM projects WHERE active = 1 ORDER BY project_allowed...

Visual foxpro DBF update using php

I am using php to update some tables under VFP 9.0 using ADO COM. I am able to select and update the DBF until i specify any Where clause. The moment i add a where clause to the query, it simply returns or updates 0 rows. $conn = new COM("ADODB.Connection"); $conn->Open('Provider=VFPOLEDB.1;Data Source="C:\\testDB.dbc";'); $query = "...