sql

Updating SQL Database through PHP & xCode

Hi, I am trying to update a MS SQL Server database from my iPhone application. Here is what I have in the XCode: NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.xxxxx.com/UploadTextView.php"]]; [request setHTTPMethod:@"POST"]; NSString *postString = self.textView.text; [r...

Complex SQL Query to NHibernate DetachedCriteria or HQL

Hi, I have the following SQL Query returning the results I need: SELECT Person.FirstName,Person.LastName,OrganisationUnit.Name AS UnitName, RS_SkillsArea.Name AS SkillsArea, Activity.Name AS ActivityName, Activity.CLASS, Activity.StartsOn, Activity.EndsOn, SUM(ActivityCost.CostAmount) / NULLIF( ( SELECT COUNT(Registration.A...

query multiple databases for statistic purposes SQL

Hello all! I am trying to write a stored procedure that will allow me to write a single SELECT statement that runs on all databases on my SQL Server. (Microsoft SQL 2005) so far ive come up with the following procedure set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [sp_cross_db_query] @SQLQuery varchar(400) AS DECLARE...

Sorted result differs with inner and left joins in mysql

I just found this irregularitry in a query i made, why does the result differ when using inner and left joins? for one, the result is ordered both in the temporary hit table and in the final query? I made a little example to show the problem: # cleanup drop temporary table if exists ids; drop temporary table if exists arts; # create t...

A Transport-level error has occured when sending the request to the Server.

Do anyone have a REAL and CLEAR way to solve this problem and an explaination of why it happens? Because, every thread i've read on how to solve this issue where not "politicaly correct". I mean, i saw things like "Restart machine, etc" but I get this error on a hosted dedicated server and I can't restart it like that. A transport-l...

SQL converting columns times out

I need a query that will alter a single column from nvarchar(max) to 32. The real problem is this table has 800,000 rows. And my alter table myTable alter column mycolumn statement times out. Any suggestions or tips? ...

How to add zeros in front of a text field in an access table.

Hi, I have an access table with a text field. It has alpha numeric values. But i want all values to be minimum 3 digit. so i want to add zeroes in front of all single or two digit values . 5 must become 005 89 must become 089 how do i write a query to update all values in the table. thanks tksy ...

database design help needed

Design a database to store details about U.S. Presidents and their terms in office. Also, record details of their date and place of birth, gender, and political party affiliation. You are required to record the sequence of presidents so that the predecessor and successor of any president can be identified. Remember Grover Cleveland se...

How to Use Variables in Access SQL Queries

Hi I'm working on a project which requires I use a large number of columns in my Access SQL queries. A typical query contains several fields such as the one below: SELECT ([Score1]+[Score2]+[Score3])*.5 AS [Scores], [Subject] FROM [ScoresTable] WHERE ([Score1]+[Score2]+[Score3])*.5 > 500 Is there any way to assign the value of ([Score...

Random Scheduling

I have the following table in my database: tbl1 PK ClientID ScheduleDay Time1Start Time1Stop Time2Start Time2Stop Time3Start Time3Stop Status Here is some sample data ID ClientID ScheduleDay Time1Start Time1Stop Time2Start Time2Stop Time3Start Time3Stop -- -------- ----------- ---------- --------- ---------- --------- ---------- -...

Help on a SQL Query

In a previous Post, I was doing a very simple database with 3 tables "doctor", "patient" and "visit". I've tried to make it more realistic and included now a many to many relationship between "doctor" and "patient". "visit" is the table resulting in this n-m relation. I assume the following simple structure for my table : doctor - idD...

SQL: Get a selected row index from a query

Hi everyone! I have an applications that stores players ratings for each tournament. So I have many-to-many association: Tournament has_many :participations, :order => 'rating desc' has_many :players, :through => :participations Participation belongs_to :tournament belongs_to :player Player has_many :participations has_ma...

CASE statement in WHERE clause

i have a procedure in which the below condition is to be written in a WHERE clause. How do I do that using CASE, or something like it? IF (@itemId IS NOT NULL) dataId = @itemid ...

Unusual runtime of date functions in Oracle

I am running a query that returns me a collection of date objects for months between a certain date range. The query works fine, but is very slow (~2 seconds on my local machine, ~30 in our corporate development environment). Here it is: SELECT ADD_MONTHS(TO_DATE('200804', 'YYYYMM'), -1+rownum) AS MONTH FROM all_objects WHERE ADD_MONTHS...

Problem connecting to database after a RESTORE. SQL Server 2005 and Classic ASP

Hi, I have some Selenium test scripts which I'm using to test a Classic ASP web app, but I'm having problems after restoring the database (SQL Server 2005) with a backup file before every test is run. Immediately after the successful RESTORE (from a Python script running sqlcmd ...) when the ASP tries to connect to the db I get the foll...

How can I insert a record and lock that row simultaneously?

I'm inserting a row using an Oracle stored procedure which is configured to use an autonomous transaction. I'd like to insert this record, commit that transaction, and then lock the newly-inserted record so that nobody else can modify it except my current session (in another transaction, obviously, since the one that inserted it is auto...

Mysql many to many query

Having a mental block with going around this query. I have the following tables: review_list: has most of the data, but in this case the only important thing is review_id, the id of the record that I am currently interested in (int) variant_list: model (varchar), enabled (bool) variant_review: model (varchar), id (int) variant_rev...

Database design guidance needed

A dairy farmer, who is also a part-time cartoonist, has several herds of cows. He has assigned each cow to a particular herd. In each herd, the farmer has one cow that is his favorite - often that cow is featured in a cartoon. A few malcontents in each herd, mainly those who feel they should have appeared in the cartoon, disagree with t...

Oracle Partition Pruning with bind variables

I have a large (150m+ row) table, which is partitioned into quarters using a DATE partition key. When I query the table using something like... SELECT * FROM LARGE_TABLE WHERE THE_PARTITION_DATE >= TO_DATE('1/1/2009', 'DD/MM/YYYY') AND THE_PARTITION_DATE < TO_DATE('1/4/2009', 'DD/MM/YYYY'); ... partition pruning works correctly...

TSQL strip date from datetime

What is the best way to strip the date from a DATETIME so only time is left to do a comparison? I know I can do the following: CONVERT(DATETIME, CONVERT(VARCHAR(8), GETDATE(),8)) But this involves convert and characters. If I wanted to check whether a time (including minutes) was between two other times stored in DATETIME columns, ...