sql

Replace NOT working!!!

I have column with values that have wrong character ?. Now I want to change it to character b. For this I am using this statement: SELECT REPLACE(name,'?','b') from contacts; But when I do this nothing's happening, it return value with ?. What I am doing wrong? How I can replace this? ...

Delayed for some heavy users of a billing details page

I've developed a billing summary page use mysql + php. there are many users : (1M) light user :each has less than 10K record :0.99M users heavy user :each has about 1M record SQL is the following : SELECT SUM(value_a) A, SUM(value_b) B, SUM(value_c) C FROM daily_data_sep_2010 WHERE user_id='<user_id>' AND type IN ( 'type_a', ...

postgresql union

I have this data in postgresql id | rate | hrv | activity | orientation | timestamp | user_id | status ----------+-----------+-----+----------+-------------+------------------------+---------+-------------- 66764728 | 72 | 1 | 0 | 90 | 2010-06-10 18:54:54+00 | 397 | t 66764729 | ...

How to create DbCommand

Hi, I'm using a method in the EnterpriseLibrary.Data.Database namespace called public virtual object ExecuteScalar(DbCommand command) I'm wanting to use this method to execute a scalar-valued function. However the I'm not sure how to even create the DbCommand. Could someone please tell me how to create it because it won't let me inst...

SMO "Restore failed for Server" Restoring Backup From File

I'm using the following code to restore a backup sql database with C# and SMO. void RestoreDatabaseWithSMO(string sConnect, string dbName, string backUpPath) { using (SqlConnection cnn = new SqlConnection(sConnect)) { cnn.Open(); cnn.ChangeDatabase("master"); ServerConnection sc = new ServerConnection(cn...

MYSQL - Concatenate two tables

I have two tables as follows: TABLE A TABLE B StuID | actid FacID | actid 3 12 98 17 5 17 54 21 I want to list the name of everyone, both students and faculty, who participate in activity 17. Is there anyway I can get a result as below: ...

How to compare rows in two identical tables and return result set of missing rows?

I've looked through all the related questions, but none of them does exactly what I need. I have two identically-structured tables (id, VoucherNbr, BalanceInit) - one is from our current production system (tableA), and the other is from a client's legacy system (tableB). Table A has records a,b,c,d,e (for example), and table B has a,b,c,...

What's the SQL significance of 0x5E5B7D7E?

Looking through some apache logs, I've run into the following pattern several times (URL decoded): GET /foo.php?id=1 and union select 0x5E5B7D7E,0x5E5B7D7E,0x5E5B7D7E,... -- Clearly this is an SQL injection attempt. But why the constant shown above? I can't see how it could be particularly significant, though it seems to appear quite ...

Is their a posIndex in MS Access Queries?

Hi, I need to write a query like SELECT substring(variable, startPosIndex, endPos) from Blah blah ; startPostIndex = indexPosition('#') endPos = lenght(variable) - 1; So basically my query to access will be SELECT substring(variable, indexPosition('#'), lenght(variable) - 1) from Blah blah ; The query that I have written to get if...

Why my mysql doesn't use index?

I'm tuning my query for mysql. the schema has index of user_id (following..) but the index is not used. why? Env: MySQL4.0.27,MyISAM SQL is the following : SELECT type,SUM(value_a) A, SUM(value_b) B, SUM(value_c) C FROM big_record_table WHERE user_id='<user_id>' GROUP BY type Explain: |table |type |possible_keys |key |key_len...

Oracle SELECT COUNT(*) … GROUP BY … not returning rows where the count is zero

I tried the solution given in "mysql SELECT COUNT(*) … GROUP BY … not returning rows where the count is zero" but it didn't work for me. Here is SQL :: SELECT empid, SUM (total_records) total_records FROM (SELECT ID, (CASE WHEN ID LIKE '2%' THEN '2____' WHEN ID LIKE '3%' THEN '3____' ...

How to view Execution Plans for Oracle Database in Java

With SQL Plus for Oracle Database, I can call SET autotrace on and then see Execution Plan, statistics, etc. The problem is that I want access to information about the Execution Plan and statistics in my Java program. I typically have done something like this to execute a sql statement, Connection connection = //INITIALIZE HERE; St...

Index performance with WHERE clause in SQL

I'm reading about indexes in my database book and I was wondering if I was correct in my assumption that a WHERE clause with a non-constant expression in it will not use the index. So if i have SELECT * FROM statuses WHERE app_user_id % 10 = 0; This would not use an index created on app_user_id. But SELECT * FROM statuses WHERE app_...

How to set variable from a SQL query?

Hi, I'm trying to set a variable from a SQL query: declare @ModelID uniqueidentifer Select @ModelID = select modelid from models where areaid = 'South Coast' Obviously I'm not doing this right as it doesn't work. Can somebody suggest a solution? Thanks! ...

Migrate database from Sql Server 2008 to MySql?

Hi all, i want migrate a database from Sql Server 2008 to MySql using a the tool MySql Migration Toolkit but when the tool is establishing the database connection i receive this error : Connecting to source database and retrieve schemata names. Initializing JDBC driver ... Driver class MS SQL JDBC Driver Opening connection ... Connec...

Delete all record exist in all table.

Hello there, How to make query in sql to delete all record exist in every table. There possible to write every name table using command delete. But it will take long time to write every single name table. I am already try DELETE FROM * in MySQL but it got error: You have an error in your SQL syntax; check the manual that correspond...

How to perform string concatenation in PL/SQL?

I have a variable defined as define dbs '&1' Suppose I pass database1 as an argument. Then the statement is interpreted as define dbs database1 I want to append single quotes around the string, ie I want it to be interpreted as define dbs 'database1' How should I do this? ...

what if I delete information_schema database from mySQL?

I'm curious to know, "what if I delete information_schema database from mySQL?" ...

Quick introduction on how to use oracle xml data type

How do you work with the oracle XML data type? This question is intended to be asked and answered by me, just to share the information with others ...

How to deal with single quote in Word VBA SQL query?

Hi, I get a customer name from dropdown and use that value to query an excel spreadsheet, however, the name can contain a single quote (example: Adam's Meat). This breaks my application and how do I make a query with a variable that contains a single quote? Private Sub cboCompany_Change() Dim customerName As String ...