sql

My update query executes but doesn't update

I have this update query. UPDATE production_shr_01 SET total_hours = hours, total_weight = weight, percentage = total_hours / 7893.3 WHERE (status = 'X') The query executes fine but the problem is that when this query executes, it doesn't update the percentage field. What might be the problem? ...

Good strategy for copying a "sliding window" of data from a table?

I have a MySQL table from a third-party application that has millions of rows and only one index - the timestamp of each entry. Now I want to do some heavy self-joins and queries on the data using fields other than the timestamp. Doing the query on the original table would bring the database to a crawl, adding indexes to the table is not...

IIS 6.0 Server and Unicode Characters

We are performing a pen test on a simple asp application that uses MS SQL Database. It seems for the authentication they are using dynamic constructed queries but escaping single qoutes. When we use Unicode quotes like %uFFO7,%u02b9 etc we are able to successfully inject SQL injections. Want to understand is it more a kind of configura...

ALTER TABLE error

Can someone explain to me why I am receiving the following error? I want to rename the column "exerciseID" to "ID" in a mysql table using the following syntax. ALTER TABLE `exercises` CHANGE `exerciseID` `ID` INT( 11 ) NOT NULL AUTO_INCREMENT However I receive the following error: MySQL said: #1025 - Error on rename of './balan...

How do I create a create and execute an SQL command using OleDB directly?

I want to use the OleDB interfaces directly to open a connection to a DB, create a command and executing it (for example using the ICommandText interface). The main thing I can't find is how to create the connection and the command object and how to connect the object that implements the ICommandText to the connection. In ADO I would ju...

How to use local variables in stored procedures?

if I want to select any id from a table and want to insert it's value in another table as foreign key then how i will do it through stored procedure? ...

INSERT SQL in Java

Hello. I have a Java application and I want to use SQL database. I have a class for my connection : public class SQLConnection{ private static String url = "jdbc:postgresql://localhost:5432/table"; private static String user = "postgres"; private static String passwd = "toto"; private static Connection connect; pub...

How can I connect to Sybase with Perl?

I'm trying to a good Perl module to use for connecting to a Sybase database. My Googling has led me to see sybperl as a possible choice, but it hasn't been updated since 2005. ...

Dynamically set the result of a TSQL query using CASE WHEN

SELECT MyTable.Name, ( SELECT CASE WHEN ISNULL(SUM(TotalDays), 0) <= 0 THEN 0 ELSE SUM(TotalDays) END AS Total FROM Application AS Applications WHERE (ID = MyTable.id) ) - MIN(Assignments) AS Excesses FROM MyTable The above TSQL statement is a subq...

At what point should a Table Variable be abandoned for a Temp Table?

Is there a row count that makes table variable's inefficient or what? I understand the differences between the two and I've seen some different figures on when that point is reached, but I'm curious if anyone knows. ...

Querying tables based on other column values

Is there a way to query different databases based on the value of a column in the query? Say for example you have the following columns: id part_id attr_id attr_value_ext attr_value_int You then run a query and if the attr_id is '1' is returns the attr_value_int column but if attr_id is greater than '1' it joins data from another ta...

sql error, NULL??

So I have a query, can someone let me know if it looks ok content wise? "INSERT INTO ".TBL_MESSAGES." (NULL, 'Your ranking points have changed', 'Due to your recent activity, your ranking points have increased by $r', '2', '$u', '0', '0', '0', '0', NULL, NUL...

SQL Query in NHibernate diction

I have a SQL Query which works in SQL Management Studio: Select Id From table t Where t.Date= (Select Max(Date) From ( Select * From table where ReferenceId = xy) u) Reason is, from all entries with a certain foreign key, I want to receive the one with the highest date. I tried to reform this Query for use in NHiber...

SQL - Break a start/end time into 15 minute records

I've got a record set that consists of a start and end time in two separate fields: id - Int startTime - DateTime endTime - DateTime I'd like to find a way to query a record and return it as X records based on the number of 15 minute intervals found between the start and end times. For example, let's say I have a record like this: ...

Handling apostrophes, php and pgsql

For my forms, I'm using pg_escape_string on every field before I insert them into the database. So I get something like firstname='O''reilly'. But when I try to print that out, I get O''reily, 2 apostrophes. Shouldn't it only 1 apostrophe, O'reilly? This isnt a debugging problem, im just wondering if you have firstname='O''reilly', how ...

How to remove the secondary database created by sp_add_log_shipping_secondary_database

How to remove the secondary database created by sp_add_log_shipping_secondary_database ...

What value should .net SqlCommand.ExecuteNonQuery() return if no rows are affected?

I have the following code: int result = -1; StringBuilder sb = new StringBuilder(); SqlCommand cmd = MyConnection. sb.AppendLine("delete from Table1 where ID in"); sb.AppendLine("(select id from Table1 t1 where not exists(select * from Table2 t2 where t2.Table1ID = t1.ID))"); cmd.CommandText = sb.ToString(); result = cmd.ExecuteNonQuer...

Find details of a query or statement that caused an unexpected table update

We have been having problems with ghost updates in our DB (SQL Server 2005). Fields are changing, and we cannot find the routine that is performing the update. Is there any way, (perhaps using an update trigger ?) to determine what caused the update? The SQL statement, process, username/login,etc? ...

How do I Change SQL Server column names in T-SQL?

I have a table with 600+ columns imported from a csv with special chars % _ - in the column names, is there a way to change the column names to remove these special chars ? The code can be in T-SQL. ...

SQL Server compare table entries for update

I have a trade table with several million rows. Each row represents the version of a trade. If I'm given a possibly new trade I compare it to the latest version in the trade table. If it has changed I add a new version, otherwise I do nothing. In order to compare the 2 trades I read the version from the trade table into my application. ...