sql

How can I use "FOR UPDATE" with a JOIN on Oracle?

The answer to another SO question was to use this SQL query: SELECT o.Id, o.attrib1, o.attrib2 FROM table1 o JOIN (SELECT DISTINCT Id FROM table1, table2, table3 WHERE ...) T1 ON o.id = T1.Id Now I wonder how I can use this statement together with the keyword FOR UPDATE. If I simply append it to the query, Or...

Linq.Where-to-SQL on a text field comparing to a list of values

Customer.text is a field in an T-SQL DB (that I do not control and thus may not alter) of type "text". I'd like to do something like this: List<string> compare = new List<string>(); compare.Add("one"); compare.Add("two"); var q = from t in customer where t.text.Contains( compare.First()) select t; this will work. Bu...

Can you create a table with indexes at the same time?

I'd like to create a table: CREATE TABLE sfc.OpenId ( Url VARCHAR(255) PRIMARY KEY, UserGuid uniqueidentifier NOT NULL references dbo.aspnet_users(userId), ) ...with an index on UserGuid. Is it possible to create that index in the create table statement? ...

Recursive SQL giving ORA-01790

Using Oracle 11g release 2, the following query gives an ORA-01790: expression must have same datatype as corresponding expression: with intervals(time_interval) AS (select trunc(systimestamp) from dual union all select (time_interval + numtodsinterval(10, 'Minute')) from intervals where time_interval < systimestamp) sel...

UPDATE statement wrapped in an IF EXISTS block

I'm trying to write a DML script that updates a column but I wanted to make sure the column existed first so I wrapped it in a IF EXISTS block IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='Client' AND COLUMN_NAME='IsClarityEnabled') BEGIN UPDATE Client SET IsClarityEnabled = 1 WHERE ClientID = 21 END So the...

MySQL column not found

The SQL query without where statement runs great and outputs good results, but when I include WHERE condition it shows Unknown column 'date1' in 'where clause'. What's the problem? SELECT IF( e.weekly, DATE_ADD(DATE(e.time), INTERVAL CEIL(DATEDIFF('2010-04-08', e.time)/7) WEEK ), DATE(e.time)) AS `e.date1`, `v`.`lat`...

Retrieve data using Dynamic Query and Linq to SQL

Hi I have a really complicated dynamic query that i want to use to retrieve data from the database I am working in .net 3.5 sql server 2008 i created a stored procedure that accepts a varchar(max) as input parameter and does execute (@SqlQuery) it executes but does not return anything I really would like to use LINQ as all my proje...

Rails activerecord to_sql_string?

I've seen somewhere but can not remember. How to get a SQL string from an ActiveRecord object? Client.find(1).to_sql_string ...

select all values from a dimension for which there are facts in all other dimensions

I've tried to simplify for the purposes of asking this question. Hopefully, this will be comprehensible. Basically, I have a fact table with a time dimension, another dimension, and a hierarchical dimension. For the purposes of the question, let's assume the hierarchical dimension is zip code and state. The other dimension is just des...

VB.net Debug sqldatareader - immediate window

Scenario is this; I've a sqldatareader query that seems to be returning nothing when I try to convert the sqldatareader to a datatable using datatable.load. So I debug into it, I grab the verbose SQL query before it goes into the sqldatareader, just to make sure it's formatted correctly. I copy and paste this into SQL server to run it a...

Combining the UNIQUE and CHECK constraints

I have a table with columns a b and c, and if c is false then I only want to allow insertions if columns a and b are unique, but if c is true then a and b do not need to be unique. Example: There can only be one (foo, bar, false) in the table, but no limit on how many (foo, bar, true) there can be. I tried something like CONSTRAINT bla...

How to do a join that removes values?

Customers Holidays id | name customer_id | start | end ---+------ ------------+--------+------ 1 | Peter 1 | 5 | 10 2 | Simon 1 | 15 | 20 3 | Mary 2 | 5 | 20 What's a working SQL query that gives me all customers without ho...

How to issue SQL Server lock hints in WCF Entity Framework?

I'm just learning the WCF entity framework (and .net in general), and I'm running into a problem specifying lock hints in an embedded SQL query. I'm trying to specify a query that has lock hints in it (e.g., "SELECT * FROM xyz WITH(XLOCK, ROWLOCK)") and I keep getting errors from the runtime that the query syntax is not valid. The quer...

LINQ to Entity, joining on NOT IN tables

My brain seems to be mush right now! I am using LINQ to Entity, and I need to get some data from one table that does NOT exist in another table. For example: I need the groupID, groupname and groupnumber from TABLE A where they do not exist in TABLE B. The groupID will exist in TABLE B, along with other relevant information. The tables ...

counting rows that date hasn't yet passed

I am trying to count the number of rows whose date has not yet passed so i can get only the current records I get an error sayng MySQL error #111 Invalid use of group function SELECT COUNT(festivalid) FROM festivals WHERE min(datefrom) > now() ...

More efficient method for grabbing all child units

I have a table in SQL that links to itself through parentID. I want to find the children and their children and so forth until I find all the child objects. I have a recursive function that does this but it seems very ineffective. Is there a way to get sql to find all child objects? If so how? Using: Microsoft SQL Server Management St...

MySQL: How can I select only the last update for each user?

Say I have a 'user_log' table with the following field: id user_id status_text timestamp How do I write a query that selects only the last update for all the users in that table? Appreciate your help :) ...

sql - getting the id from a row based on a group by

Table A tableAID tableBID grade Table B tableBID name description Table A links to Table b from the tableBID found in both tables. If I want to find the row in Table A, which has the highest grade, for each row in Table B, I would write my query like this: select max(grade) from TableA group by tableBID However, I don't jus...

SQL query multi table selection

I have 3 tables, - Section table that defines some general item sections. - Category table -> has a "section" column (foreign key). - Product table -> has a "category" column (foreign key). I want to get all products that belong to X section. How can I do it? select from select? ...

How to log the raw SQL from Oracle occi C++ api?

One of our customers is complaining our application is not working. Their reasoning is that our sql function call to their Oracle database is not getting the "expected" result. Sometime, it should failed but our application get success from their database. It's really frustrating because it's their database and we cannot do any test on i...