sql

Executing a WHERE clause conditionally in SQL

Hello, I have an application on a SQL Server 2008 database. This database has a stored procedure that queries one of the tables. This stored procedure takes two parameters: userName and ID The userName parameter will always be passed. However, the ID field will either be NULL or an actual value. If the value is something other than NUL...

Using single quote in an Exec statement in SQL

I am having issues executing a SQL statement from a stored proc having single quotes. Here is my query from a stored procedure that I am executing. EXEC('UPDATE myTABLE SET myCOLUMN = (SELECT Replace('OSINGLEQUOTEJOHN DOE','SINGLEQUOTE','''')') I am trying to update table "myTABLE" column "myCOLUMN" with a value "O'John Doe"...

SQL: BETWEEN and IN (which is faster)

Possible Duplicate: Is there a performance difference between BETWEEN and IN with MySQL or in SQL in general? If I have the following ids: 1,2,3,4,5,6 Is it better to use IN or the between clause for deleting? ...

Can you define a NULL on a column definition in the Create Table statement in a Firebird DB?

I am using SQL Manager Lite to try to run a DDL Create Table script. I am new to Firebird and I don't know why it isn't working. The following script... create table Contacts ( ID integer not null, FirstName varchar(64) not null, LastName varchar(64) ...

Converting SQL Server to MySQL

Hi, is it possible to convert a SQL Server database file to a MySQL Database file and if so what would be the best way to go about doing this. Thanks. ...

whats the advantage or disadvantage of doing one of these way

I see some people do joins like this SELECT * FROM table1 JOIN table 2 ON table1_id = table2_id where as some people do this SELECT * FROM table1 WHERE table1.table1_id = tabl2.table2_id; whats the difference and what is more efficient and benificial ...

ORDER BY in PHP/MYSQL not working

The sql query is $query = mysql_query( "SELECT * FROM games ORDER BY gamename" ); But it doesn't order them by the gamename. This is a sample of the database id (int) | gamename (text) | gameurl (varchar) | width (int) | height (int) 1--------- Copter ---------- copter ----------- 100 ---------- 200-------- 2--------- Adrenaline -...

When programming in PHP is it better to use stored procedures or hard coded SQL?

Currently, I only use stored procedures, is this considered good practice or bad? I find it helpful to separate my SQL code from my PHP code, and I also remember hearing in a PHP course I took a few semesters back that stored procedures are more secure. ...

XML - CSV data output: server-client interaction and optimization

Hi gurus, I am planning an application that involves pulling XML data from the server side and manipulating it on the client side before allowing the user to save it as CSV. On the server side, I will use Apache and PHP as the primary service interface, and the data source could be coming from MySQL server and/or Exist database server....

Process a Repeatable Subset of Records in a SQL Server 2000 Table

I have a script that processes queued records in a SQL table in SQL Server 2000. I now need to add additional instances of my script to process their own subset of the queued records in the table. How can I query the table within each instance so that each instance will return a subset of rows that never overlap with each other? I cou...

help with distinct !!!

Im a little confused about whether should I use a nested Subquery Or JOINS with distinct !! which one of these will perform better and faster ? any suggestions to do this query without distinct ?!? SELECT distinct TOP(20) e.*, u1.UserName As Sender, u2.UserName As Receiver, u1.Avatar AS SenderPic FROM Friends f INNER JOIN Users u ON...

update a dataset corresponding to a database from it's datagridview

there is a datagridview corresponding to a table of some database. this database has a identity (auto-incrementing) column named "id".this column is primary key,also. user just see a blanked and empty datgridview.he/she can modify this table(datagridview) for example add new row,remove it,edit(update)one cell and can do every possible mo...

Search for a value in where clause from Serialized Array

Hello, The title could be confusing, but I think my doubt is clear. I'll explain. I'm doing this query: $sql = 'SELECT * FROM calendar WHERE day = "'.$day.'" AND month = "'.$month.'" AND year = "'.$year.'" AND realizada = 0 AND colaborador = "What to put here?!"'; But the field "colaborador" is a serialized array. One example, whe...

SQL inner join two tables with the same column names

Hello I have two tables with a variable amount of columns. (I don't know how many columns or what there names will be) for example Table A and Table B. TableA: ID | B_ID | {variable} TableB ID | {variable} Query: SELECT TableA.*, TableB.* FROM TableA INNER JOIN TableB ON TableA.B_ID= TableB.id; When TableA and TableB bot...

Creating new date field dynamically from next row

I have a table of data. I have a field which shows date. I had set this column as Start Date. I want to create an additional column as End Date, where the End Date will be the Start Date of the next row. Can you give me a query of creating the End Date by taking the data of the Start Date in next row ? ...

Add empty row to query results if no results found

I'm writing stored procs that are being called by a legacy system. One of the constraints of the legacy system is that there must be at least one row in the single result set returned from the stored proc. The standard is to return a zero in the first column (yes, I know!). The obvious way to achieve this is create a temp table, put the...

Use of CASE statement values in THEN expression

I am attempting to use a case statement but keep getting errors. Here's the statement: select TABLE1.acct, CASE WHEN TABLE1.acct_id in (select acct_id from TABLE2 group by acct_id having count(*) = 1 ) THEN ...

SQL in Access 2007 - Syntax error

I am using Access 2007 to create an SQL query to join two tables. I was able to do that but then I don't have the rows where the columns from the second table are NULL; I just have the rows where there is information in the second table that matches. I tried to do a LEFT JOIN but Access didn't like this. Instead I am trying to create a b...

Should you use single table inheritance or multiple tables that are union-ed in a view?

Let's say you have a notes table. The note can be about a particular account, orderline or order. Notes that are about the account do not apply to any specific orderline or order. Notes that are about the orderline also apply to the parent order and the account that is attached to the order. Notes that are on the order also apply to t...

Can I use multiple statements in a JDBC prepared query?

Hi, I'd like to execute something like this on my MySQL server: SET @id=(SELECT id FROM lookupTable WHERE field=?); (SELECT * FROM table2 WHERE id=@id) UNION (SELECT * FROM table3 WHERE id=@id) UNION (SELECT * FROM table4 WHERE id=@id); This works fine from the console, but not from my Java PreparedStatement. It throws an exception...