sql

what could cause a merge cartesian join

I have a super-simple query in a star schema. One fact, two dimensions. I have verified that I am doing the joins properly. But when I execute the query plan, I get a merge cartesian join right before the steps to add the dimensions. explain plan for select * from fact f inner join dim1 d1 on d1.id = f.d1_id inner join dim2 d2 ...

Using Ref Cursor in Oracle SQL Developer

I am using Oracle SQL Developer, but I am having an issue seeing results from a package that returns a ref cursor. Below is the package definition: CREATE OR REPLACE package instance.lswkt_chgoff_recov as type rec_type is record ( source_cd lswk_tpr.gltrans.tpr_source_cd%TYPE, ...

postgres column alias problem

As a newbie to Postgresql (I'm moving over because I'm moving my site to heroku who only support it, I'm having to refactor some of my queries and code. Here's a problem that I can't quite understand the problem with: PGError: ERROR: column "l_user_id" does not exist LINE 1: ...t_id where l.user_id = 8 order by l2.geopoint_id, l_user_i...

Can queries that read table variables generate parallel exection plans in SQL Server 2008?

First, from BOL: Queries that modify table variables do not generate parallel query execution plans. Performance can be affected when very large table variables, or table variables in complex queries, are modified. In these situations, consider using temporary tables instead. For more information, see CREATE TABLE (Transact-SQL). Que...

Bulk Insert a File with a Text Field with Carriage Return (Enters)

Hi!, I´m having trouble with bulk insert a file that contains a field in data type text, and it holds enters and the delimiter for the fields are pipes "|" and the row terminator is "|\n" I get an error of truncation for the fields next to the text field. I think that the bulk insert thinks that the enters in the second field are the n...

MySQL GROUP BY behavior

Given the following table 'foo' ID | First Name | Last Name ---------------------------- 67 John Smith ---------------------------- 67 Bill Jacobs What first_name and last_name will the following query return and why? SELECT * FROM foo WHERE ID = 67 GROUP BY ID ...

How can I get the number of days between 2 dates in Oracle 11g?

I'm trying to find an integer number of days between two dates in Oracle 11g. I can get close by doing select sysdate - to_date('2009-10-01', 'yyyy-mm-dd') from dual but this returns an interval, and I haven't been successful casting this to an integer. Edit: Apparently in 10g, this returns the number of days as an integer. ...

Constraint like check constraints, not null constraints on MyISAM Storage Engines in MySQL

Can we use constraint like check constraints, not null constraints on MyISAM Storage Engines in MySQL? ...

GET ISNULL from COMPLEX FUNCTION

I have a SQL Table UDF That gets a Standard Deviation from a 20 day moving average of values... The table its computing from is: Tickers([date] datetime, [close] numeric(7,2)) The Function computes a Table GetStDev([date] datetime, stddev numeric(7,2). The last row of the stddev column is always NULL (due to STDEV calc?)... I need to r...

Purging SQL Tables from large DB?

The site I am working on as a student will be redesigned and released in the near future and I have been assigned the task of manually searching through every table in the DB the site uses to find tables we can consider for deletion. I'm doing the search through every HTML files source code in dreamweaver but I was hoping there is an aut...

Client side ADO.NET call fails to fill Dataset

I have a ASP.NET web page that needs to make a SQL Server call from the client side in a script sectipn of my aspx file. I'm calling a stored proc which takes one parm. This sp works fine in SQL Server Management Studio returning records as expected. When I try to fill a dataset from a call to this sp the ds gets filled with zero records...

SQL question regarding searching for data from multiple tables

I have 2 tables containing information that i want to search for, a main table, and a comments table. The main table contains timestamps, subjects, etc. While the comments table holds comments for the individual records in the main table. Its basically a simple ticket system. I need to be able to search for things in the main table and ...

Adding Row Numbers To a SELECT Query Result in SQL Server Without use Row_Number() function

Hi, i need Add Row Numbers To a SELECT Query without using Row_Number() function. and without using user defined functions or stored procedures. Select (obtain the row number) as [Row], field1, field2, fieldn from aTable UPDATE i am using SAP B1 DIAPI, to make a query , this system does not allow the use of rownumber() function in th...

How does one cheaply validate the existance of a column in a table in another schema with Oracle?

The environment is Oracle 9 & 10. I do not have DBA level access. The problem is to verify that a specific column exists in a specific table, in another schema. There are two cases to deal with. Another schema in the same instance A schema in a different instance, using a db_link Given my schema FRED and another schema BARNEY...

How can I update a 'long' datatype in Oracle?

Probably about 300K rows. Using SQL and/or PL/SQL. Would it be best to copy/convert into an interim format in a temporary table, work on it and then import it back in? The updated data would need to remain as a 'long' datatype because we don't have the resources (or inclination) to fix the DB. Thanks. ...

How can I use placeholders for variadic SQL functions with Perl's DBI?

I don't know if "variadic" is actually the right word, but I'm talking about things that can take a list of values, like IN(). If you've been working with DBI for long, you've probably tried to do this: (Note: All examples extremely simplified for brevity) my $vals = join ', ', @numbers; my $sth = $dbh->prepare( "SELECT * FROM mytbl WH...

How to select rows where a column value is empty/null using Zend_Db?

I have an SQLite database, eventually will be a MySQL database and I'm using Zend Framework. I'm trying to fetch all the rows in a table where the 'date_accepted' column is empty/null/doesn't have a value. This is what I have so far: public function fetchAllPending() { $select = $this->getDbTable()->select(); $select->where('date_acce...

Sorting by Price with SQL data type VARCHAR

I´m sorting by Price, look: SELECT Price FROM re2_listings ORDER BY Price asc Result: 1.200.000,00 1.500.000,00 200,00 3.000,00 ...but the correct way is: 200,00 3.000,00 1.200.000,00 1.500.000,00 Understand? How to do this? ...

postgres - comparing two arrays

postgres has an array data type, in this case a numeric array: CREATE TABLE sal_emp (name text, pay_by_quarter integer[]); INSERT INTO sal_emp VALUES ('one', '{1,2,3}'); INSERT INTO sal_emp VALUES ('two', '{4,5,6}'); INSERT INTO sal_emp VALUES ('three', '{2,4,6}'); SELECT * FROM sal_emp; Result: one, {1,2,3} two, {4,5,6} three, {2,4,6}...

Eliminating record duplicates in the Entity Framework database

I work with Entity Framework - add records in the database using classes that map to the DB. But i need to make sure I dont add duplicate records in the database. I assumed that when SaveChanges() is called, it sorts out all the duplicates, but it doesnt. Is there a way to eliminate creation of the duplicate records? ...