sql

php beginner question. if statements

check it, i have this table tablename: reports id (AI) content (varchar), contentID (int), checked (tinyint) if (isset($_GET['reportPost'])){ $query = mysql_query("select * from reports where contentID = $_GET[reportPost]"); $report = mysql_fetch_assoc($query); if (!mysql_num_rows($query) && $report['checked'] == 0) { echo 'T...

Why is this Java PreparedStatement throwing ArrayIndexOutOfBoundsException 0 with parameterIndex = 1?

The following method, when called with something like String val = getCell("SELECT col FROM table WHERE LIKE(other_col,'?')", new String[]{"value"}); (this is SQLite), throws a java.lang.ArrayIndexOutOfBoundsException: 0 at org.sqlite.PrepStmt.batch(PrepStmt.java:131). Can anyone take pity on my poor bumbling here and help me with why? ...

MySQL DELIMITER syntax errors

This MySQL script installs multiple triggers. It works on one machine running MySQL 5.0.51b-community. On another machine running MySQL 14.12 Distrib 5.0.45, for redhat-linux-gnu (i386) it fails, with this error message, which seems to be related to the DELIMITER // ... // DELIMITER; syntax : ERROR 1064 (42000) at line 272: You ha...

Replacement of compute by clause in t-sql

i have been working on query which uses compute by clause for avg and sum operators . As Microsoft declared this will be a discontinued feature ,what will be the replacement for this feature ...

AVG in Sql - Float number problem

SELECT AVG(variable) AS Expr1, SUM(variable) AS Expr2 FROM ...... result for AVG is 2, but it is not true, it must be 2.95. What is the problem, any idea? ...

SQL Query with Table Locking

I am having an argument with a developer colleague on the team. Problem: SQL query X runs for 1 second on the test system, but for an unknown amount of time on live system (150 users can run queries at the same time). The query causes locks on 8 tables, of which 7 are useless. His idea is to put a WITH (NOLOCK) on the 7 tables so there ...

Programmatically add an SSIS ForEachLoop

How do you programmatically add an SSIS ForEachLoop? We are limited to SQL Server 2005. I'm having trouble adding the following properties: ForEachEnumerator CollectionEnumerator Directory FileNameRetrieval FileSpec Recurse My code format looks like this: Microsoft.SqlServer.Dts.Runtime.Executable executable = aSequence[0].Executable...

SQL2008 MultiServerQuery

How i will write multiserver Query in SQL2008? ...

SQL Server subquery syntax

When I run the query : select count(*) from (select idCover from x90..dimCover group by idCover having count(*) > 1) I get the error : Server: Msg 170, Level 15, State 1, Line 2 Line 2: Incorrect syntax near ')' How do I formulate this query correctly? I'm on SQL Server 2000 ...

SQL Server Syntax for update via a subquery

How do I formulate this query update forge..dimInteg2 set duplicates = (select count(*) from (select idCover from x90..dimCover group by idCover having count(*) > 1)) where dimTable = 'dimCover' to avoid this error Line 6: I...

db2 sql script file

Hi all, I have an oracle script that I am trying to convert to valid db2 syntax. Within this sql file I have various calls to other sql files passing in a parameter using the '@' syntax. e.g. @script1 param1 @script2 param2 Can anyone help me with valid db2 equivalent statements? Is there an equivalent run command in db2? is it po...

Return number of rows affected by UPDATE statements

How can I get the number of rows affected by an UPDATE query in a Stored Procedure (SQL Server 2005), as a resultset. e.g. CREATE PROCEDURE UpdateTables AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; UPDATE Table1 Set Column = 0 WHERE Column IS N...

Check that all rows match a given criterion

requestId Consultantid statusid 1 2 10 2 2 10 3 2 10 I want to check if every row has a statusid of 10. if (every row has a statusid of 10) then -----do this endif; ...

SQL calculate difference between cell values

Hi i was wondering if anyone knows how i can calculate the difference between two tables in tsql. I dont mean finding which cells are different - i mean calulcating the numerical difference. eg - Table A has column1, column 2 and only one 1 row. A1 = 40, B1 = 30. Table B has column1, column 2 and only one 1 row. A1 = 25, B1 = 10. So how ...

Microsoft Access SQL Date Comparison

I am using Access 2007. I need to return rows with a date/time field falling within a date range to be specified in query parameters. The following doesn't error out, but doesn't appear to work. SELECT FIELDS FROM FOO WHERE (FOO.CREATED_DTG BETWEEN [START_DTG] And [END_DTG]); Likewise this doesn't work for me SELECT FIELDS FROM FOO...

Select values in SQL that do not have other corresponding values except those that i search for

I have a table in my database: Name | Element 1 2 1 3 4 2 4 3 4 5 I need to make a query that for a number of arguments will select the value of Name that has on the right side these and only these values. E.g.: arguments are 2 and 3, the query should return only 1 and not 4 (because 4 al...

ISO advice on best way to store particular group of values

I'm adding a number of fields to a table that stores information on vessels (ships). The values are related to fuel consumption. There are eight values, which at any time four can be used: At port IFO 180 At port IFO 380 At port MDO At port MGO Sailing IFO 180 Sailing IFO 380 Sailing MDO Sailing MGO Now, a user can enter a value for...

Get Text of every row in a Paged Gridview

I have a paged gridview. I want to get the text of every row and put that text into an array. However, I only get the text for the visible rows, not the entire dataset. I can't just get the data from the datasource because the gridview is populated by two different databases. How could I get every row's text - visible or not visible? I'm...

Joining to a table with multiple rows for the join item

I have a table users which has a primary key userid and a datetime column pay_date. I've also got a table user_actions which references users via the column userid, and a datetime column action_date. I want to join the two tables together, fetching only the earliest action from the user_actions table which has an action_date later than...

How can I capture a SQL Stored Procedure Error triggered by RAISEERROR() in .asmx file?

I'm very new to .NET. All I've done so far is implement some SQL Stored Procedure calls as WebServices by copying and pasting existing code (as instructed by my superior). I am calling some commands via Database.ExecuteNonQuery(). In the SQL Stored Procedure, I am performing some security checks based on the LoginId passed in (a user ca...