sql

Sql query only printing first row

I am coding in php and the code takes data from an array to fetch additional data from a mysql db. Because I need data from two different tables, I use nested while loops. But the code below always only prints out (echo "a: " . $data3[2]; or echo "b: " . $data3[2];) one time: foreach($stuff as $key) { $query3 = "SELECT * FROM foobar...

Which isolation mode should you choose if you want the least concurrency?

If you need to minimize concurrency as much as possible, which isolation level (repeatable read, serializable, read committed, read uncomitted) would work best? ...

Is it possible to temporarily duplicate and modify rows on the fly in an SQL SELECT query?

I've just received a new data source for my application which inserts data into a Derby database only when it changes. Normally, missing data is fine - I'm drawing a line chart with the data (value over time), and I'd just draw a line between the two points, extrapolating the expected value at any given point. The problem is that as miss...

Tool to export result set from SQL to Insert statements?

I would like to export a ad hoc Select query result sets from SQL Server to be exported directly as Insert Statements. I would love to see a Save As option "Insert.." along with the other current available options (csv, txt) when you right-click in SSMS. I am not exporting from an existing physical table and I have no permissions to cre...

Oracle: loading a large xml file?

So now that I have a large bit of XML data I'm interested in: http://blog.stackoverflow.com/2009/06/stack-overflow-creative-commons-data-dump I'd like to load this into Oracle to play with. How can I directly load a large XML file directly into Oracle? Server-side solutions (where the data file can be opened on the server) and client...

Conditional where clause in Select statement

I am using a stored procedure to generate a report based on parameters to SP. I have to join different where conditions depending upon parameters passed. For ex. ALTER PROCEDURE [dbo].[sp_Report_InventoryAging] @TitleFlag int=0, /*0-All veh, 1-Clear Title, 2-Without Clear Title*/ @CompName varchar(100) = 'ALL COMPANIES', @CompBran...

Deferrable Constraints in SQL Server

Do any versions of SQL Server support deferrable constraints (DC)? Since about version 8.0, Oracle has supported deferrable constraints - constraints that are only evaluated when you commit a statement group, not when you insert or update individual tables. Deferrable constraints differ from just disabling/enabling constraints, in that...

quick method to save ruby objects on command line?

I'm using Netbeans to develop my RoR project so it is managing the SQL database. How can I make quick changes (i.e. edit row-by-row) to my DB, preferably in command line? i'm thinking - changing temporary passwords and users for testing purposes. Thanks for your input! ...

sql table udt, vs 2008, csharp

Hi, I am trying to run a SQL stored proc from Visual Studio 2008 which takes a table-valued UDT parameter as an input. I added this parameter in Visual Studio 2008 but when I run this program it gets an "ArgumentException - Specified type isn't registered on target server." So I googled this problem and think I need to create a new cla...

What is a slot?

When reading about SQL I've come across the term 'slot'. For example, in a DBCC error message you may get something like this which references slot 0: Page (1:157), slot 0 in object ID 2121058592, index ID 0, partition ID 72057594038517760, alloc unit ID 72057594042515456 (type "In-row data"). Column "col2" value is out of range for da...

Create optimum query to find records that are in only one table

Hey, so let's say i'm building this contact management system. There is a USER table and a CONTACT_INFO table. For every USER, I can have zero or more CONTACT_INFO records. The way I've defined it, I've setup a foreign key in my CONTACT_INFO table to point to the relevant USER record. I would like do a search for all the USER reco...

SQL Server 2005: Finding/accessing value of (currentrow-N) & implementing a formula ?

I have a table with four columns (Year,Month,Name & Value) I want to add another column (new_value) which is calculated by the following formula NEW_VALUE = (VALUE of currentMonth/VALUE of (currentMonth-4))^1/3 Example Year Month NAME VALUE NEW_VALUE 2008 01 A 4.412 ? 2008 02 B 4.941 2008 03 C ...

How to output a column per group that an item is a member of?

Given this SQL Input Table GroupId Item 1 Fish 1 FishBowl 2 Fish 3 Fish How Can i derive this Output? Item IsInGroup1 IsInGroup2 IsInGroup3 Fish Y Y Y FishBowl Y N N Please note that the Number of Groups can be variable ...

How to forward demo data dates using a stored procedure?

Hi guys, I am looking for a clean way to forward some demo data using a stored procedure. The data that I want to forward are date types. Due to the nature of my app, some of the data in my app will only appear when certain dates in the data are in the future. I hope this makes sense. : S Since my database is ever expanding, I was thin...

need Sql query (may be pivot)

Hi guys, i have table like below , Product Name Price Date Apple 1.5 5/5/2009 Apple 3 5/6/2009 Apple 3.5 5/7/2009 Apple 2.5 5/8/2009 Apple 5.5 5/9/2009 Orange 10.5 5/5/2009 Orange 12.5 5/6/2009 Orange 7.5 5/7/2009 Orange 4....

Update the results of a SELECT statement

Oracle lets you update the results of a SELECT statement. UPDATE (<SELECT Statement>) SET <column_name> = <value> WHERE <column_name> <condition> <value>; I suppose that this could be used for updating columns in one table based on the value of a matching row in another table. How is this feature called, can it efficiently be used fo...

Query all user defined types from Sql Server?

How can I query all user defined data types from sql server like the way I do this for database object which are stored in sysobjects. ...

SQL - Formatting XML response value

Hi I want to receive my response XML in following format... <PersonDetails> <Name>Ajay</Name> <Age>29</Age> <ContactDetails> <ContactDetail> <ContactType>Mobile</ContactType> <ContactValue>9565649556</ContactValue> </ContactDetail> <ContactDetail> <ContactType>Email</ContactType> <Cont...

Weird problem with an SQL exception truncate string or binary data

Hello, I'm currently building an app for my work, it work perfectly on my PC but one i put the compile code on to the 2008 server with sqlserver 2005 and run it i get an sql error truncat data. The weird part is that it aim the same table in the same database and it try to send to same datas. Any one has an idea? the error: Unhandl...

SQL 2005 XML Special/Escaped Characters from System.Xml.XmlDocument.OuterXml

I have some XML that has creating using an XmlDocument object in C#. I am then inserting the xml data into an XML column in SQL 2005 using the XmlDocument.OuterXml method to get the raw xml. The problem I have is that the xml contains some special characters. Namely: &#x1F;&#x1C; This is because the xml is built up from user input from...