sql

Oracle Minus - From a list of values, how do I count ONLY non reversed values.

I have a list of payment transactions in a table. That include payment reversals. The Payment reversals are not flagged, so I have to infer that if a deduction is equal to an existing transaction it is a reversal I want a count of only the transactions that were not reversed. E.g From a list of transactions amounts. 5 5 -5 (This is...

getting data from 2 different table with JOIN sql. Codeigniter

I use codeigniter, and I need to get data from 2 different table. for now it returns data only from works_image table. how can I get data from both 2 table ? thanks a lot!! $this->db->select('works_image.*', 'works.*'); $this->db->from('works_image', 'works'); $this->db->join('works', 'works.id = works_image.id_work'); $result = $thi...

update sql in Oracle conversion from Sql Server

I am trying to create an update statement in the Oracle. here it is version in Sql Server UPDATE ev SET (ev.station_type = t.st_type, ev.adt = t.adt ) FROM source ev JOIN dataTbl t ON ev.counterID = t.counterID There are two tables source table were counterID is primary key dataTBL table were counterID is Fore...

Formatting varchar data into a certain format.

I need to format data in a sql column that is currently entered like this: Z04000002003.7 The desired output of this would be: Z04/000/002/003.7 Every time a user enters data like this Z04000002003.7. The next time the user opens the record it would have automatically formatted it to display Z04/000/002/003.7. ...

how to use a variable in oracle script for the table name

I have an pl\sql script where I want to set the table name used in the script to a variable. So, from some examples I found on the web, I wrote the code below. The first section works, so I think my general syntax is correct,but the second section, where I attempt to use a variable for a table name it errors ("SQL Error: ORA-00903: inv...

Trying to access the results/result-set of a SQL server EXEC statement

Say I've got stored proc 1, that returns some data. how can I execute that stored proc and set some parameters within another stored proc based on the results of that stored proc. For example: Table: UserInfo (UserID [int], Name [varchar], DateOfBirth [datetime] ) Stored Proc 1: CREATE Procedure StoredProc1 @Name [varchar] AS ...

How do I limit the acceptable values in a database column to be 1 to 5?

I have a table in a database where one of the columns should have a value from 1 to 5. How can I write this limitation into the database? Do I use a constraint? What's the best practice say about this kind of thing? I am using SQL Server 2005 ...

large sql resultsets in java

How can I fetch large resultset in java? I have about 140,000 rows with 3 columns. ...

What SQL is required to put SQL Server 2005 in single user mode?

I would like to know how (and by extension if it's possible) to put SQL Server 2005 in single user mode using SQL statements? I found these instructions on the MSDN, but alas they require SSMS. http://msdn.microsoft.com/en-us/library/ms345598(SQL.90,loband).aspx *To set a database to single-user mode In Object Explorer, connect to...

SQL Concat field from multiple rows.

I would like to create a function that returns a concatinated string of a given field of given query. Here is what I did. And this one gives me an error. Must declare the table variable "@qry". CREATE FUNCTION dbo.testing ( @qry varchar(1000), @fld varchar(100), @separator varchar(15) = '; ' ) RETURNS varchar AS...

When do I need to use Begin / End Blocks and the Go keyword in SQL Server?

Can someone tell me when and where I need to use begin and end blocks in SQL Server? Also, what exactly does the Go keyword do? Thanks in advance... ...

SQL Query: Incrementing by two instead of 1

Hello all, I am trying to update a field in a table by increasing its integer value by 1. Here is what I am using: function updateViews($id){ $sql = "UPDATE tweets SET tweet_views = tweet_views + 1 WHERE tweet_key = '$id'"; $result = mysql_query($sql) or die("DB Error : ". mysql_error()); return $result; } However, I find its inc...

Querying email addresses other than the primary in Active Directory

I'm trying to query Active Directory from a stored procedure using OPENQUERY and add the values to a temporary table. I've got everything working, except when I add the 'proxyAddresses' field to my query, it throws this error: "OLE DB error trace [OLE/DB Provider 'ADSDSOOBject' IRowset::GetData returned 0x80040e21: Data status returne...

Addressing cursors using a field.(SQL Server)

I have a table that I process using a cursor. Lets say it's structure is like this: RID | School | Order | Text Now, I filter out the other schools(so only mine is shown) and then I ORDER BY order, so that I get the text arranged how I want. Now, my problem is, the order isn't straight incrementing(though all of them are unique per scho...

Sql Query for Commissions (Decision?) Table

SQL 2008 I have a commission table that looks like this: Comm% | ProfitStartRange | ProfitEndRange 0.01 | 0.00 | 100.99 0.02 | 101 | 500.99 0.03 | 501 | 1000.99 etc... Basically I want create a query that returns the appropriate Comm% based on a value. I would like to do this inline and not in a user defined function if possible ...

How do I write a TSQL function that takes a table name to drop, and drops a table

Sorry, but I am new to TSQL so I don't even know basic things. I've been working on this function, but I've been running into a lot of syntax issues. If someone can assist me in writing this function, I would appreciate it. 1. I would like it to check for the existence of a table before attempting to drop the table 2. I would like ...

How can I further optimize a derived table query which performs better than the JOINed equivalent?

UPDATE: I found a solution. See my Answer below. My Question How can I optimize this query to minimize my downtime? I need to update over 50 schemas with the number of tickets ranging from 100,000 to 2 million. Is it advisable to attempt to set all fields in tickets_extra at the same time? I feel that there is a solution here that I'm ...

Creating VIEW in system level

I have created a VIEW using the CREATE OR REPLACE VIEW statement at the domain schema level. create or replace VIEW SERV as select loop.loop_serv serv, component.cmpnt_id,component.loop_id from component,loop where component.loop_id = loop.loop_id union select distinct ' ',0,0 from component,loop; So if I login to the domain schema a...

TSQL - how to find if a column has a space char(32)?

TSQL - how to find if a column has a space char(32)? select * from [sometable] where CHARINDEX(' ', [somecolumn]) > 0 doesn't work? Any ideas? ...

mysql_num_rows error

Cant figure out what the problem is! $msgs = mysql_num_rows(mysql_query("SELECT * FROM messages WHERE recipient = $userID AND read = 0")); echo $msgs; The above code works if I remove "and read =0". But if not i get: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in left_menu.php on line 16. I h...