sql

django: sort table data according to other table data

Hi. I have read the (excellent) documentation but I can't figure out how to do this. I have a table which represents user friendships called "Shortlist" (with fields "from_user" and "to_user": both Foreign Keys to the classic auth_user table. Namely, from_user befriends to_user). I have another table into which I log user events/acti...

Simple SQL Problem

I have a SQL query that I cant wrap my mind around. I do not have a large amount of sql experience. So I need some help I have a table XXX: Social Security No (SSN). Name. organisation. (Finance/IT) In english what I want is: To select all SSNs and Names in "Finance" where there is a different name for that SSN in "IT". My not work...

creating a table with a primary key and an unique key

i am using sql server 2000 i want to create a table having id as primary key and one more column having unique key constraint. ...

Sql Server Most efficient way to join

I have a table with approx 3000 records which I need to export to csv (through a .net Web application) however I also need to pull information from about 10 other tables (also about 3000 records each) so that the form more columns, e.g. Individual Table Organisation Table IndividualOrganisation Table Output: Individual.Name, Orga...

idea to write procedure?

i pass parameter as productid, i check in productrelated table whether this product related product are there or not if it is not there i want to check sample productid in departmentreplated table if it is not there i find the department of the productid and find the that productid related department product.. Plz help me how to wri...

Crosstab Query in SQL Server 2000

I am hoping that someone has attempted this before and I can get some advice before I go any further. I am looking to produce something similar to a crosstab query in sql-server 2000. I have a table structure similar to the following: Item Item_Parameter Parameter id item_id id desc parameter_id ...

Looking for a SQL function to pull data for month selected and previous six months.

I am looking for a SQL function to use in a BOE Report to generate data from the month selected in the prompt and the previous six months. ...

Sweepstakes data model?

I want to be able to host multiple sweepstakes at a time on my website (.NET). How would YOU go about storing that data? I need to collect the user's information Assign them to the specific sweepstakes The sweepstakes have begin and end dates and may have prerequisites for entry Just wondering if you all have ever done anything like t...

Copying rows in a database when rows have children

I need to make a copy of a row in a table and also copy all the rows that link to it via its foreign key in other tables. And then copy all the rows that link to these rows. The problem is when I make a copy of the row the key is going to change. How can I propagate these changes through the relationships between tables? ...

Find "missing" records in a bridge/data-intersect table

I'm generating images from an original and storing them in a table. I want a query that will check for gaps. The image sizes are kept in a 3rd table, and each original should have 1 generated image for each record in the type table. Where's what I've got so far: SELECT oi.OriginalImageID, it.ImageTypeID FROM dbo.OriginalImages AS...

Treat Null as Max

Hey, So if I had a table in my database with the values 1 2 3 4 NULL And I executed the query SELECT MAX(col1) FROM <table> I'd get 4. Is there any way to change this so Null would be treated as the maximum as oppose to the minimum? Thanks! ...

Help with SQL query - some magic needed

Hi All! I need some help with a query - I'm using Firebird 2.1. I have a table like: RowID (primary key) | ActivityID | Duration | BilledAt 1 | 1 | 50 | 06.08.2010, 14:05:00.598 2 | 1 | 70 | 06.08.2010, 14:05:00.608 3 | 2 | 30 | 06.08.2010, 14:05:00.598 4 | 3 | 40 | 06.08.2010, 14:05:00.598 5 | 3 | 50 | 06.08.2010, 14:05:00.608 I'd...

Is there a way to get the Nth index of a specified char in T-SQL? (Without Substring!)

Hello, I am trying to get the index of the Nth character inside a varchar(MAX). Right now I am cutting off the front end of the varchar so I only have to check for the first but With extremely large varchars the process is getting way too slow. I would like to parse through the varchar(max) and just keep track of what index I am at and g...

Ajax page does not update consistently

I've recently started exploring using AJAX for a small project, and I've had reasonable success though it's not as smooth as I would like. The Basic setup is that an applications named ProphetX which interfaces with Excel to show stock market prices. Prices are updated as they change in Excel. Using VBA I save the data from the spreadsh...

SQL Azure - Substring Searches?

SQL Azure does not support SQL Server's Full Text Search feature. Does this mean a text field cannot be indexed to handle substring searches? For example, if I have a table Emails, with a Message column And I want to find all messages with both the words 'hello' and 'thanks' in them, will the standard index on the message collumn allow ...

Sql Query Pervious Row Optimisation

Here is my table structure MyTable ----------- ObjectID int (Identity), -- Primary Key FileName varchar(10), CreatedDate datetime ........... ........... ........... I need to get the time taken to create record in a file... ie... Time elapsed between the previous record in the same file and the current record of the same f...

Why does this stored procedure not return the correct ID?

Intermittently this stored procedure will return an ID that is in the millions when it should actually only be around 400. set ANSI_NULLS OFF set QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[TestStoredProcedure] ( @Title VARCHAR(50), @ID INT OUTPUT ) AS DECLARE @ResultsTable Table(InsertedID INT); INSERT INTO Table ( T...

openquery update on linked server

I want to execute the following statement through from a linked server (openquery): UPDATE SAP_PLANT SET (OWNER, OWNER_COUNTRY) = (SELECT import.AFNAME, import.COUNTRY FROM SAP_IMPORT_CUSTOMERS import, SAP_PLANT plant WHERE plant.SAP_FL = import.SAP_NO ...

T-SQL creating a dynamic where statement?

I know this is not possible, but is there something that would work? Basically I want the where statement to be dynamic, allowing me to pass it any string, which it will be able to search upon. Declare @search varchar(80) set @search = 'RegionID' Select * from TBL_TripDetails Where @search = '1' Thanks for your answers. After reading...

Use varbinary(max) to store HMTL? SQL Server 2008

Hi All, I am trying to figureout the best solution to store html data in some of my tables and track the history of changes made to that HTML. I read that text, ntext, etc are no longer supported for AFTER Triggers so I was thinking of using the varbinary(max) instead. Has anyone used varbinary to store HTML? I was planning on tracki...